2023-02-26 11:25:53 +09:00

31 lines
569 B
Go

package d1
import (
"database/sql"
"errors"
"syscall/js"
)
type result struct {
resultObj js.Value
}
var (
_ sql.Result = (*result)(nil)
)
// LastInsertId returns id of result's last row.
// If lastRowId can't be retrieved, this method returns error.
func (r *result) LastInsertId() (int64, error) {
v := r.resultObj.Get("lastRowId")
if v.IsNull() {
return 0, errors.New("d1: lastRowId cannot be retrieved")
}
id := v.Int()
return int64(id), nil
}
func (r *result) RowsAffected() (int64, error) {
return int64(r.resultObj.Get("changes").Int()), nil
}