aboutsummaryrefslogtreecommitdiff
path: root/markers.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 /markers.go
parent03b874fdef2003ef9bfff7f4ce3021d594211a30 (diff)
downloadgo-oblast-bce3df549ff4ccc8895697a3222269bd14fc22a4.tar.gz
start reflecting on types to build a query plan
Diffstat (limited to 'markers.go')
-rw-r--r--markers.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/markers.go b/markers.go
new file mode 100644
index 0000000..e62fe52
--- /dev/null
+++ b/markers.go
@@ -0,0 +1,44 @@
+// SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net>
+// SPDX-License-Identifier: Apache-2.0
+
+package oblast
+
+// seal is a private type that appears in interface definitions below,
+// to ensure that only types from this package can implement these interfaces.
+type seal struct{}
+
+// TableInfo is a marker for struct types that correspond to tables.
+// Put this as an embedded field on your struct type and put the table name in the field's `db` tag.
+//
+// // For example, this struct type...
+// type LogEntry struct {
+// oblast.TableInfo `db:"log_entries"`
+// oblast.PrimaryKeyInfo `db:"id"`
+// ID int64 `db:"id,auto"`
+// CreatedAt time.Time `db:"created_at"`
+// Message string `db:"message"`
+// }
+// // ...corresponds to this table schema (shown here in PostgreSQL syntax):
+// CREATE TABLE log_entries (
+// id BIGSERIAL NOT NULL PRIMARY KEY,
+// created_at TIMESTAMPTZ NOT NULL,
+// message TEXT NOT NULL
+// );
+//
+// This marker is required for all operations that use autogenerated SQL statements.
+type TableInfo struct{}
+
+// isTable implements the IsTable interface.
+func (TableInfo) isTable(seal) {}
+
+// IsTable is implemented by all types that have an embedded field of type [TableInfo].
+type IsTable interface {
+ isTable(seal)
+}
+
+// PrimaryKeyInfo is a marker for struct types that correspond to tables with a primary key.
+// Put this as an embedded field on your struct type and list the columns of the primary key in the field's `db` tag,
+// as shown on the example for type [TableInfo].
+//
+// This marker is required for all UPDATE and DELETE operations that use autogenerated SQL statements.
+type PrimaryKeyInfo struct{}