drizzle-schema-checker
v1.2.0
Published
Checks if a Drizzle schema is also valid in a database
Downloads
45
Maintainers
Readme
drizzle-schema-checker
Checks if a Drizzle schema is also valid in a database.
uses unjs/db0 to connect your database.
Installation
npm install drizzle-schema-checker
# or
pnpm add drizzle-schema-checker
Usage
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);
}
Roadmap
- [x] Remove any slip code
- [x] tableNames
- [x] SQLite support
- [x] Bun SQlite support
- [x] LibSQL support
- [ ] PostgreSQL support
- [ ] Cloudflare D1 support
- [ ] MySQL support
Development
Prerequisites
- pnpm
- Bun (for testing)
Setup
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
Testing
To run tests using Vitest:
pnpm test
To run tests with coverage:
pnpm test:ci
Linting and Formatting
- Lint:
pnpm lint
- Format:
pnpm format
License
MIT