Skip to content

Commit 72c1aea

Browse files
authored
Merge pull request #425 from objectstack-ai/copilot/add-turso-driver-support
2 parents 593a37a + df8031e commit 72c1aea

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

.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
@@ -90,6 +90,7 @@ ObjectQL is the **Standard Protocol for AI Software Generation** — a universal
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)
9292
- ✅ Plugin-based metadata auto-loading: `createAppPlugin()` factory in `@objectql/platform-node` replaces manual `loadObjects()`. Metadata registered as `app.*` services for upstream ObjectQLPlugin auto-discovery. Added `MetadataRegistry.listEntries()` and 8 new tests.
93+
-`pnpm dev` supports Turso/libSQL driver via `TURSO_DATABASE_URL` env var (local embedded, remote cloud, or embedded replica modes)
9394

9495
---
9596

objectstack.config.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,35 @@ 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 { createAppPlugin } from '@objectql/platform-node';
3536

37+
// Choose driver based on environment — Turso when TURSO_DATABASE_URL is set,
38+
// MemoryDriver otherwise (zero-config fallback for quick starts).
39+
function createDefaultDriver() {
40+
const tursoUrl = process.env.TURSO_DATABASE_URL;
41+
if (tursoUrl) {
42+
console.log(`🗄️ Driver: Turso (${tursoUrl})`);
43+
const syncUrl = process.env.TURSO_SYNC_URL;
44+
return createTursoDriver({
45+
url: tursoUrl,
46+
authToken: process.env.TURSO_AUTH_TOKEN,
47+
syncUrl,
48+
sync: syncUrl
49+
? {
50+
intervalSeconds: Number(process.env.TURSO_SYNC_INTERVAL) || 60,
51+
onConnect: true,
52+
}
53+
: undefined,
54+
});
55+
}
56+
console.log('🗄️ Driver: Memory (in-memory, non-persistent)');
57+
return new MemoryDriver();
58+
}
59+
3660
// Shared driver instance — registered as 'driver.default' service for
3761
// upstream ObjectQLPlugin discovery and passed to QueryPlugin for query execution.
38-
const defaultDriver = new MemoryDriver();
62+
const defaultDriver = createDefaultDriver();
3963

4064
// App plugins: each business module is loaded via createAppPlugin.
4165
// ObjectLoader recursively scans for *.object.yml, *.view.yml, *.permission.yml, etc.
@@ -59,14 +83,19 @@ export default {
5983
createApiRegistryPlugin(),
6084
new HonoServerPlugin({}),
6185
new ConsolePlugin(),
62-
// Register MemoryDriver as 'driver.default' service so upstream
86+
// Register the active driver as 'driver.default' service so upstream
6387
// ObjectQLPlugin can discover it during start() phase.
6488
{
65-
name: 'driver-memory',
89+
name: 'driver-default',
6690
init: async (ctx: any) => {
6791
ctx.registerService('driver.default', defaultDriver);
6892
},
69-
start: async () => {},
93+
start: async () => {
94+
// Connect Turso driver if applicable (MemoryDriver has no connect method)
95+
if ('connect' in defaultDriver && typeof (defaultDriver as { connect: () => Promise<void> }).connect === 'function') {
96+
await (defaultDriver as { connect: () => Promise<void> }).connect();
97+
}
98+
},
7099
},
71100
// App plugins: register app metadata as `app.*` services.
72101
// Must be before ObjectQLPlugin so services are available during start().

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)