Checks if a Drizzle schema is also valid in a database.
uses unjs/db0 to connect your database.
npm install drizzle-schema-checker
# or
pnpm add drizzle-schema-checker
First, create your schemas using Zod:
// schema.ts
import { sqliteTable, text, integer, primaryKey } from "drizzle-orm/sqlite-core";
import { sql } from "drizzle-orm";
export const userTable = sqliteTable("users", {
id: text("id").primaryKey().notNull(),
password: text("password"),
email: text("email").notNull().unique(),
created_at: integer("created_at", { mode: "timestamp" }).notNull().default(sql`CURRENT_TIMESTAMP`),
updated_at: integer("updated_at", { mode: "timestamp" }).notNull().default(sql`CURRENT_TIMESTAMP`),
});
Then, use the checkDatabaseValidity
function to validate your database:
// your db stuff
import { createChecker } from 'drizzle-schema-checker';
import sqlite from "db0/connectors/better-sqlite3";
import { createDatabase } from "db0";
import { userTable } from './schema';
const db = createDatabase(sqlite());
const dbChecker = createChecker(db, "sqlite");
try {
const validatedTable = await checker.checkTable("user", userTable);
console.log('table user is valid in db');
} catch (error) {
console.error(error.message);
}
- Remove any slip code
- tableNames
- SQLite support
- Bun SQlite support
- LibSQL support
- PostgreSQL support
- Cloudflare D1 support
- MySQL support
- pnpm
- Bun (for testing)
-
Clone the repository:
git clone https://github.com/adrienZ/drizzle-schema-checker.git cd drizzle-schema-checker
-
Install dependencies:
pnpm install
-
Build the project:
pnpm build
To run tests using Vitest:
pnpm test
To run tests with coverage:
pnpm test:ci
- Lint:
pnpm lint
- Format:
pnpm format
MIT