@lunora/sql-store 0.0.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/README.md +59 -0
- package/package.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# @lunora/sql-store
|
|
2
|
+
|
|
3
|
+
**Internal.** The dialect-parameterized SQL store core shared by Lunora's
|
|
4
|
+
`.global()` table backends. One ORM implementation (`createSqlCtxDb`) drives any
|
|
5
|
+
SQL engine:
|
|
6
|
+
|
|
7
|
+
- **SQLite / D1** — via [`@lunora/d1`](../d1)
|
|
8
|
+
- **Postgres / MySQL** (PlanetScale, Neon, … over Cloudflare Hyperdrive) — via
|
|
9
|
+
[`@lunora/hyperdrive/global`](../hyperdrive)
|
|
10
|
+
|
|
11
|
+
You do not depend on this package directly. Depend on `@lunora/d1` or
|
|
12
|
+
`@lunora/hyperdrive`, which supply the concrete dialect and wrap the core.
|
|
13
|
+
|
|
14
|
+
## How it works
|
|
15
|
+
|
|
16
|
+
The core builds every statement as a composable **drizzle `SQL`** and renders it
|
|
17
|
+
for the target engine via drizzle's matching dialect (selected off
|
|
18
|
+
`dialect.name`). Drizzle owns identifier quoting (`"..."` vs `` `...` ``) and
|
|
19
|
+
placeholder numbering (`?` vs `$N`), so the core stays engine-blind without any
|
|
20
|
+
hand-rolled rewriting.
|
|
21
|
+
|
|
22
|
+
The small per-engine `SqlDialect` value object carries only what drizzle can't
|
|
23
|
+
infer from a dynamic, column-per-field schema: the framework columns every
|
|
24
|
+
global table carries, column and companion-table types, value encode/decode
|
|
25
|
+
(every engine stores SQLite-shaped values), `RETURNING` availability (with an
|
|
26
|
+
affected-rows fallback for MySQL), unique-violation detection, the MySQL index
|
|
27
|
+
key-prefix, and the system-catalog (`tableExists`) probe. Full-text search is
|
|
28
|
+
not part of the dialect — the core probes FTS5 availability on the `exec` at
|
|
29
|
+
runtime.
|
|
30
|
+
|
|
31
|
+
Reactivity is engine-independent: the writer is injected as `globalDb` into
|
|
32
|
+
`createShardCtxDb`, whose `broadcast` hook drives live queries no matter which
|
|
33
|
+
backend stores the row.
|
|
34
|
+
|
|
35
|
+
## Public exports
|
|
36
|
+
|
|
37
|
+
Both subpaths resolve to the same symbols (`./dialect` re-exports the dialect
|
|
38
|
+
seam from the root); consumers import everything from the root `@lunora/sql-store`.
|
|
39
|
+
|
|
40
|
+
- `createSqlCtxDb(options: SqlCtxDbOptions): DatabaseWriterLike` — builds the
|
|
41
|
+
store writer. `options` requires `dialect` and `exec` (the async SQL surface)
|
|
42
|
+
and `schema`; the rest (`auth`, `cdc`, `clock`, `idGenerator`,
|
|
43
|
+
`crossShardReader`/`crossShardCounter`, `maxRelationKeys`, `scheduler`) are
|
|
44
|
+
optional.
|
|
45
|
+
- `decodeGlobalRow(definition, row)` — decode a raw stored row back to its JS
|
|
46
|
+
shape via the table definition's validators.
|
|
47
|
+
- Migration runners (each takes `(exec, schema, dialect)`, or `(exec, dialect)`
|
|
48
|
+
for CDC): `runSqlGlobalTableMigrations`, `runSqlAggregateMigrations`,
|
|
49
|
+
`runSqlRankMigrations`, `runSqlSearchMigrations`, `runSqlCdcMigration`.
|
|
50
|
+
- CDC log helpers: `readSqlCdcChanges`, `trimSqlCdcChanges`.
|
|
51
|
+
- Value codec building blocks a dialect reuses for `encode`/`decode`:
|
|
52
|
+
`sqliteEncode`, `sqliteDecode`, `decodeBigint`, `tryJsonParse`,
|
|
53
|
+
`effectiveColumnKind`.
|
|
54
|
+
- Types: `SqlCtxDbOptions`, `SqlCtxExec`, `SqlDialect`, `SqlExec`,
|
|
55
|
+
`SqlRunResult`.
|
|
56
|
+
|
|
57
|
+
Writing a new engine adapter means supplying a `SqlDialect` value (see
|
|
58
|
+
[`@lunora/d1`](../d1)'s `sqliteDialect` for the reference) and an `exec` that
|
|
59
|
+
satisfies `SqlExec`/`SqlCtxExec`, then calling `createSqlCtxDb`.
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lunora/sql-store",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Internal dialect-parameterized SQL store core for Lunora .global() backends (D1, PlanetScale)",
|
|
5
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
6
|
+
"homepage": "https://lunora.sh",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/anolilab/lunora.git",
|
|
10
|
+
"directory": "packages/sql-store"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/anolilab/lunora/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"lunora",
|
|
17
|
+
"cloudflare",
|
|
18
|
+
"sql",
|
|
19
|
+
"sqlite",
|
|
20
|
+
"postgres",
|
|
21
|
+
"mysql",
|
|
22
|
+
"dialect",
|
|
23
|
+
"orm"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"README.md"
|
|
30
|
+
]
|
|
31
|
+
}
|