From e16f72b6aa9addb740b9cc944f6b7ffffc8060d1 Mon Sep 17 00:00:00 2001 From: syumai Date: Sun, 5 Feb 2023 23:50:00 +0900 Subject: [PATCH] remove Result interface --- cloudflare/d1/result.go | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/cloudflare/d1/result.go b/cloudflare/d1/result.go index e3d37c0..72b21c3 100644 --- a/cloudflare/d1/result.go +++ b/cloudflare/d1/result.go @@ -10,39 +10,21 @@ type result struct { resultObj js.Value } -// Result is the interface which represents Cloudflare's D1Result type. -// For `changes` field, RowsAffected method can be used. -// see: https://github.com/cloudflare/workers-types/blob/v3.18.0/src/workers.json#L1608 -type Result interface { - // LastRowId returns id of result's last row. - // If LastRowId can't be retrieved, this method returns nil. - LastRowId() *int - // Duration returns duration of executed query. - Duration() int -} - var ( _ sql.Result = (*result)(nil) - _ 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) { - return 0, errors.New("d1: LastInsertId is not implemented. instead of it, please use d1.Result.LastRowId") + 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 } - -func (r *result) LastRowId() *int { - v := r.resultObj.Get("lastRowId") - if v.IsNull() { - return nil - } - id := v.Int() - return &id -} - -func (r *result) Duration() int { - return r.resultObj.Get("duration").Int() -}