@lunora/hyperdrive 1.0.0-alpha.101 → 1.0.0-alpha.102
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 +18 -4
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -83,19 +83,33 @@ pnpm add mysql2 # mysql2 → fromMysql2
|
|
|
83
83
|
|
|
84
84
|
## Usage
|
|
85
85
|
|
|
86
|
-
`ctx.sql` is wired by codegen onto `ActionCtx` only — never `QueryCtx`/`MutationCtx
|
|
86
|
+
`ctx.sql` is wired by codegen onto `ActionCtx` only — never `QueryCtx`/`MutationCtx`, and it is `readonly`, so it is built once at the app level rather than assigned in a handler. Codegen emits a `sql` config thunk for it (`createHyperdrive` returns connection info; only you know which driver wraps it):
|
|
87
87
|
|
|
88
88
|
```ts
|
|
89
|
+
// src/server/index.ts
|
|
90
|
+
import type { HyperdriveLike } from "@lunora/hyperdrive";
|
|
89
91
|
import { createHyperdrive, fromPostgresJs } from "@lunora/hyperdrive";
|
|
90
92
|
import postgres from "postgres";
|
|
91
93
|
|
|
94
|
+
import { defineApp } from "../../lunora/_generated/app";
|
|
95
|
+
|
|
96
|
+
const app = defineApp<Env>()
|
|
97
|
+
.shard((env) => env.SHARD)
|
|
98
|
+
.hyperdrive((env) => fromPostgresJs(postgres(createHyperdrive(env.HYPERDRIVE as HyperdriveLike).connectionString)))
|
|
99
|
+
.build();
|
|
100
|
+
|
|
101
|
+
export const ShardDO = app.ShardDO;
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Hand-composing the worker instead? The same thunk is `createShardDO({ sql: (env) => … })`. Without it, every `ctx.sql` method throws a message pointing back at this wiring.
|
|
105
|
+
|
|
106
|
+
Handlers then just read it. The procedure builders (`action`, `v`) and `api` come from your app-local generated modules:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
92
109
|
import { api } from "@/lunora/_generated/api";
|
|
93
110
|
import { action, v } from "@/lunora/_generated/server";
|
|
94
111
|
|
|
95
112
|
export const syncCustomer = action.input({ orgId: v.string() }).action(async ({ args: { orgId }, ctx }) => {
|
|
96
|
-
const { connectionString } = createHyperdrive(ctx.env.HYPERDRIVE);
|
|
97
|
-
ctx.sql = fromPostgresJs(postgres(connectionString));
|
|
98
|
-
|
|
99
113
|
const rows = await ctx.sql.query<{ id: string; name: string }>("select id, name from customers where org = $1", [orgId]);
|
|
100
114
|
|
|
101
115
|
// Want it reactive? Project it into a Lunora table — THIS write is tracked.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/hyperdrive",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.102",
|
|
4
4
|
"description": "Bring-your-own Postgres/MySQL for Lunora via Cloudflare Hyperdrive: a driver-agnostic, action-only ctx.sql",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
54
|
-
"@lunora/platform": "1.0.0-alpha.
|
|
55
|
-
"@lunora/shard-engine": "1.0.0-alpha.
|
|
56
|
-
"@lunora/sql-store": "1.0.0-alpha.
|
|
53
|
+
"@lunora/errors": "1.0.0-alpha.27",
|
|
54
|
+
"@lunora/platform": "1.0.0-alpha.23",
|
|
55
|
+
"@lunora/shard-engine": "1.0.0-alpha.49",
|
|
56
|
+
"@lunora/sql-store": "1.0.0-alpha.102",
|
|
57
57
|
"drizzle-orm": "^0.45.2"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|