@schemic/surrealdb 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vertio Solutions
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # @schemic/surrealdb
2
+
3
+ The SurrealDB driver for [Schemic](https://github.com/schemichq/schemic) — author
4
+ your SurrealDB schema in TypeScript and generate SurrealQL DDL, types, and
5
+ migrations from that one definition.
6
+
7
+ - Define tables and relations with `s.*`, a drop-in for [Zod](https://zod.dev)'s `z.*`.
8
+ - Generate `DEFINE TABLE` / `DEFINE FIELD` DDL, run reviewable migrations, and introspect a live database back into TypeScript.
9
+ - Read and write rows as typed values via codecs (`datetime` ⇄ `Date`, `uuid`, record links, …).
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ bun add @schemic/cli @schemic/surrealdb zod
15
+ ```
16
+
17
+ `zod` is a required peer. `@surrealdb/node` is an optional peer (the embedded
18
+ in-memory engine `schemic check` can replay into). The `surrealdb` SDK ships with
19
+ the driver — you only import it directly in seed or app query code.
20
+
21
+ ## Quick start
22
+
23
+ Scaffold a project (`sc` is the short alias for `schemic`):
24
+
25
+ ```bash
26
+ sc init
27
+ ```
28
+
29
+ `init` writes a `schemic.config.ts`, a sample `user` schema, a seed stub, and
30
+ `.env.example`. The sample schema:
31
+
32
+ ```ts
33
+ // database/schema/tables/user.ts
34
+ import { defineTable, s, surql } from "@schemic/surrealdb";
35
+
36
+ export const User = defineTable("user", {
37
+ name: s.string().$assert(surql`string::len($value) > 0`),
38
+ email: s.email().unique(),
39
+ createdAt: s.datetime().$default(surql`time::now()`).$readonly(),
40
+ }).schemafull();
41
+ ```
42
+
43
+ …which generates this SurrealQL DDL (the `id` field is provided automatically):
44
+
45
+ ```surql
46
+ DEFINE TABLE user TYPE NORMAL SCHEMAFULL;
47
+ DEFINE FIELD name ON TABLE user TYPE string ASSERT string::len($value) > 0;
48
+ DEFINE FIELD email ON TABLE user TYPE string ASSERT string::is_email($value);
49
+ DEFINE INDEX user_email_idx ON TABLE user FIELDS email UNIQUE;
50
+ DEFINE FIELD createdAt ON TABLE user TYPE datetime DEFAULT time::now() READONLY;
51
+ ```
52
+
53
+ The connection lives in `schemic.config.ts` — a named connection from the
54
+ `surrealConnection` factory (no `driver:` string to keep in sync):
55
+
56
+ ```ts
57
+ import { defineConfig } from "@schemic/core/config";
58
+ import { surrealConnection } from "@schemic/surrealdb";
59
+
60
+ export default defineConfig({
61
+ connections: {
62
+ default: surrealConnection({
63
+ schema: "./database/schema",
64
+ url: process.env.SURREAL_URL ?? "ws://127.0.0.1:8000/rpc",
65
+ namespace: process.env.SURREAL_NAMESPACE ?? "app",
66
+ database: process.env.SURREAL_DATABASE ?? "app",
67
+ username: process.env.SURREAL_USER,
68
+ password: process.env.SURREAL_PASS,
69
+ authLevel: "root", // "root" | "namespace" | "database"
70
+ }),
71
+ },
72
+ });
73
+ ```
74
+
75
+ Then drive it from the CLI:
76
+
77
+ ```bash
78
+ sc diff # preview changes vs the last snapshot (--ts for a TypeScript view)
79
+ sc gen # write a migration for the pending change
80
+ sc migrate # apply pending migrations
81
+ sc seed # run database/seed.ts against a connection
82
+ sc status # show applied vs pending migrations
83
+ sc pull # introspect a live database back into TypeScript
84
+ ```
85
+
86
+ ## Reading & writing rows
87
+
88
+ A table definition carries codecs that bridge your app values and the database
89
+ wire format. `decode` turns a returned row into typed values (a `datetime`
90
+ becomes a `Date`, a `uuid` a string, record links resolve); `encode` and
91
+ `encodePartial` build the payloads you write back. You keep the `surrealdb` SDK
92
+ for queries — Schemic owns the schema, DDL, migrations, and row types.
93
+
94
+ ## Docs
95
+
96
+ Full guides, concepts, and reference live at
97
+ [surreal.schemic.dev/docs](https://surreal.schemic.dev/docs). For a
98
+ feature-by-feature map, see [docs/COVERAGE.md](docs/COVERAGE.md). This package is
99
+ part of the [Schemic](https://github.com/schemichq/schemic) toolkit.
100
+
101
+ ## License
102
+
103
+ [MIT](./LICENSE) © Vertio Solutions