Package Exports
- @dataql/drizzle-adapter
- @dataql/drizzle-adapter/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@dataql/drizzle-adapter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@dataql/drizzle-adapter
Migrate from Drizzle ORM to DataQL with zero API changes. This adapter provides a Drizzle-compatible API that uses DataQL under the hood.
Installation
npm install @dataql/core @dataql/drizzle-adapterQuick Start
import { drizzle } from "@dataql/drizzle-adapter";
import { pgTable, serial, varchar, integer } from "@dataql/drizzle-adapter";
// Define your schema exactly like Drizzle
const users = pgTable("users", {
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }),
email: varchar("email", { length: 256 }),
age: integer("age"),
});
const posts = pgTable("posts", {
id: serial("id").primaryKey(),
title: varchar("title", { length: 256 }),
content: varchar("content", { length: 1000 }),
authorId: integer("author_id").references(() => users.id),
});
// Initialize DataQL with Drizzle-like API
const db = drizzle({
appToken: "your-app-token",
});
// Register your tables
db.registerTable(users);
db.registerTable(posts);
// Use familiar Drizzle syntax
const allUsers = await db.select().from(users).execute();
const user = await db.insert(users).values({
name: "John Doe",
email: "john@example.com",
age: 30,
});
const userPosts = await db
.select()
.from(posts)
.leftJoin(users, eq(posts.authorId, users.id))
.where(eq(users.id, 1))
.execute();API Compatibility
Supported Drizzle Features
Table Definition
- ✅
pgTable(),mysqlTable(),sqliteTable() - ✅ Column types:
serial,varchar,text,integer,decimal,boolean,timestamp,date,json,jsonb - ✅ Column modifiers:
.primaryKey(),.notNull(),.unique(),.default() - ✅ Foreign key references:
.references()
Query Builder
- ✅
select()- Select data - ✅
insert()- Insert new records - ✅
update()- Update existing records - ✅
delete()- Delete records - ✅
.from()- Specify table - ✅
.where()- Filter conditions - ✅
.leftJoin(),.innerJoin()- Table joins - ✅
.limit(),.offset()- Pagination - ✅
.orderBy()- Sorting
Operators
- ✅
eq,ne,gt,gte,lt,lte - ✅
like,ilike - ✅
isNull,isNotNull - ✅
inArray,notInArray
Advanced Features
- ✅ Transactions
- ✅ TypeScript type inference
- ✅ Schema validation
DataQL Enhancements
While maintaining Drizzle compatibility, you also get DataQL's additional features:
- Offline-first: Automatic offline support and sync
- Real-time: Built-in real-time updates
- Multi-region: Global data distribution
- Schema evolution: Dynamic schema updates
- WAL support: Write-ahead logging for reliability
Migration Guide
From Drizzle ORM
Replace imports:
// Before import { drizzle } from "drizzle-orm/postgres-js"; import { pgTable, serial, varchar } from "drizzle-orm/pg-core"; // After import { drizzle, pgTable, serial, varchar } from "@dataql/drizzle-adapter";
Update database connection:
// Before const db = drizzle(postgres(connectionString)); // After const db = drizzle({ appToken: "your-app-token", });
Register tables (new requirement):
// Register your tables with DataQL db.registerTable(users); db.registerTable(posts);
Your queries work the same:
// This works exactly the same const users = await db.select().from(usersTable).execute();
Configuration
const db = drizzle({
appToken: "your-app-token", // Authentication token
env: "prod", // 'dev' or 'prod'
devPrefix: "dev_", // Prefix for dev tables
});TypeScript Support
Full TypeScript support with inferred types:
import { InferSelectModel, InferInsertModel } from "@dataql/drizzle-adapter";
type User = InferSelectModel<typeof users>;
type NewUser = InferInsertModel<typeof users>;
const user: User = await db
.select()
.from(users)
.where(eq(users.id, 1))
.execute();
const newUser: NewUser = { name: "Jane", email: "jane@example.com" };Limitations
Some advanced Drizzle features are not yet supported:
- Custom schema names
- Advanced SQL functions
- Raw SQL queries
- Prepared statements
- Complex subqueries
If you need these features, please open an issue.
License
MIT