aboutsummaryrefslogtreecommitdiff
path: root/store.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-04-11 20:19:12 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-04-11 20:20:03 +0200
commite9d31443f01eda2ecee66dbc25f154a6949a9c97 (patch)
tree1824c7dc3290e4d38ab111522938e8a33e2f9618 /store.go
parent3d28ce0650fc85ca054a608bce32f88f2d90295f (diff)
downloadgo-oblast-e9d31443f01eda2ecee66dbc25f154a6949a9c97.tar.gz
reorganize the API from type DB to type Store
Diffstat (limited to 'store.go')
-rw-r--r--store.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/store.go b/store.go
new file mode 100644
index 0000000..4ab0f4b
--- /dev/null
+++ b/store.go
@@ -0,0 +1,35 @@
+// SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net>
+// SPDX-License-Identifier: Apache-2.0
+
+package oblast
+
+import (
+ "reflect"
+
+ "go.xyrillian.de/oblast/internal"
+)
+
+// Store is the main interface of this library.
+// It holds information on how to read and write data into record type R, and can also be used to execute autogenerated queries if the respective [PlanOption]s were provided during [NewStore].
+type Store[R any] struct {
+ plan internal.Plan
+}
+
+// NewStore initializes a store for record type R.
+func NewStore[R any](dialect Dialect, opts ...PlanOption) (Store[R], error) {
+ var popts internal.PlanOpts
+ for _, opt := range opts {
+ opt(&popts)
+ }
+ plan, err := internal.BuildPlan(reflect.TypeFor[R](), dialect, popts)
+ return Store[R]{plan}, err
+}
+
+// MustNewStore is like [NewStore], but panics on error.
+func MustNewStore[R any](dialect Dialect, opts ...PlanOption) Store[R] {
+ store, err := NewStore[R](dialect, opts...)
+ if err != nil {
+ panic(err.Error())
+ }
+ return store
+}