aboutsummaryrefslogtreecommitdiff
path: root/oblast.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-04-12 16:45:59 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-04-12 16:45:59 +0200
commit8d60f626d819f8bdb038ce619d00946442cc2594 (patch)
tree672f828af4a7ad098d41f3f98f45efa45f4c3635 /oblast.go
parente9d31443f01eda2ecee66dbc25f154a6949a9c97 (diff)
downloadgo-oblast-8d60f626d819f8bdb038ce619d00946442cc2594.tar.gz
add Handle interface
Diffstat (limited to 'oblast.go')
-rw-r--r--oblast.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/oblast.go b/oblast.go
index 9ed60a4..be1571e 100644
--- a/oblast.go
+++ b/oblast.go
@@ -40,7 +40,11 @@
// }
package oblast // import "go.xyrillian.de/oblast"
-import "go.xyrillian.de/oblast/internal"
+import (
+ "database/sql"
+
+ "go.xyrillian.de/oblast/internal"
+)
// PlanOption is an option that can be given to NewStore() to influence query planning for a certain type of record.
type PlanOption func(*internal.PlanOpts)
@@ -56,3 +60,18 @@ func TableNameIs(name string) PlanOption {
func PrimaryKeyIs(columnNames ...string) PlanOption {
return func(opts *internal.PlanOpts) { opts.PrimaryKeyColumnNames = columnNames }
}
+
+// Handle is an interface for functions providing direct DB access.
+// It covers methods provided by both *sql.DB and *sql.Tx, thus allowing functions using it to be used both within and outside of transactions.
+type Handle interface {
+ Exec(query string, args ...any) (sql.Result, error)
+ Prepare(query string) (*sql.Stmt, error)
+ Query(query string, args ...any) (*sql.Rows, error)
+ QueryRow(query string, args ...any) *sql.Row
+}
+
+// static assertion that the respective types implement the interface
+var (
+ _ Handle = &sql.DB{}
+ _ Handle = &sql.Tx{}
+)