{"id":46858,"library":"zod-sqlite","title":"zod-sqlite","description":"Generate type-safe SQLite table schemas from Zod validation schemas, v1.0.2. Requires Node >=24.4.0 and Zod v4 as a peer dependency. Provides a single createTable() function that produces SQL CREATE TABLE and INDEX statements plus a Zod object schema for runtime validation and TypeScript inference. Key differentiators: single source of truth for both database schema and validation, automatic CHECK constraints from Zod rules (min/max, enums, literals), foreign key support, and index management. Released as a new tool bridging Zod and SQLite, with active development.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/favorodera/zod-sqlite","tags":["javascript","zod","sqlite","database","schema","validation","zod-to-sqlite","typescript"],"install":[{"cmd":"npm install zod-sqlite","lang":"bash","label":"npm"},{"cmd":"yarn add zod-sqlite","lang":"bash","label":"yarn"},{"cmd":"pnpm add zod-sqlite","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for defining schemas; must be v4","package":"zod","optional":false}],"imports":[{"note":"ESM-only package; no CommonJS support.","wrong":"const createTable = require('zod-sqlite')","symbol":"createTable","correct":"import { createTable } from 'zod-sqlite'"},{"note":"Common mistake is importing the entire module; z is a named export.","wrong":"import * as z from 'zod'","symbol":"z (from zod)","correct":"import { z } from 'zod'"},{"note":"No standalone type export; infer from return value.","wrong":"import { CreateTableResult } from 'zod-sqlite'","symbol":"createTable result type","correct":"import { createTable } from 'zod-sqlite'; const result = createTable({...}); type Schema = typeof result.schema"}],"quickstart":{"code":"import { createTable } from 'zod-sqlite';\nimport { z } from 'zod';\n\nconst users = createTable({\n  name: 'users',\n  columns: [\n    { name: 'id', schema: z.int() },\n    { name: 'email', schema: z.string().email() },\n    { name: 'username', schema: z.string().min(3).max(20) },\n    { name: 'created_at', schema: z.date().default(() => new Date()) }\n  ],\n  primaryKeys: ['id'],\n  indexes: [\n    { name: 'idx_users_email', columns: ['email'], unique: true }\n  ]\n});\n\nconsole.log(users.table);\n// CREATE TABLE users (id INTEGER NOT NULL, email TEXT NOT NULL, username TEXT NOT NULL CHECK(length(username) >= 3 AND length(username) <= 20), created_at DATE NOT NULL DEFAULT '...', PRIMARY KEY (id));\n\nconst validData = users.schema.parse({\n  id: 1,\n  email: 'test@example.com',\n  username: 'john',\n  created_at: new Date()\n});\n\ntype User = z.infer<typeof users.schema>;\n// { id: number; email: string; username: string; created_at: Date }","lang":"typescript","description":"Demonstrates creating a users table with primary key, unique index, and automatic CHECK constraints from Zod validators."},"warnings":[{"fix":"Upgrade Node to >=24.4.0 or use an older major version of the package.","message":"Requires Node >=24.4.0. Older versions will fail to import.","severity":"breaking","affected_versions":"<24.4.0"},{"fix":"Install zod@^4.0.0 alongside this package.","message":"Requires Zod v4 as a peer dependency. Zod v3 schemas are incompatible.","severity":"breaking","affected_versions":"all"},{"fix":"Wrap default values in arrow functions: z.date().default(() => new Date())","message":"Using z.default() without a function argument is deprecated in Zod v4. Use z.default(() => value) instead.","severity":"deprecated","affected_versions":">=1.0"},{"fix":"Use .safeParse() for error handling. No special treatment needed.","message":"The result.schema is a ZodObject, not a ZodEffects. Validation errors will be detailed per field.","severity":"gotcha","affected_versions":"all"},{"fix":"Use snake_case or camelCase without spaces. Sanitize names before passing.","message":"Column names must be valid SQL identifiers; spaces or special characters may cause SQL errors.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'24.4.0':18 'activ':87 'automat':62 'bridg':82 'check':63 'constraint':64 'creat':34 'createt':29 'databas':58,92 'depend':25 'develop':88 'differenti':51 'enum':69 'foreign':71 'function':30 'generat':4 'index':37,75 'infer':49 'javascript':89 'key':50,72 'liter':70 'manag':76 'min/max':68 'new':80 'node':17 'object':42 'peer':24 'plus':39 'produc':32 'provid':26 'releas':77 'requir':16 'rule':67 'runtim':45 'safe':7 'schema':10,14,43,59,93 'singl':28,52 'sourc':53 'sql':33 'sqlite':3,8,85,91,98 'statement':38 'support':73 'tabl':9,35 'tool':81 'truth':55 'type':6 'type-saf':5 'typescript':48,99 'v1.0.2':15 'v4':21 'valid':13,46,61,94 'zod':2,12,20,41,66,83,90,96 'zod-sqlit':1 'zod-to-sqlit':95","created_at":"2026-06-07T13:01:58.413480+00:00","updated_at":"2026-06-07T13:01:58.413480+00:00","problems":[{"fix":"Change to import { createTable } from 'zod-sqlite' or use dynamic import().","cause":"Using require() to import an ESM-only package.","error":"ERR_REQUIRE_ESM"},{"fix":"Run: npm install zod@^4.0.0","cause":"Zod v4 not installed as a peer dependency.","error":"Cannot find module 'zod'"},{"fix":"Use .default(() => new Date()) in Zod v4.","cause":"Using .default() without parentheses or with invalid argument.","error":"TypeError: z.date(...).default is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/favorodera/zod-sqlite#readme","github":"https://github.com/favorodera/zod-sqlite","docs":null,"changelog":null,"pypi":null,"npm":"zod-sqlite","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}