{"id":45247,"library":"kysely-codegen-sqlite","title":"kysely-codegen-sqlite","description":"kysely-codegen-sqlite v0.2.0 generates Kysely type definitions (.d.ts files) directly from SQLite databases. It supports CLI and configuration file usage, camelCase conversion, custom type imports, and requires Node >=20. Unlike generic codegen tools, it is purpose-built for SQLite and integrates tightly with Kysely and better-sqlite3. The library is ESM-only and ships TypeScript types.","status":"active","version":"0.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/trancong12102/kysely-codegen-sqlite","tags":["javascript","typescript"],"install":[{"cmd":"npm install kysely-codegen-sqlite","lang":"bash","label":"npm"},{"cmd":"yarn add kysely-codegen-sqlite","lang":"bash","label":"yarn"},{"cmd":"pnpm add kysely-codegen-sqlite","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; required to use generated types with Kysely ORM","package":"kysely","optional":false},{"reason":"Peer dependency; used to connect to SQLite database during codegen","package":"better-sqlite3","optional":false}],"imports":[{"note":"DB is a named export, not default. The lib is ESM-only.","wrong":"import DB from 'kysely-codegen-sqlite'","symbol":"DB","correct":"import { DB } from 'kysely-codegen-sqlite'"},{"note":"Generated is re-exported from generated .d.ts file; you can also import it from 'kysely' directly.","wrong":"","symbol":"Generated","correct":"import { Generated } from 'kysely-codegen-sqlite'"},{"note":"Table interfaces like Company are generated in the output file, not from the package itself.","wrong":"import { Company } from 'kysely-codegen-sqlite'","symbol":"Company","correct":"import { Company } from './path/to/generated-file'"}],"quickstart":{"code":"// 1. Install dependencies\n// npm install --save-dev kysely-codegen-sqlite\n// npm install kysely better-sqlite3\n\n// 2. Create .env with DATABASE_URL=./path/to/database.db\n\n// 3. Run CLI (or add to package.json scripts)\n// npx kysely-codegen-sqlite --out-file ./src/db/db.d.ts\n\n// 4. Use generated types\nimport { Kysely } from 'kysely';\nimport BetterSqlite3 from 'better-sqlite3';\nimport { BetterSqlite3Dialect } from 'kysely';\nimport { DB } from './src/db/db.d.ts'; // path to generated file\n\nconst db = new Kysely<DB>({\n  dialect: new BetterSqlite3Dialect({\n    database: new BetterSqlite3('./database.db'),\n  }),\n});\n\nconst rows = await db.selectFrom('users').selectAll().execute();\n// rows is typed as { id: number; name: string; ... }[]","lang":"typescript","description":"Shows end-to-end setup: install deps, configure env, run codegen CLI, and use generated DB type with Kysely."},"warnings":[{"fix":"Upgrade Node.js to >=20.0.0 if using this version.","message":"Node.js <20 is not supported, but this constraint may change in future versions.","severity":"deprecated","affected_versions":"0.2.0"},{"fix":"Do not edit the generated .d.ts file; custom types should be declared separately.","message":"Generated file is overwritten each run; manual changes will be lost.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Import DB from the generated output file (e.g., ./db.d.ts) rather than the package name.","message":"The DB type export is from the generated file, not from 'kysely-codegen-sqlite' package.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use CLI argument --camel-case or enable in config file to match Kysely's CamelCasePlugin.","message":"CamelCase plugin usage requires --camel-case flag; otherwise column names stay snake_case.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'20':35 'better':54 'better-sqlite3':53 'built':44 'camelcas':27 'cli':22 'codegen':3,7,38 'configur':24 'convers':28 'custom':29 'd.ts':14 'databas':19 'definit':13 'direct':16 'esm':60 'esm-on':59 'file':15,25 'generat':10 'generic':37 'import':31 'integr':48 'javascript':66 'kyse':2,6,11,51 'kysely-codegen-sqlit':1,5 'librari':57 'node':34 'purpos':43 'purpose-built':42 'requir':33 'ship':63 'sqlite':4,8,18,46 'sqlite3':55 'support':21 'tight':49 'tool':39 'type':12,30,65 'typescript':64,67 'unlik':36 'usag':26 'v0.2.0':9","created_at":"2026-06-07T12:54:05.412191+00:00","updated_at":"2026-06-07T12:54:05.412191+00:00","problems":[{"fix":"Do not import from 'kysely-codegen-sqlite' in your runtime code. Instead, import the generated .d.ts file.","cause":"The package is a CLI tool; its types are not used directly in code.","error":"Cannot find module 'kysely-codegen-sqlite' or its corresponding type declarations."},{"fix":"Use npx kysely-codegen-sqlite instead of the bare command, or install locally with npm install --save-dev.","cause":"Package not installed globally or node_modules/.bin not in PATH.","error":"kysely-codegen-sqlite: command not found"},{"fix":"Ensure your database file is accessible and tables exist. Check DATABASE_URL in .env or provide --db-url explicitly.","cause":"Generated DB type may be empty if no tables exist or codegen failed.","error":"Type 'DB' does not satisfy the constraint 'Record<string, KyselyTableDefinition>'."}],"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/trancong12102/kysely-codegen-sqlite#readme","github":"https://github.com/trancong12102/kysely-codegen-sqlite","docs":null,"changelog":null,"pypi":null,"npm":"kysely-codegen-sqlite","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","devops"],"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}}