{"_id":"kysely-knex","_rev":"1-3cf5789a3f56cbd750daf7b526a8a8d9","name":"kysely-knex","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"kysely-knex","version":"0.1.0","description":"Kysely dialect for Knex.js","repository":{"type":"git","url":"git+https://github.com/kysely-org/kysely-knex.git"},"homepage":"https://github.com/kysely-org/kysely-knex","author":{"name":"Igal Klebanov","email":"igalklebanov@gmail.com"},"license":"MIT","main":"./dist/cjs/index.js","module":"./dist/esm/index.js","exports":{".":{"import":"./dist/esm/index.js","require":"./dist/cjs/index.js"}},"keywords":["kysely","knex","postgres","mysql","postgresql","mariadb","sqlite","better-sqlite3","mssql","dialect"],"scripts":{"build":"tsup && node ./scripts/dist-fix.js","clean":"rm -rf dist","fmt":"prettier --write .","fmt:check":"prettier --check .","lint":"eslint src --ext .ts","prepack":"pnpm lint && pnpm build","test":"pnpm build && pnpm test:nodejs","test:nodejs":"mocha ./tests/nodejs","type-check":"tsc --noEmit"},"peerDependencies":{"knex":">= 3.0.0 < 4","kysely":">= 0.24.0 < 1"},"devDependencies":{"@tsconfig/node20":"^20.1.3","@types/chai":"^4.3.14","@types/lodash":"^4.17.0","@types/mocha":"^10.0.6","@types/node":"^20.11.30","@typescript-eslint/eslint-plugin":"^7.3.1","@typescript-eslint/parser":"^7.3.1","better-sqlite3":"^9.4.3","chai":"^4.3.10","esbuild":"^0.20.2","esbuild-runner":"^2.2.2","eslint":"^8.57.0","eslint-config-prettier":"^9.1.0","eslint-plugin-import":"^2.29.1","eslint-plugin-prettier":"^5.1.3","knex":"^3.1.0","kysely":"^0.27.3","lodash":"^4.17.21","mocha":"^10.3.0","mysql":"^2.18.1","mysql2":"^3.9.2","pg":"^8.11.3","pg-query-stream":"^4.5.3","prettier":"^3.2.5","prettier-plugin-organize-imports":"^3.2.4","prettier-plugin-pkg":"^0.18.1","sqlite3":"^5.1.7","tedious":"^18.1.0","tsd":"^0.30.7","tsup":"^8.0.2","typescript":"^5.4.3"},"sideEffects":false,"gitHead":"45bad74ef1763ded4e0410608a40368646693b2d","types":"./dist/cjs/index.d.ts","bugs":{"url":"https://github.com/kysely-org/kysely-knex/issues"},"_id":"kysely-knex@0.1.0","_nodeVersion":"20.4.0","_npmVersion":"9.7.2","dist":{"integrity":"sha512-owNq2o4SkTROQuiiHw3gBmbYols7Shnt9FHdfZ4QBQHpDawyn0giHmnVrBCkSzAaxiwNeU7FZxf7vX6h7q0zdA==","shasum":"ca9d841f7f16a775a9d1d9d4ea806174d3f6eb09","tarball":"https://registry.npmjs.org/kysely-knex/-/kysely-knex-0.1.0.tgz","fileCount":12,"unpackedSize":76177,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDJsTBFMueEnQvBrMmEUpUXcBc5NS7j2lAUq7g9ca0IhQIhANKLUuPe5DZ+K0UjiC8aVJOWUOJcNdW9RcutNENnYn1h"}]},"_npmUser":{"name":"igalklebanov","email":"igalklebanov@gmail.com"},"directories":{},"maintainers":[{"name":"igalklebanov","email":"igalklebanov@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/kysely-knex_0.1.0_1711747216406_0.327865353251122"},"_hasShrinkwrap":false},"0.2.0":{"name":"kysely-knex","version":"0.2.0","description":"Kysely dialect for Knex.js","repository":{"type":"git","url":"git+https://github.com/kysely-org/kysely-knex.git"},"homepage":"https://github.com/kysely-org/kysely-knex","author":{"name":"Igal Klebanov","email":"igalklebanov@gmail.com"},"license":"MIT","main":"./dist/cjs/index.js","module":"./dist/esm/index.js","exports":{".":{"import":"./dist/esm/index.js","require":"./dist/cjs/index.js"}},"keywords":["kysely","knex","postgres","mysql","postgresql","mariadb","sqlite","better-sqlite3","mssql","dialect"],"peerDependencies":{"knex":">= 3.0.0 < 4","kysely":">= 0.24.0 < 1"},"devDependencies":{"@tsconfig/node20":"^20.1.3","@types/chai":"^4.3.14","@types/lodash":"^4.17.0","@types/mocha":"^10.0.6","@types/node":"^20.12.7","@typescript-eslint/eslint-plugin":"^7.6.0","@typescript-eslint/parser":"^7.6.0","better-sqlite3":"^9.5.0","chai":"^4.3.10","esbuild":"^0.20.2","esbuild-runner":"^2.2.2","eslint":"^8.57.0","eslint-config-prettier":"^9.1.0","eslint-plugin-import":"^2.29.1","eslint-plugin-prettier":"^5.1.3","knex":"^3.1.0","kysely":"^0.27.3","lodash":"^4.17.21","mocha":"^10.3.0","mysql":"^2.18.1","mysql2":"^3.9.4","pg":"^8.11.3","pg-query-stream":"^4.5.5","prettier":"^3.2.5","prettier-plugin-organize-imports":"^3.2.4","prettier-plugin-pkg":"^0.18.1","sqlite3":"^5.1.7","tedious":"^18.1.0","ts-node":"^10.9.2","tsd":"^0.31.0","tsup":"^8.0.2","typescript":"^5.4.5"},"sideEffects":false,"scripts":{"build":"tsup && node ./scripts/dist-fix.js","clean":"rm -rf dist","fmt":"prettier --write .","fmt:check":"prettier --check .","lint":"eslint src --ext .ts","test":"pnpm build && pnpm test:nodejs && pnpm test:migrations","test:migrations":"knex --knexfile ./knexfile.ts migrate:latest && knex --knexfile ./knexfile.ts migrate:rollback","test:nodejs":"mocha ./tests/nodejs","type-check":"tsc --noEmit"},"types":"./dist/cjs/index.d.ts","bugs":{"url":"https://github.com/kysely-org/kysely-knex/issues"},"_id":"kysely-knex@0.2.0","_integrity":"sha512-kaZSKXdRf+VM+FOEQqqBF1wq3N76xGozdqjOtYWAqfSgzMqD1bdEMN8Z0l/dAmfayMtB3oNN0vcMz7OADNxECA==","_resolved":"/tmp/119ea04868a3ca3eef99adccc1930daa/kysely-knex-0.2.0.tgz","_from":"file:kysely-knex-0.2.0.tgz","_nodeVersion":"20.4.0","_npmVersion":"9.7.2","dist":{"integrity":"sha512-kaZSKXdRf+VM+FOEQqqBF1wq3N76xGozdqjOtYWAqfSgzMqD1bdEMN8Z0l/dAmfayMtB3oNN0vcMz7OADNxECA==","shasum":"ad40c62832538ee901da3c772839e0136e8ca084","tarball":"https://registry.npmjs.org/kysely-knex/-/kysely-knex-0.2.0.tgz","fileCount":12,"unpackedSize":87197,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAu+SSehmXlDWEcT2HyJFPoyWf9Ft1lgYwrylAXXs8tGAiEA2qPo7m4fX+lIoxXkHcJ5k3JBMqJsW4oR7nyhaKci+ls="}]},"_npmUser":{"name":"igalklebanov","email":"igalklebanov@gmail.com"},"directories":{},"maintainers":[{"name":"igalklebanov","email":"igalklebanov@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/kysely-knex_0.2.0_1713116085473_0.5455071900563022"},"_hasShrinkwrap":false}},"time":{"created":"2024-03-29T21:20:16.405Z","0.1.0":"2024-03-29T21:20:16.639Z","modified":"2024-04-14T17:34:45.832Z","0.2.0":"2024-04-14T17:34:45.648Z"},"maintainers":[{"name":"igalklebanov","email":"igalklebanov@gmail.com"}],"description":"Kysely dialect for Knex.js","homepage":"https://github.com/kysely-org/kysely-knex","keywords":["kysely","knex","postgres","mysql","postgresql","mariadb","sqlite","better-sqlite3","mssql","dialect"],"repository":{"type":"git","url":"git+https://github.com/kysely-org/kysely-knex.git"},"author":{"name":"Igal Klebanov","email":"igalklebanov@gmail.com"},"bugs":{"url":"https://github.com/kysely-org/kysely-knex/issues"},"license":"MIT","readme":"# kysely-knex\n\nKnex.js (pronounced /kəˈnɛks/) is a \"batteries included\" SQL query builder for PostgreSQL, CockroachDB, MSSQL, MySQL, MariaDB, SQLite3, Better-SQLite3, Oracle, and Amazon Redshift designed to be flexible, portable, and fun to use. It features both traditional node style callbacks as well as a promise interface for cleaner async flow control, a stream interface, full-featured query and schema builders, transaction support (with savepoints), connection pooling and standardized responses between different query clients and dialects.\n\nAs of Mar 29, 2024, Knex has 1,625,784 weekly downloads on npm (3rd most popular SQL library). It is a very popular query builder for Node.js and TypeScript.\n\nKnex IS legendary, but since it was created before TypeScript blew up, it's type capabilities are nothing to write home about. This why Kysely was created.\n\nKysely (pronounced “Key-Seh-Lee”) is a type-safe and autocompletion-friendly TypeScript SQL query builder. Inspired by Knex. Mainly developed for Node.js but also runs on Deno and in the browser.\n\nkysely-knex is a toolkit (dialect, type translators, custom migration source, etc.) that allows using your existing Knex setup with Kysely. This'll allow you to gradually migrate your codebase from Knex to Kysely.\n\n## Installation\n\nMain dependencies:\n\n```sh\nnpm install kysely kysely-knex knex\n```\n\nPostgreSQL:\n\n```sh\nnpm install pg pg-query-stream # pg-query-stream is optional, used in .stream() method\n```\n\nMySQL:\n\n```sh\nnpm install mysql2 # or mysql\n```\n\nMS SQL Server (MSSQL):\n\n```sh\nnpm install tedious\n```\n\nSQLite:\n\n```sh\nnpm install better-sqlite3 # or sqlite3\n```\n\n## Usage\n\n### Types\n\nIf you have already defined your Knex `Tables` interface, you can convert it using\nthe `KyselifyTables` type:\n\n`src/types/database.ts`:\n\n```ts\nimport type {Tables} from 'knex/types/tables'\nimport type {KyselifyTables} from 'kysely-knex'\n\nexport type Database = KyselifyTables<Tables>\n```\n\nOtherwise, refer to the [Kysely documentation](https://kysely.dev/docs/getting-started#types) for more information.\n\n### Kysley instance\n\nCreate a Kysely instance. Pass it your existing Knex instance:\n\n`src/kysely.ts`:\n\n```ts\nimport {Kysely} from 'kysely'\nimport {KyselyKnexDialect, PGColdDialect} from 'kysely-knex'\nimport {knex} from './knex'\nimport type {Database} from './types/database'\n\nexport const kysely = new Kysely<Database>({\n  dialect: new KyselyKnexDialect({\n    knex,\n    kyselySubDialect: new PGColdDialect(),\n  }),\n})\n```\n\nFor other dialects, simply swap `PGColdDialect` with `MySQLColdDialect`, `MySQL2ColdDialect`, `MSSQLColdDialect`, `SQLite3ColdDialect` or `BetterSQLite3ColdDialect`.\n\n### Migrations\n\nThere are a few ways to tackle migrations given you have an existing Knex migration setup:\n\n1. Delete all existing migrations and start fresh with Kysely migrations.\n2. Use our [custom migration source](https://knexjs.org/guide/migrations.html#custom-migration-sources) `KyselyFsMigrationSource` to provide a Kysely instance to your Knex-managed migrations:\n\n`migrations/20240101000000_add_email_column.ts`:\n\n```ts\nimport type {Knex} from 'knex'\nimport type {Kysely} from 'kysely'\n\nexport async function up(_: Knex, kysely: Kysely<any>): Promise<void> {\n  await kysely.schema\n    .alterTable('dog_walker')\n    .addColumn('email', 'varchar', (cb) => cb.unique())\n    .execute()\n}\n\nexport async function down(_: Knex, kysely: Kysely<any>): Promise<void> {\n  await kysely.schema.alterTable('dog_walker').dropColumn('email').execute()\n}\n```\n\nPass the migration source to all migrate commands as follows:\n\n`scripts/migrate-to-latest.ts`:\n\n```ts\nimport {join} from 'node:path'\nimport {KyselyFsMigrationSource} from 'kysely-knex'\nimport {knex} from '../src/knex'\nimport {kysely} from '../src/kysely'\n\nexport const migrationSource = new KyselyFsMigrationSource({\n  migrationDirectories: join(__dirname, '../migrations'),\n})\n\nawait knex.migrate.latest({migrationSource})\n```\n\nor pass it to Knex CLI globally:\n\n`knexfile.ts`:\n\n```ts\nconst {KyselyFsMigrationSource, PGColdDialect} = require('kysely-knex')\n\nmodule.exports = {\n  // ...\n  migrations: {\n    // ...\n    migrationSource: new KyselyFsMigrationSource({\n      kyselySubDialect: new PGColdDialect(),\n      migrationDirectories: 'migrations',\n    }),\n    // ...\n  },\n  // ...\n}\n```\n\nThis'll allow you to seamlessly transition to only use Kysely from a certain point in time. Then, you could gradually convert existing Knex migration files to use Kysely instead of Knex, as all migrations now receive a Kysely instance.\n\nMore ways to tackle this topic might be provided in the future. Stay tuned!\n","readmeFilename":"README.md"}