Skip to content

feat: wire Turso/libSQL driver into pnpm dev via TURSO_DATABASE_URL#425

Merged
hotlong merged 3 commits intomainfrom
copilot/add-turso-driver-support
Mar 20, 2026
Merged

feat: wire Turso/libSQL driver into pnpm dev via TURSO_DATABASE_URL#425
hotlong merged 3 commits intomainfrom
copilot/add-turso-driver-support

Conversation

Copy link
Contributor

Copilot AI commented Mar 20, 2026

  • Create .env.example at project root with Turso environment variables
  • Update objectstack.config.ts to conditionally use TursoDriver when TURSO_DATABASE_URL is set, falling back to MemoryDriver
  • Add @objectql/driver-turso as devDependency in root package.json
  • Update ROADMAP.md to reflect this improvement
  • Merge main branch and resolve conflicts (objectstack.config.ts, ROADMAP.md)
Original prompt

Problem

Currently, pnpm dev (which runs objectstack serve --dev) uses objectstack.config.ts that hardcodes MemoryDriver as the default driver. There is no way to switch to the Turso/libSQL driver for local development without manually editing the config file. The @objectql/driver-turso package (v4.2.2) is already implemented with full support for 3 connection modes (Remote Cloud, Local Embedded, Embedded Replica), but it's not wired into the dev workflow.

Goal

Enable developers to use the Turso driver during local development via pnpm dev by:

  1. Creating a .env.example file at the project root documenting all Turso-related environment variables.
  2. Updating objectstack.config.ts to conditionally use the Turso driver when TURSO_DATABASE_URL is set in the environment, falling back to MemoryDriver when not set (preserving backward compatibility).
  3. Adding @objectql/driver-turso as a devDependency in the root package.json.
  4. Updating ROADMAP.md to reflect this improvement.

Implementation Details

1. Create .env.example

Create a .env.example file at the project root with:

# ─── Auth ──────────────────────────────────────────────────────────────────
AUTH_SECRET=objectql-dev-secret-change-me-in-production

# ─── Turso / libSQL Driver ────────────────────────────────────────────────
# Uncomment and set these to use Turso driver instead of MemoryDriver.
#
# Connection modes:
#   Remote (Cloud):          TURSO_DATABASE_URL=libsql://my-db-orgname.turso.io
#   Local (Embedded file):   TURSO_DATABASE_URL=file:./data/local.db
#   In-memory:               TURSO_DATABASE_URL=:memory:
#
# TURSO_DATABASE_URL=file:./data/local.db
# TURSO_AUTH_TOKEN=
#
# Embedded Replica (Hybrid) — sync a local file with a remote primary:
# TURSO_SYNC_URL=libsql://my-db-orgname.turso.io
# TURSO_SYNC_INTERVAL=60

2. Update objectstack.config.ts

The config should:

  • Import TursoDriver and TursoDriverPlugin from @objectql/driver-turso
  • Check process.env.TURSO_DATABASE_URL at startup
  • If the env var is set, instantiate a TursoDriver with the appropriate config (including optional authToken, syncUrl, sync.intervalSeconds)
  • Register it as 'driver.default' and pass it to QueryPlugin
  • If the env var is NOT set, fall back to the existing MemoryDriver behavior (zero-config for quick starts)
  • Log which driver mode is active at startup (e.g., console.log('🗄️ Driver: Turso (file:./data/local.db)') or console.log('🗄️ Driver: Memory (in-memory, non-persistent)'))

Here's the key pattern for the driver selection in objectstack.config.ts:

import { MemoryDriver } from '@objectql/driver-memory';
import { createTursoDriver } from '@objectql/driver-turso';
import { TursoDriverPlugin } from '@objectql/driver-turso';

// Choose driver based on environment
function createDefaultDriver() {
    const tursoUrl = process.env.TURSO_DATABASE_URL;
    if (tursoUrl) {
        console.log(`🗄️  Driver: Turso (${tursoUrl})`);
        return createTursoDriver({
            url: tursoUrl,
            authToken: process.env.TURSO_AUTH_TOKEN,
            syncUrl: process.env.TURSO_SYNC_URL,
            sync: process.env.TURSO_SYNC_URL
                ? {
                    intervalSeconds: Number(process.env.TURSO_SYNC_INTERVAL) || 60,
                    onConnect: true,
                }
                : undefined,
        });
    }
    console.log('🗄️  Driver: Memory (in-memory, non-persistent)');
    return new MemoryDriver();
}

