Integrate with ORM tools
When seekdb-js is integrated with ORM-style tools such as Drizzle and Prisma, you can use Drizzle and Prisma to work with seekdb and run vector search, full-text search, or hybrid search.
seekdb-js supports two modes. The connection patterns are:
-
Server mode: Use one database with two connections (SeekdbClient + ORM).
-
Embedded mode: Drizzle uses
drizzle-orm/mysql-proxyand wrapsclient.execute()in a callback; Prisma uses@seekdb/prisma-adapter.
Drizzle
Prerequisites
- Server mode: seekdb or OceanBase Database is deployed.
- Embedded: Node 20+ (loads native addons on first use).
Run
-
Server mode
pnpm install
pnpm start
# From repo root: pnpm --filter seekdb-drizzle-example run startOptional environment variables:
SEEKDB_HOST: seekdb server host, for example127.0.0.1.SEEKDB_PORT: seekdb server port, for example2881.SEEKDB_USER: seekdb username, for exampleroot.SEEKDB_PASSWORD: seekdb password.SEEKDB_DATABASE: seekdb database name, for exampletest.
-
Embedded
pnpm install
pnpm start:embedded
# From repo root: pnpm --filter seekdb-drizzle-example run start:embedded
Examples
-
Set up connections.
-
Server mode: Connect with SeekDBClient to host and port; create a separate
mysql2connection (same configuration) and pass it todrizzle(conn). -
Embedded mode: Use SeekDBClient with a path; obtain the proxy runner and pass it to
drizzle(run)(usingmysql-proxy).
-
-
Create a collection and insert documents; create a
userstable and insert rows (IDs aligned). -
Run hybrid search, then use Drizzle
inArray()to load users by IDs from the result. -
Print a combined-style result.
-
Server mode
import { createConnection } from "mysql2/promise";
import { SeekdbClient } from "seekdb";
import { drizzle } from "drizzle-orm/mysql2";
import { inArray } from "drizzle-orm";
import { users } from "./schema.js";
import { DEMO_IDS, DEMO_DOCS, DEMO_USERS } from "./shared.js";
const COLLECTION_NAME = "seekdb_drizzle_docs";
async function main() {
const dbConfig = {
host: process.env.SEEKDB_HOST ?? "127.0.0.1",
port: parseInt(process.env.SEEKDB_PORT ?? "2881", 10),
user: process.env.SEEKDB_USER ?? "root",
password: process.env.SEEKDB_PASSWORD ?? "",
database: process.env.SEEKDB_DATABASE ?? "test",
};
const client = new SeekdbClient(dbConfig);
const conn = await createConnection(dbConfig);
const db = drizzle(conn);
await client.execute(`
CREATE TABLE IF NOT EXISTS users (
id VARCHAR(64) PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255)
)
`);
const collection = await client.getOrCreateCollection({
name: COLLECTION_NAME,
});
await collection.add({ ids: [...DEMO_IDS], documents: [...DEMO_DOCS] });
try {
await db.insert(users).values([...DEMO_USERS]);
} catch {
// ignore if already inserted (e.g. re-run)
}
// Hybrid search → get ids
const result = await collection.hybridSearch({
query: { whereDocument: { $contains: "vector" } },
knn: { queryTexts: ["database search"] },
nResults: 5,
});
const resultIds = (result.ids?.flat().filter(Boolean) ?? []) as string[];
// Type-safe relational query by ids
const usersList =
resultIds.length > 0
? await db.select().from(users).where(inArray(users.id, resultIds))
: [];
console.log("Vector/hybrid search result ids:", resultIds);
console.log("Relational users for those ids:", usersList);
await conn.end();
await client.close();
}
main().catch((err) => {
console.error(err);
process.exit(1);
}); -
Embedded mode
import { SeekdbClient } from "seekdb";
import { drizzle } from "drizzle-orm/mysql-proxy";
import { inArray } from "drizzle-orm";
import { users } from "./schema.js";
import { DEMO_IDS, DEMO_DOCS_EMBEDDED, DEMO_USERS } from "./shared.js";
/** Drizzle mysql-proxy runner from a SeekdbClient (Embedded or Server). */
function getDrizzleProxyRunner(client: SeekdbClient) {
return async (
sql: string,
params: unknown[],
method: string
): Promise<{ rows: unknown[] | unknown[][] }> => {
const result = await client.execute(sql, params);
if (result === null) return { rows: method === "get" ? [] : [] };
const rows = result.map((row) => Object.values(row));
return { rows: method === "get" ? (rows[0] ?? []) : rows };
};
}
const COLLECTION_NAME = "seekdb_drizzle_embed_docs";
const DB_PATH = "./seekdb.db";
async function main() {
const client = new SeekdbClient({ path: DB_PATH, database: "test" });
const db = drizzle(getDrizzleProxyRunner(client));
await client.execute(`
CREATE TABLE IF NOT EXISTS users (
id VARCHAR(64) PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255)
)
`);
const collection = await client.getOrCreateCollection({
name: COLLECTION_NAME,
});
await collection.add({
ids: [...DEMO_IDS],
documents: [...DEMO_DOCS_EMBEDDED],
});
try {
await db.insert(users).values([...DEMO_USERS]);
} catch {
// ignore if already inserted
}
const result = await collection.hybridSearch({
query: { whereDocument: { $contains: "vector" } },
knn: { queryTexts: ["database"] },
nResults: 5,
});
const resultIds = (result.ids?.flat().filter(Boolean) ?? []) as string[];
const usersList =
resultIds.length > 0
? await db.select().from(users).where(inArray(users.id, resultIds))
: [];
console.log("Embedded: vector result ids:", resultIds);
console.log("Embedded: users for those ids:", usersList);
await client.close();
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
Prisma
Prerequisites
- Server mode: seekdb or OceanBase Database is deployed.
- Embedded: Node 20+ (loads native addons on first use).
Configuration
-
Server mode
-
Copy
.env.exampleto.envand setDATABASE_URLsohost,port,user,password, anddatabasematchSeekdbClient, for example:mysql://root:@127.0.0.1:2881/test. -
Generate the Prisma client and push the schema.
pnpm install
pnpm db:generate
pnpm db:push # Server only -
Run (from this directory, or from the repo root with the filter).
pnpm start
# From repo root: pnpm --filter seekdb-prisma-example run start
-
-
Embedded
Start with pnpm directly.
pnpm run start:embedded
# From repo root: pnpm --filter seekdb-prisma-example run start:embedded
Examples
- Use
SeekDBClientandPrismaClientagainst the same database. - Create a collection and insert documents; insert or upsert user rows (IDs aligned).
- Run hybrid search, then load users with
prisma.user.findMany({ where: { id: { in: ids } } })using result IDs. - Print a combined-style result.
-
Server mode
import { SeekdbClient } from "seekdb";
import { PrismaClient } from "@prisma/client";
import { DEMO_IDS, DEMO_DOCS, DEMO_USERS } from "./shared.js";
const COLLECTION_NAME = "seekdb_prisma_docs";
async function main() {
const client = new SeekdbClient({
host: process.env.SEEKDB_HOST ?? "127.0.0.1",
port: parseInt(process.env.SEEKDB_PORT ?? "2881", 10),
user: process.env.SEEKDB_USER ?? "root",
password: process.env.SEEKDB_PASSWORD ?? "",
database: process.env.SEEKDB_DATABASE ?? "test",
});
const prisma = new PrismaClient();
const collection = await client.getOrCreateCollection({
name: COLLECTION_NAME,
});
await collection.add({ ids: [...DEMO_IDS], documents: [...DEMO_DOCS] });
for (const user of DEMO_USERS) {
await prisma.user.upsert({
where: { id: user.id },
create: user,
update: {},
});
}
const result = await collection.hybridSearch({
query: { whereDocument: { $contains: "vector" } },
knn: { queryTexts: ["database search"] },
nResults: 5,
});
const resultIds = (result.ids?.flat().filter(Boolean) ?? []) as string[];
// Relational query by ids (type-safe)
const users =
resultIds.length > 0
? await prisma.user.findMany({ where: { id: { in: resultIds } } })
: [];
console.log("Vector/hybrid search result ids:", resultIds);
console.log("Relational users for those ids:", users);
await client.close();
await prisma.$disconnect();
}
main().catch((err) => {
console.error(err);
process.exit(1);
}); -
Embedded mode
import { SeekdbClient } from "seekdb";
import { PrismaSeekdb } from "@seekdb/prisma-adapter";
import { PrismaClient } from "@prisma/client";
import { DEMO_IDS, DEMO_DOCS_EMBEDDED, DEMO_USERS } from "./shared.js";
const COLLECTION_NAME = "seekdb_prisma_embed_docs";
const DB_PATH = "./seekdb.db";
async function main() {
const client = new SeekdbClient({ path: DB_PATH, database: "test" });
const adapter = new PrismaSeekdb(client);
const prisma = new PrismaClient({ adapter });
await client.execute(`
CREATE TABLE IF NOT EXISTS User (
id VARCHAR(191) NOT NULL,
name VARCHAR(191) NOT NULL,
email VARCHAR(191) NULL,
PRIMARY KEY (id)
)
`);
const collection = await client.getOrCreateCollection({
name: COLLECTION_NAME,
});
await collection.add({
ids: [...DEMO_IDS],
documents: [...DEMO_DOCS_EMBEDDED],
});
for (const user of DEMO_USERS) {
await prisma.user.upsert({
where: { id: user.id },
create: user,
update: {},
});
}
const result = await collection.hybridSearch({
query: { whereDocument: { $contains: "vector" } },
knn: { queryTexts: ["database"] },
nResults: 5,
});
const resultIds = (result.ids?.flat().filter(Boolean) ?? []) as string[];
const users =
resultIds.length > 0
? await prisma.user.findMany({ where: { id: { in: resultIds } } })
: [];
console.log("Embedded: vector result ids:", resultIds);
console.log("Embedded: users for those ids:", users);
await prisma.$disconnect();
await client.close();
}
main().catch((err) => {
console.error(err);
process.exit(1);
});