summaryrefslogtreecommitdiff
path: root/query.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-07-31 21:39:56 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-07-31 23:35:23 +0200
commit656e5dcce132716b39005814407224f989aa8c2d (patch)
treeab0a6d3a046170f0ace6a6e4ab3668ce0af811ae /query.go
parenta2f8d7a68f324d5b4086148571f990409425e22a (diff)
downloadgo-oblast-656e5dcce132716b39005814407224f989aa8c2d.tar.gz
replace types Handle, DB, Conn, Tx with their gg/gsql equivalents
Diffstat (limited to 'query.go')
-rw-r--r--query.go25
1 files changed, 12 insertions, 13 deletions
diff --git a/query.go b/query.go
index b92106a..e9d6862 100644
--- a/query.go
+++ b/query.go
@@ -10,8 +10,7 @@ import (
"reflect"
"go.xyrillian.de/gg/errext"
-
- "go.xyrillian.de/oblast/handle"
+ "go.xyrillian.de/gg/gsql"
)
// PrepareThreshold is a tuning parameter for the strategy used by all methods of [Store] operating on batches of records provided by the caller
@@ -29,12 +28,12 @@ import (
var PrepareThreshold int = 8
// prepare behaves like [Handle.Prepare].
-func prepare(ctx context.Context, db Handle, query, operation string, inputSize int) (handle.Statement, error) {
+func prepare(ctx context.Context, db gsql.Handle, query, operation string, inputSize int) (gsql.Statement, error) {
if query == "" {
return nil, fmt.Errorf("cannot execute %s() because query could not be autogenerated", operation)
}
- return db.OblastPrepare(ctx, query, inputSize >= PrepareThreshold)
+ return db.GSQLPrepare(ctx, query, inputSize >= PrepareThreshold)
}
// Insert executes an SQL INSERT statement for each of the provided records.
@@ -48,7 +47,7 @@ func prepare(ctx context.Context, db Handle, query, operation string, inputSize
// Returns an error if any of the `records` has a non-zero value in any column marked as `db:",auto"`.
// Records that already exist in the database should be handled with [Store.Update] instead.
// To automatically decide between INSERT and UPDATE on a per-record basis, use [Store.Upsert] instead.
-func (s Store[R]) Insert(ctx context.Context, db Handle, records ...*R) error {
+func (s Store[R]) Insert(ctx context.Context, db gsql.Handle, records ...*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.
@@ -59,7 +58,7 @@ func (s Store[R]) Insert(ctx context.Context, db Handle, records ...*R) error {
return s.insertUsing(ctx, stmt, db, records)
}
-func (s Store[R]) insertUsing(ctx context.Context, stmt handle.Statement, db Handle, records []*R) error {
+func (s Store[R]) insertUsing(ctx context.Context, stmt gsql.Statement, db gsql.Handle, records []*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.
@@ -85,7 +84,7 @@ func (s Store[R]) insertUsing(ctx context.Context, stmt handle.Statement, db Han
return errext.WithCleanup(nil, "Stmt.Close", stmt.Close())
}
-func insertRecord(ctx context.Context, plan plan, v reflect.Value, recordIndex int, stmt handle.Statement, argumentIndexes [][]int, argumentSlots []any, scanIndexes [][]int, scanSlots []any) error {
+func insertRecord(ctx context.Context, plan plan, v reflect.Value, recordIndex int, stmt gsql.Statement, argumentIndexes [][]int, argumentSlots []any, scanIndexes [][]int, scanSlots []any) error {
for idx, index := range argumentIndexes {
argumentSlots[idx] = v.FieldByIndex(index).Interface()
}
@@ -156,7 +155,7 @@ func checkTransparentPointerStructFieldsInitialized(operation string, recordInde
// Returns [MissingRecordError] if any of the records does not exist in the database, that is, if for any of the records, the database contains no row with the same primary key values.
//
// Returns an error if [NewStore] was called without the [TableNameIs] or [PrimaryKeyIs] options, which are both required to generate a query for this method.
-func (s Store[R]) Update(ctx context.Context, db Handle, records ...R) error {
+func (s Store[R]) Update(ctx context.Context, db gsql.Handle, records ...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.
@@ -187,7 +186,7 @@ func (s Store[R]) Update(ctx context.Context, db Handle, records ...R) error {
return errext.WithCleanup(nil, "Stmt.Close", stmt.Close())
}
-func updateRecord(ctx context.Context, v reflect.Value, recordIndex int, stmt handle.Statement, argumentIndexes [][]int, argumentSlots []any) (int64, error) {
+func updateRecord(ctx context.Context, v reflect.Value, recordIndex int, stmt gsql.Statement, argumentIndexes [][]int, argumentSlots []any) (int64, error) {
for idx, index := range argumentIndexes {
argumentSlots[idx] = v.FieldByIndex(index).Interface()
}
@@ -205,7 +204,7 @@ func updateRecord(ctx context.Context, v reflect.Value, recordIndex int, stmt ha
// Delete executes an SQL DELETE statement for each of the provided records, using their primary keys to locate the respective table rows.
//
// Returns an error if [NewStore] was called without the [TableNameIs] or [PrimaryKeyIs] options, which are both required to generate a query for this method.
-func (s Store[R]) Delete(ctx context.Context, db Handle, records ...R) error {
+func (s Store[R]) Delete(ctx context.Context, db gsql.Handle, records ...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.
@@ -230,7 +229,7 @@ func (s Store[R]) Delete(ctx context.Context, db Handle, records ...R) error {
return errext.WithCleanup(nil, "Stmt.Close", stmt.Close())
}
-func deleteRecord(ctx context.Context, plan plan, v reflect.Value, recordIndex int, stmt handle.Statement, argumentIndexes [][]int, argumentSlots []any) error {
+func deleteRecord(ctx context.Context, plan plan, v reflect.Value, recordIndex int, stmt gsql.Statement, argumentIndexes [][]int, argumentSlots []any) error {
err := checkTransparentPointerStructFieldsInitialized("DELETE", recordIndex, v, plan, true)
if err != nil {
return errext.WithCleanup(err, "Stmt.Close", stmt.Close())
@@ -253,7 +252,7 @@ func deleteRecord(ctx context.Context, plan plan, v reflect.Value, recordIndex i
// Returns an error if [NewStore] was called without the [TableNameIs] or [PrimaryKeyIs] options, which are both required to generate the respective queries for this method.
// - For record types that do not have fields declared with the "auto" tag, an INSERT ... ON CONFLICT statement is used.
// Returns an error if [NewStore] was called without the [TableNameIs] option, which is required to generate a query for this method.
-func (s Store[R]) Upsert(ctx context.Context, db Handle, records ...*R) error {
+func (s Store[R]) Upsert(ctx context.Context, db gsql.Handle, records ...*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.
@@ -281,7 +280,7 @@ func (s Store[R]) Upsert(ctx context.Context, db Handle, records ...*R) error {
return err
}
-func (s Store[R]) doUpsert(ctx context.Context, db Handle, insertStmt, updateStmt handle.Statement, records []*R) error {
+func (s Store[R]) doUpsert(ctx context.Context, db gsql.Handle, insertStmt, updateStmt gsql.Statement, records []*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.