aboutsummaryrefslogtreecommitdiff
path: root/db.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-04-10 14:55:26 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-04-10 14:56:39 +0200
commitbce3df549ff4ccc8895697a3222269bd14fc22a4 (patch)
tree1e1338ec9e9a15b0096b31e692e646d081d71677 /db.go
parent03b874fdef2003ef9bfff7f4ce3021d594211a30 (diff)
downloadgo-oblast-bce3df549ff4ccc8895697a3222269bd14fc22a4.tar.gz
start reflecting on types to build a query plan
Diffstat (limited to 'db.go')
-rw-r--r--db.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/db.go b/db.go
new file mode 100644
index 0000000..a511d6f
--- /dev/null
+++ b/db.go
@@ -0,0 +1,34 @@
+// SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net>
+// SPDX-License-Identifier: Apache-2.0
+
+package oblast
+
+import (
+ "context"
+ "database/sql"
+ "reflect"
+ "sync"
+)
+
+// DB wraps an [sql.DB] instance for use with Oblast's query interface.
+type DB struct {
+ *sql.DB
+ dialect Dialect
+ plans map[reflect.Type]plan
+ planMutex sync.Mutex
+}
+
+func NewDB(db *sql.DB, dialect Dialect) *DB {
+ return &DB{
+ DB: db,
+ dialect: dialect,
+ plans: make(map[reflect.Type]plan),
+ }
+}
+
+func Keks[T IsTable](ctx context.Context, db *DB) error {
+ _, err := db.getPlan(reflect.TypeFor[T]())
+ return err
+}
+
+// TODO: Begin() -> custom Tx type