From 656e5dcce132716b39005814407224f989aa8c2d Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Fri, 31 Jul 2026 21:39:56 +0200 Subject: replace types Handle, DB, Conn, Tx with their gg/gsql equivalents --- select.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'select.go') diff --git a/select.go b/select.go index 37edb92..c171655 100644 --- a/select.go +++ b/select.go @@ -11,8 +11,8 @@ import ( "reflect" "go.xyrillian.de/gg/errext" + "go.xyrillian.de/gg/gsql" . "go.xyrillian.de/gg/option" - "go.xyrillian.de/oblast/handle" ) // Select executes the provided SQL query and fills an instance of the record type R for each row in the result set, @@ -20,7 +20,7 @@ import ( // // An error is returned if any column name in the result set does not correspond to an addressable field in R. // Errors can be retrieved through the methods on type [Selection]. -func (s Store[R]) Select(ctx context.Context, db Handle, query string, args ...any) Selection[R] { +func (s Store[R]) Select(ctx context.Context, db gsql.Handle, query string, args ...any) Selection[R] { // NOTE: This function body should be as short as possible to reduce the binary size after monomorphization. // Any expression that does not depend on type R should be factored out into a reusable function. @@ -41,15 +41,15 @@ func (s Store[R]) Select(ctx context.Context, db Handle, query string, args ...a // // Returns an error if [NewStore] was called without the [TableNameIs] option, which is required to generate a query for this method. // Errors can be retrieved through the methods on type [Selection]. -func (s Store[R]) SelectWhere(ctx context.Context, db Handle, partialQuery string, args ...any) Selection[R] { +func (s Store[R]) SelectWhere(ctx context.Context, db gsql.Handle, partialQuery string, args ...any) Selection[R] { // NOTE: This function body should be as short as possible to reduce the binary size after monomorphization. // Any expression that does not depend on type R should be factored out into a reusable function. return Selection[R]{startSelectWhereQuery(ctx, db, s.plan, partialQuery, args...)} } -func startSelectQuery(ctx context.Context, db Handle, plan plan, query string, args ...any) selection { - rows, err := db.OblastQuery(ctx, query, args) +func startSelectQuery(ctx context.Context, db gsql.Handle, plan plan, query string, args ...any) selection { + rows, err := db.GSQLQuery(ctx, query, args) if err != nil { return selection{Err: fmt.Errorf("during Query(): %w", err)} } @@ -81,12 +81,12 @@ func startSelectQuery(ctx context.Context, db Handle, plan plan, query string, a } } -func startSelectWhereQuery(ctx context.Context, db Handle, plan plan, partialQuery string, args ...any) selection { +func startSelectWhereQuery(ctx context.Context, db gsql.Handle, plan plan, partialQuery string, args ...any) selection { if plan.Select.Query == "" { return selection{Err: errors.New("cannot execute SelectWhere() because query could not be autogenerated")} } query := plan.Select.Query + partialQuery - rows, err := db.OblastQuery(ctx, query, args) + rows, err := db.GSQLQuery(ctx, query, args) if err != nil { return selection{Err: fmt.Errorf("during Query(): %w", err)} } @@ -106,7 +106,7 @@ func startSelectWhereQuery(ctx context.Context, db Handle, plan plan, partialQue // // Warning: Because of limitations in the interface of database/sql, this function is built on [Store.Select] and cannot be any faster than it. // For maximum performance, use [Store.SelectOneWhere] which avoids the overhead of potentially having to read multiple rows. -func (s Store[R]) SelectOne(ctx context.Context, db Handle, query string, args ...any) (R, error) { +func (s Store[R]) SelectOne(ctx context.Context, db gsql.Handle, query string, args ...any) (R, error) { // NOTE: This function body should be as short as possible to reduce the binary size after monomorphization. // Any expression that does not depend on type R should be factored out into a reusable function. // @@ -117,7 +117,7 @@ func (s Store[R]) SelectOne(ctx context.Context, db Handle, query string, args . } // SelectOneOrNone is like SelectOne, but returns [None] instead of [sql.ErrNoRows]. -func (s Store[R]) SelectOneOrNone(ctx context.Context, db Handle, query string, args ...any) (Option[R], error) { +func (s Store[R]) SelectOneOrNone(ctx context.Context, db gsql.Handle, query string, args ...any) (Option[R], error) { // NOTE: This function body should be as short as possible to reduce the binary size after monomorphization. // Any expression that does not depend on type R should be factored out into a reusable function. @@ -129,7 +129,7 @@ func (s Store[R]) SelectOneOrNone(ctx context.Context, db Handle, query string, // // This method is more efficient than [Store.SelectOne] on CPU runtime, but has a slight memory allocation overhead per call from query preparation. // This can be avoided by using [Store.PrepareSelectQueryWhere] instead. -func (s Store[R]) SelectOneWhere(ctx context.Context, db Handle, partialQuery string, args ...any) (R, error) { +func (s Store[R]) SelectOneWhere(ctx context.Context, db gsql.Handle, partialQuery string, args ...any) (R, error) { // NOTE: This function body should be as short as possible to reduce the binary size after monomorphization. // Any expression that does not depend on type R should be factored out into a reusable function. @@ -139,14 +139,14 @@ func (s Store[R]) SelectOneWhere(ctx context.Context, db Handle, partialQuery st } // SelectOneOrNoneWhere is like SelectOneWhere, but returns [None] instead of [sql.ErrNoRows]. -func (s Store[R]) SelectOneOrNoneWhere(ctx context.Context, db Handle, partialQuery string, args ...any) (Option[R], error) { +func (s Store[R]) SelectOneOrNoneWhere(ctx context.Context, db gsql.Handle, partialQuery string, args ...any) (Option[R], error) { // NOTE: This function body should be as short as possible to reduce the binary size after monomorphization. // Any expression that does not depend on type R should be factored out into a reusable function. return noRowsToNone(s.SelectOneWhere(ctx, db, partialQuery, args...)) } -func selectOneWhere(ctx context.Context, db Handle, plan plan, v reflect.Value, partialQuery string, args []any) error { +func selectOneWhere(ctx context.Context, db gsql.Handle, plan plan, v reflect.Value, partialQuery string, args []any) error { if plan.Select.Query == "" { return errors.New("cannot execute SelectOneWhere() because query could not be autogenerated") } @@ -154,7 +154,7 @@ func selectOneWhere(ctx context.Context, db Handle, plan plan, v reflect.Value, return selectOne(ctx, db, plan, v, query, args) } -func selectOne(ctx context.Context, db Handle, plan plan, v reflect.Value, query string, args []any) error { +func selectOne(ctx context.Context, db gsql.Handle, plan plan, v reflect.Value, query string, args []any) error { for _, field := range plan.TransparentPointerStructFields { f := v.FieldByIndex(field.Index) f.Set(reflect.New(f.Type().Elem())) @@ -163,7 +163,7 @@ func selectOne(ctx context.Context, db Handle, plan plan, v reflect.Value, query for idx, index := range plan.Select.ScanIndexes { slots[idx] = v.FieldByIndex(index).Addr().Interface() } - stmt, err := db.OblastPrepare(ctx, query, false) + stmt, err := db.GSQLPrepare(ctx, query, false) if err != nil { return err } @@ -218,14 +218,14 @@ type PreparedSelectQuery[R any] struct { } // Select behaves the same as [Store.SelectWhere], but uses the query that was precomputed when q was constructed. -func (q PreparedSelectQuery[R]) Select(ctx context.Context, db Handle, args ...any) Selection[R] { +func (q PreparedSelectQuery[R]) Select(ctx context.Context, db gsql.Handle, args ...any) Selection[R] { // NOTE: This function body should be as short as possible to reduce the binary size after monomorphization. // Any expression that does not depend on type R should be factored out into a reusable function. return Selection[R]{startSelectQuery(ctx, db, q.store.plan, q.query, args...)} } // SelectOne behaves the same as [Store.SelectOneWhere], but uses the query that was precomputed when q was constructed. -func (q PreparedSelectQuery[R]) SelectOne(ctx context.Context, db Handle, args ...any) (R, error) { +func (q PreparedSelectQuery[R]) SelectOne(ctx context.Context, db gsql.Handle, args ...any) (R, error) { // NOTE: This function body should be as short as possible to reduce the binary size after monomorphization. // Any expression that does not depend on type R should be factored out into a reusable function. @@ -235,7 +235,7 @@ func (q PreparedSelectQuery[R]) SelectOne(ctx context.Context, db Handle, args . } // SelectOneOrNone is like SelectOne, but returns [None] instead of [sql.ErrNoRows]. -func (q PreparedSelectQuery[R]) SelectOneOrNone(ctx context.Context, db Handle, args ...any) (Option[R], error) { +func (q PreparedSelectQuery[R]) SelectOneOrNone(ctx context.Context, db gsql.Handle, args ...any) (Option[R], error) { return noRowsToNone(q.SelectOne(ctx, db, args...)) } @@ -254,7 +254,7 @@ type Selection[R any] struct { // This separate type does not have type arguments and thus is not duplicated by monomorphization. type selection struct { // from startSelectQuery() - Rows handle.Rows + Rows gsql.Rows Slots []any // NOTE: len(s.Slots) == len(s.Indexes) Err error // NOTE: if this field is set, all other fields will be unset // from plan -- cgit v1.3.1