Skip to content

Commit 473cb73

Browse files
Copilothotlong
andcommitted
feat: enable Turso/libSQL driver for pnpm dev via TURSO_DATABASE_URL env var
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 6929a07 commit 473cb73

5 files changed

Lines changed: 55 additions & 4 deletions

File tree

.env.example

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# ─── Auth ──────────────────────────────────────────────────────────────────
2+
AUTH_SECRET=objectql-dev-secret-change-me-in-production
3+
4+
# ─── Turso / libSQL Driver ────────────────────────────────────────────────
5+
# Uncomment and set these to use Turso driver instead of MemoryDriver.
6+
#
7+
# Connection modes:
8+
# Remote (Cloud): TURSO_DATABASE_URL=libsql://my-db-orgname.turso.io
9+
# Local (Embedded file): TURSO_DATABASE_URL=file:./data/local.db
10+
# In-memory: TURSO_DATABASE_URL=:memory:
11+
#
12+
# TURSO_DATABASE_URL=file:./data/local.db
13+
# TURSO_AUTH_TOKEN=
14+
#
15+
# Embedded Replica (Hybrid) — sync a local file with a remote primary:
16+
# TURSO_SYNC_URL=libsql://my-db-orgname.turso.io
17+
# TURSO_SYNC_INTERVAL=60

ROADMAP.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ ObjectQL is the **Standard Protocol for AI Software Generation** — a universal
8989
-`@objectql/driver-turso` — Turso/libSQL driver (Phase A: Core Driver) with 125 tests, 3 connection modes (remote, local, embedded replica)
9090
-`@objectql/driver-turso` — Phase B: Multi-Tenant Router, Schema Diff Engine, Platform API Client, Driver Plugin (52 new tests, 177 total)
9191
- ✅ Fix test quality: replaced all `expect(true).toBe(true)` placeholder assertions with meaningful state checks across `plugin-optimizations`, `protocol-odata-v4`, `protocol-json-rpc`, and `protocol-graphql` (7 files, 10 assertions fixed)
92+
-`pnpm dev` supports Turso/libSQL driver via `TURSO_DATABASE_URL` env var (local embedded, remote cloud, or embedded replica modes)
9293

9394
---
9495

objectstack.config.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { ValidatorPlugin } from '@objectql/plugin-validator';
3131
import { FormulaPlugin } from '@objectql/plugin-formula';
3232
import { createApiRegistryPlugin } from '@objectstack/core';
3333
import { MemoryDriver } from '@objectql/driver-memory';
34+
import { createTursoDriver } from '@objectql/driver-turso';
3435
import * as fs from 'fs';
3536
import * as yaml from 'js-yaml';
3637

@@ -58,9 +59,32 @@ function loadObjects(dir: string) {
5859

5960
const projectTrackerDir = path.join(__dirname, 'examples/showcase/project-tracker/src');
6061

62+
// Choose driver based on environment — Turso when TURSO_DATABASE_URL is set,
63+
// MemoryDriver otherwise (zero-config fallback for quick starts).
64+
function createDefaultDriver() {
65+
const tursoUrl = process.env.TURSO_DATABASE_URL;
66+
if (tursoUrl) {
67+
console.log(`🗄️ Driver: Turso (${tursoUrl})`);
68+
const syncUrl = process.env.TURSO_SYNC_URL;
69+
return createTursoDriver({
70+
url: tursoUrl,
71+
authToken: process.env.TURSO_AUTH_TOKEN,
72+
syncUrl,
73+
sync: syncUrl
74+
? {
75+
intervalSeconds: Number(process.env.TURSO_SYNC_INTERVAL) || 60,
76+
onConnect: true,
77+
}
78+
: undefined,
79+
});
80+
}
81+
console.log('🗄️ Driver: Memory (in-memory, non-persistent)');
82+
return new MemoryDriver();
83+
}
84+
6185
// Shared driver instance — registered as 'driver.default' service for
6286
// upstream ObjectQLPlugin discovery and passed to QueryPlugin for query execution.
63-
const defaultDriver = new MemoryDriver();
87+
const defaultDriver = createDefaultDriver();
6488

6589
export default {
6690
metadata: {
@@ -73,14 +97,19 @@ export default {
7397
createApiRegistryPlugin(),
7498
new HonoServerPlugin({}),
7599
new ConsolePlugin(),
76-
// Register MemoryDriver as 'driver.default' service so upstream
100+
// Register the active driver as 'driver.default' service so upstream
77101
// ObjectQLPlugin can discover it during start() phase.
78102
{
79-
name: 'driver-memory',
103+
name: 'driver-default',
80104
init: async (ctx: any) => {
81105
ctx.registerService('driver.default', defaultDriver);
82106
},
83-
start: async () => {},
107+
start: async () => {
108+
// Connect Turso driver if applicable (MemoryDriver has no connect method)
109+
if ('connect' in defaultDriver && typeof (defaultDriver as { connect: () => Promise<void> }).connect === 'function') {
110+
await (defaultDriver as { connect: () => Promise<void> }).connect();
111+
}
112+
},
84113
},
85114
// Upstream ObjectQLPlugin from @objectstack/objectql:
86115
// - Registers objectql, metadata, data, protocol services

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@objectql/cli": "workspace:*",
2929
"@objectql/core": "workspace:*",
3030
"@objectql/driver-memory": "^4.2.2",
31+
"@objectql/driver-turso": "workspace:*",
3132
"@objectql/example-enterprise-erp": "workspace:*",
3233
"@objectql/example-project-tracker": "workspace:*",
3334
"@objectql/plugin-security": "workspace:*",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)