31 lines
602 B
Go
Raw Normal View History

package d1
2023-01-09 23:10:30 +09:00
import (
"database/sql"
"errors"
"syscall/js"
)
2023-01-09 23:10:30 +09:00
type result struct {
resultObj js.Value
}
var (
_ sql.Result = (*result)(nil)
)
2023-02-05 23:50:00 +09:00
// LastInsertId returns id of result's last row.
// If lastRowId can't be retrieved, this method returns error.
func (r *result) LastInsertId() (int64, error) {
2023-02-26 17:38:38 +09:00
v := r.resultObj.Get("meta").Get("last_row_id")
2023-02-06 02:34:45 +09:00
if v.IsNull() || v.IsUndefined() {
2023-02-05 23:50:00 +09:00
return 0, errors.New("d1: lastRowId cannot be retrieved")
2023-01-09 23:10:30 +09:00
}
id := v.Int()
2023-02-05 23:50:00 +09:00
return int64(id), nil
2023-01-09 23:10:30 +09:00
}
2023-02-05 23:50:00 +09:00
func (r *result) RowsAffected() (int64, error) {
return int64(r.resultObj.Get("changes").Int()), nil
}