drizzle-orm/src/knex/README.md
This is a toolchain for integrating Drizzle with Knex.js.
You can define you DB schema using Drizzle and use Knex as the query builder. With this approach you benefit from schema definition and automated migrations provided by Drizzle, and you can use Knex to build your queries. This might be helpful if you have an existing Knex.js project and you want to add Drizzle features to it.
This integration is based on official Knex TypeScript guide.
import Knex from 'knex';
import { pgTable, serial, text } from 'drizzle-orm/pg-core';
// This line is important - it allows you to use the Knexify type
import 'drizzle-orm/knex';
const test = pgTable('test', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
});
declare module 'knex/types/tables' {
interface Tables {
test: Knexify<typeof test>;
}
}
const db = Knex({});
const result/*: { id: number, name: string }[] */ = db('test').select();
Coming soon!