const defaultDriver = createDefaultDriver();

The plugin array in the config should also register the driver properly as a service:

{
    name: 'driver-default',
    init: async (ctx: any) => {
        ctx.registerService('driver.default', defaultDriver);
    },
    start: async () => {
        // Connect Turso driver if applicable
        if ('connect' in defaultDriver && typeof defaultDriver.connect === 'function') {
            await defaultDriver.connect();
        }
    },
},

3. Update root package.json

Add @objectql/driver-turso to devDependencies:

"@objectql/driver-turso": "workspace:*",

4. Update ROADMAP.md

Add a line under the existing achievements section:

- ✅ `pnpm dev` supports Turso/libSQL driver via `TURSO_DATABASE_URL` env var (local embedded, remote cloud, or embedded replica modes)

Key Files to Modify

  • NEW: .env.example (project root)
  • MODIFY: objectstack.config.ts (project root)
  • MODIFY: package.json (project root — add devDependency)
  • MODIFY: ROADMAP.md (project root — update achievements)

Constraints

  • Backward compatible: If no TURSO_DATABASE_URL is set, the system must behave exactly as before (MemoryDriver).
  • No temporary hacks: Use the proper TursoDriver / createTursoDriver factory from @objectql/driver-turso.
  • The driver registration pattern (`ctx.registerService('driver...

This pull request was created from Copilot chat.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@vercel
Copy link

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectql Ready Ready Preview, Comment Mar 20, 2026 9:19am

Request Review

…env var

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Enable Turso driver support for local development feat: wire Turso/libSQL driver into pnpm dev via TURSO_DATABASE_URL Mar 20, 2026
Copilot AI requested a review from hotlong March 20, 2026 09:01
@hotlong hotlong marked this pull request as ready for review March 20, 2026 09:15
Copilot AI review requested due to automatic review settings March 20, 2026 09:15
@hotlong
Copy link
Contributor

hotlong commented Mar 20, 2026

@copilot 合并主分支代码并解决冲突

…ver-support

# Conflicts:
#	ROADMAP.md
#	objectstack.config.ts
Copy link
Contributor Author

Copilot AI commented Mar 20, 2026

@copilot 合并主分支代码并解决冲突

Done — merged origin/main (commit 593a37a) into this branch and resolved conflicts in objectstack.config.ts and ROADMAP.md. Merge commit: df8031e.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Wires the Turso/libSQL driver into the local pnpm dev workflow by selecting the default driver at startup via environment variables, while preserving the existing in-memory default.

Changes:

  • Add env-driven createDefaultDriver() selection (Turso when TURSO_DATABASE_URL is set; otherwise MemoryDriver) and register as driver.default.
  • Add root .env.example documenting Turso and auth environment variables for local development.
  • Add @objectql/driver-turso to root devDependencies and record the improvement in ROADMAP.md.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
objectstack.config.ts Adds driver-selection factory, registers driver.default, and attempts to connect the chosen driver on startup.
.env.example Documents AUTH_SECRET and Turso env vars / connection modes for dev setup.
package.json Adds @objectql/driver-turso as a workspace devDependency.
pnpm-lock.yaml Locks the new workspace link for @objectql/driver-turso.
ROADMAP.md Notes pnpm dev Turso support as an achievement.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (2)

objectstack.config.ts:77

  • TURSO_SYNC_INTERVAL parsing uses Number(...) || 60, which makes it impossible to configure 0 (manual-only sync) even though the Turso driver supports intervalSeconds: 0. Consider parsing the env var so that 0 is preserved, and only falling back to 60 when the value is missing or NaN.
});

export default {
    metadata: {
        name: 'objectos',

objectstack.config.ts:111

  • The comment says MemoryDriver has no connect method, but MemoryDriver does implement connect() (as a no-op) for DriverInterface compatibility. Since both TursoDriver and MemoryDriver have connect(), you can simplify this block by calling await defaultDriver.connect() directly (or update the comment/typing accordingly) to avoid redundant runtime checks and casts.
        new QueryPlugin({ datasources: { default: defaultDriver } }),
        new ValidatorPlugin(),
        new FormulaPlugin(),
        new ObjectQLSecurityPlugin({

@hotlong hotlong merged commit 72c1aea into main Mar 20, 2026
3 checks passed
@hotlong hotlong deleted the copilot/add-turso-driver-support branch March 20, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants