@lunora/hyperdrive 1.0.0-alpha.100 → 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
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/dist/global.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createSqlCtxDb as c}from"@lunora/sql-store";import{postgresDialect as l,mysqlDialect as s}from"./packem_shared/mysqlDialect-
|
|
1
|
+
import{createSqlCtxDb as c}from"@lunora/sql-store";import{postgresDialect as l,mysqlDialect as s}from"./packem_shared/mysqlDialect-v1MlKdIN.mjs";import{buildMysqlExec as a,buildPgExec as i}from"./packem_shared/buildMysqlExec-CPwtojyL.mjs";import{createPgVectorIndex as d}from"./packem_shared/createPgVectorIndex-DcpguGpe.mjs";const r=({engine:e,exec:t,...o})=>c({...o,dialect:e==="postgres"?l:s,exec:t}),p=(e,t)=>r({...t,engine:"postgres",exec:i(e)}),g=(e,t)=>r({...t,engine:"mysql",exec:a(e)});export{a as buildMysqlExec,i as buildPgExec,r as createHyperdriveGlobalCtxDb,g as createMysqlGlobalCtxDb,d as createPgVectorIndex,p as createPostgresGlobalCtxDb,s as mysqlDialect,l as postgresDialect};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{sql as t}from"drizzle-orm";const i="__id__",a="__vector__",r=e=>t`${t.identifier(e)}.${t.identifier(a)}`,c=e=>t`to_tsvector('simple', ${e})`,o=e=>t`to_tsquery('simple', ${e.map((n,s)=>s===e.length-1?`${n}:*`:n).join(" & ")})`,m=/duplicate key value violates unique constraint/iu,E=e=>{switch(e){case"bigint":return"VARCHAR(64)";case"boolean":return"TINYINT";case"bytes":return"LONGBLOB";case"date":case"number":case"timestamp":return"DOUBLE";default:return"LONGTEXT"}},T=/TEXT|BLOB/u,u={companionTypes:{autoincrementPrimaryKey:"BIGSERIAL PRIMARY KEY",integer:"INTEGER",key:"TEXT",real:"DOUBLE PRECISION",text:"TEXT"},columnType:e=>{switch(e){case"boolean":return"INTEGER";case"bytes":return"BYTEA";case"date":case"number":case"timestamp":return"DOUBLE PRECISION";default:return"TEXT"}},frameworkColumns:()=>[{name:"id",type:"TEXT PRIMARY KEY"},{name:"_creationTime",type:"DOUBLE PRECISION NOT NULL"}],isUniqueViolation:e=>{const{code:n}=e;return n==="23505"||e instanceof Error&&m.test(e.message)},maxTableColumns:1600,name:"postgres",supportsFts5:!1,nativeTextSearch:{createCompanion:(e,n)=>t`CREATE TABLE IF NOT EXISTS ${t.identifier(e)} (${t.identifier(i)} ${t.raw(n)} PRIMARY KEY, ${t.identifier(a)} tsvector)`,createIndexes:e=>[t`CREATE INDEX IF NOT EXISTS ${t.identifier(`${e}__gin`)} ON ${t.identifier(e)} USING GIN (${t.identifier(a)})`],indexDocument:(e,n,s)=>t`INSERT INTO ${t.identifier(e)} (${t.identifier(i)}, ${t.identifier(a)}) VALUES (${n}, ${c(s)})`,matches:(e,n)=>t`${r(e)} @@ ${o(n)}`,rank:(e,n)=>t`ts_rank_cd(${r(e)}, ${o(n)})`},supportsReturning:!0,textPatternOperatorClass:"text_pattern_ops",tableExists:e=>t`SELECT table_name FROM information_schema.tables WHERE table_schema = ANY (current_schemas(false)) AND table_name = ${e}`},R={affectedRows:e=>e.rowsAffected,companionTypes:{autoincrementPrimaryKey:"BIGINT AUTO_INCREMENT PRIMARY KEY",integer:"INTEGER",key:"VARCHAR(768)",real:"DOUBLE",text:"LONGTEXT"},columnType:E,frameworkColumns:()=>[{name:"id",type:"VARCHAR(768) PRIMARY KEY"},{name:"_creationTime",type:"DOUBLE NOT NULL"}],indexKeyPrefix:e=>T.test(E(e))?191:void 0,isUniqueViolation:e=>{const n=e;return n.errno===1062||n.code==="ER_DUP_ENTRY"},maxTableColumns:4096,name:"mysql",supportsFts5:!1,supportsReturning:!1,tableExists:e=>t`SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ${e}`};export{R as mysqlDialect,u as postgresDialect};
|
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": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{sqliteEncode as E,sqliteDecode as m}from"@lunora/sql-store";import{sql as t}from"drizzle-orm";const i="__id__",a="__vector__",r=e=>t`${t.identifier(e)}.${t.identifier(a)}`,T=e=>t`to_tsvector('simple', ${e})`,o=e=>t`to_tsquery('simple', ${e.map((n,s)=>s===e.length-1?`${n}:*`:n).join(" & ")})`,l=/duplicate key value violates unique constraint/iu,c=e=>{switch(e){case"array":case"object":case"record":return"JSON";case"bigint":return"VARCHAR(64)";case"boolean":return"TINYINT";case"bytes":return"LONGBLOB";case"date":case"number":case"timestamp":return"DOUBLE";default:return"LONGTEXT"}},u=/TEXT|BLOB/u,_={companionTypes:{autoincrementPrimaryKey:"BIGSERIAL PRIMARY KEY",integer:"INTEGER",key:"TEXT",real:"DOUBLE PRECISION",text:"TEXT"},columnType:e=>{switch(e){case"boolean":return"INTEGER";case"bytes":return"BYTEA";case"date":case"number":case"timestamp":return"DOUBLE PRECISION";default:return"TEXT"}},decode:m,encode:E,frameworkColumns:()=>[{name:"id",type:"TEXT PRIMARY KEY"},{name:"_creationTime",type:"DOUBLE PRECISION NOT NULL"}],isUniqueViolation:e=>{const{code:n}=e;return n==="23505"||e instanceof Error&&l.test(e.message)},maxTableColumns:1600,name:"postgres",supportsFts5:!1,nativeTextSearch:{createCompanion:(e,n)=>t`CREATE TABLE IF NOT EXISTS ${t.identifier(e)} (${t.identifier(i)} ${t.raw(n)} PRIMARY KEY, ${t.identifier(a)} tsvector)`,createIndexes:e=>[t`CREATE INDEX IF NOT EXISTS ${t.identifier(`${e}__gin`)} ON ${t.identifier(e)} USING GIN (${t.identifier(a)})`],indexDocument:(e,n,s)=>t`INSERT INTO ${t.identifier(e)} (${t.identifier(i)}, ${t.identifier(a)}) VALUES (${n}, ${T(s)})`,matches:(e,n)=>t`${r(e)} @@ ${o(n)}`,rank:(e,n)=>t`ts_rank_cd(${r(e)}, ${o(n)})`},supportsReturning:!0,textPatternOperatorClass:"text_pattern_ops",tableExists:e=>t`SELECT table_name FROM information_schema.tables WHERE table_schema = ANY (current_schemas(false)) AND table_name = ${e}`},I={affectedRows:e=>e.rowsAffected,companionTypes:{autoincrementPrimaryKey:"BIGINT AUTO_INCREMENT PRIMARY KEY",integer:"INTEGER",key:"VARCHAR(768)",real:"DOUBLE",text:"LONGTEXT"},columnType:c,decode:m,encode:E,frameworkColumns:()=>[{name:"id",type:"VARCHAR(768) PRIMARY KEY"},{name:"_creationTime",type:"DOUBLE NOT NULL"}],indexKeyPrefix:e=>u.test(c(e))?191:void 0,isUniqueViolation:e=>{const n=e;return n.errno===1062||n.code==="ER_DUP_ENTRY"},maxTableColumns:4096,name:"mysql",supportsFts5:!1,supportsReturning:!1,tableExists:e=>t`SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ${e}`};export{I as mysqlDialect,_ as postgresDialect};
|