Skip to content

feat: Integrate libseekdb to support embedded mode#7

Merged
raindrop93 merged 38 commits intomainfrom
feat/embed-mode
Feb 26, 2026
Merged

feat: Integrate libseekdb to support embedded mode#7
raindrop93 merged 38 commits intomainfrom
feat/embed-mode

Conversation

@dengfuping
Copy link
Contributor

@dengfuping dengfuping commented Jan 30, 2026

Summary

  • Add embedded mode so the SDK can run against a local seekdb instance via the native addon (@seekdb/js-bindings) instead of a remote MySQL server. Same public API: path → embedded, host → server.
  • Dependencies: seekdb C ABI #135

Solution Description

  • Embedded Mode Implementation Architecture
                    Client(args) / AdminClient(args)
                                    │
                    ┌───────────────┴───────────────┐
                    │ path?          │ host?       │
                    ▼                ▼             │
         ┌──────────────────┐  ┌──────────────────┐
         │ SeekdbEmbedded    │  │ SeekdbServer     │
         │ Client            │  │ Client           │
         └────────┬──────────┘  └────────┬─────────┘
                  │                      │
                  │     BaseSeekdbClient │
                  │     (collections)    │
                  │                      │
                  ▼                      ▼
         ┌──────────────────┐  ┌──────────────────┐
         │ InternalEmbedded │  │ InternalClient   │
         │ Client           │  │ (MySQL Connection)│
         └────────┬──────────┘  └──────────────────┘
                  │
                  ▼
         ┌──────────────────┐     ┌──────────────────┐
         │ @seekdb/js-      │ ──► │ libseekdb (C ABI)│
         │ bindings (native)│     │ seekdb_open,     │
         │ open→connect→    │     │ seekdb_connect, │
         │ execute          │     │ seekdb_query_*   │
         └──────────────────┘     └──────────────────┘
  • Main changes:

  • Client: SeekdbClient facade picks SeekdbEmbeddedClient or SeekdbServerClient from path vs host. Both extend BaseSeekdbClient and use IInternalClient for execution.

  • Embedded path: New InternalEmbeddedClient implements IInternalClient with bindings: open(path)connect(db, database)execute(conn, sql, params). Converts bindings result to RowDataPacket[] so Collection layer is unchanged.

  • Factory: Client(args) — if path → embedded; if host → server; if neither → default embedded at cwd/seekdb.db (throws if addon missing). Same for AdminClient.

  • Types: SeekdbClientArgs.path? (embedded), SeekdbClientArgs.host? (server).

  • Bindings: C++ already exposes open, connect, execute; no API change. Docs added for C ABI expectations (c-abi-modification-reference.md).

  • Tests: packages/seekdb/tests/embedded/ — client, collection (DML/query/approximate/hybrid), data, edge-cases, embedding, examples. test-utils.ts for isolated DB dirs and cleanup.

Usage

import { SeekdbClient } from "seekdb";

const client = new SeekdbClient({
  path: "./seekdb.db",
  database: "test",
});

const collection = await client.createCollection({ name: "my_collection" });
await collection.add({
  ids: ["1", "2"],
  documents: ["Hello world", "seekdb is fast"],
});
const results = await collection.query({ queryTexts: "Hello", nResults: 5 });

Checklist

  • Embedded and server collection/document behavior equivalent
  • Lazy init and no-op close acceptable; no event-loop block
  • Error handling (addon missing, init twice, C errors) clear
  • Tests cover create/get/DML/query/edge cases; isolated DB dirs

@raindrop93 raindrop93 merged commit 91ac590 into main Feb 26, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants