{"id":13464015,"url":"https://github.com/depot/kysely-planetscale","last_synced_at":"2025-05-15T01:10:08.782Z","repository":{"id":58338128,"uuid":"531295785","full_name":"depot/kysely-planetscale","owner":"depot","description":"A Kysely dialect for PlanetScale Serverless","archived":false,"fork":false,"pushed_at":"2025-03-14T12:09:31.000Z","size":1722,"stargazers_count":353,"open_issues_count":0,"forks_count":16,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-05-06T07:06:14.201Z","etag":null,"topics":["kysely","kysely-dialect","mysql","planetscale","vitess"],"latest_commit_sha":null,"homepage":"https://depot.dev/blog/kysely-dialect-planetscale","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/depot.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"support/banner.jpg","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-08-31T23:42:43.000Z","updated_at":"2025-04-13T22:02:24.000Z","dependencies_parsed_at":"2023-01-31T11:31:17.868Z","dependency_job_id":"127384a7-4cae-4c89-b98c-d6b6fa31f946","html_url":"https://github.com/depot/kysely-planetscale","commit_stats":{"total_commits":46,"total_committers":11,"mean_commits":4.181818181818182,"dds":"0.32608695652173914","last_synced_commit":"8e505212d8cf93bd7d9178cfac820710ee37ae32"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/depot%2Fkysely-planetscale","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/depot%2Fkysely-planetscale/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/depot%2Fkysely-planetscale/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/depot%2Fkysely-planetscale/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/depot","download_url":"https://codeload.github.com/depot/kysely-planetscale/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254254042,"owners_count":22039792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kysely","kysely-dialect","mysql","planetscale","vitess"],"created_at":"2024-07-31T14:00:32.116Z","updated_at":"2025-05-15T01:10:03.766Z","avatar_url":"https://github.com/depot.png","language":"TypeScript","funding_links":[],"categories":["Documentation","TypeScript"],"sub_categories":[],"readme":"![Banner Image](./support/banner.jpg)\n\n# kysely-planetscale\n\n[![CI](https://github.com/depot/kysely-planetscale/actions/workflows/ci.yml/badge.svg)](https://github.com/depot/kysely-planetscale/actions/workflows/ci.yml)\n[![npm](https://img.shields.io/npm/v/kysely-planetscale.svg)](https://www.npmjs.com/package/kysely-planetscale)\n![Powered by TypeScript](https://img.shields.io/badge/powered%20by-typescript-blue.svg)\n\nA [Kysely](https://github.com/koskimas/kysely) dialect for [PlanetScale](https://planetscale.com/), using the [PlanetScale serverless driver for JavaScript](https://planetscale.com/blog/introducing-the-planetscale-serverless-driver-for-javascript).\n\n## Installation\n\nYou should install both `kysely` and `@planetscale/database` with `kysely-planetscale`, as they are both required peer dependencies. You can install them with your favorite package manager:\n\n```bash\n# with pnpm\npnpm add kysely-planetscale kysely @planetscale/database\n\n# with yarn\nyarn add kysely-planetscale kysely @planetscale/database\n\n# with npm\nnpm install kysely-planetscale kysely @planetscale/database\n```\n\n## Usage\n\nYou can pass a new instance of `PlanetScaleDialect` as the `dialect` option when creating a new `Kysely` instance:\n\n```typescript\nimport {Kysely} from 'kysely'\nimport {PlanetScaleDialect} from 'kysely-planetscale'\n\nconst db = new Kysely\u003cDatabase\u003e({\n  dialect: new PlanetScaleDialect({\n    host: '\u003chost\u003e',\n    username: '\u003cuser\u003e',\n    password: '\u003cpassword\u003e',\n  }),\n})\n```\n\n`PlanetScaleDialect` accepts the same options as `connect({...})` from `@planetscale/database`, so for instance if you are using Node.js and need to provide a `fetch` implementation:\n\n```typescript\nimport {Kysely} from 'kysely'\nimport {PlanetScaleDialect} from 'kysely-planetscale'\nimport {fetch} from 'undici'\n\n// Connect using a DATABASE_URL, provide a fetch implementation\nconst db = new Kysely\u003cDatabase\u003e({\n  dialect: new PlanetScaleDialect({\n    url: process.env.DATABASE_URL,\n    fetch,\n  }),\n})\n```\n\n### Type Conversion\n\n`PlanetScaleDialect` provides built-in support for converting JavaScript Dates to and from `DATETIME` and `TIMESTAMP` columns, as Kysely's generated types expect. However, you can override or extend this behavior by providing a custom `format` or `cast` function to override the defaults.\n\n#### Custom `format` function\n\n`PlanetScaleDialect` passes all parameters to `@planetscale/database` unmodified, except for JavaScript Dates, which are converted to MySQL strings. If you [set a `format` function](https://github.com/planetscale/database-js#custom-query-parameter-format-function), you can override this behavior:\n\n```typescript\nimport {Kysely} from 'kysely'\nimport {PlanetScaleDialect} from 'kysely-planetscale'\nimport SqlString from 'sqlstring'\n\nconst db = new Kysely\u003cDatabase\u003e({\n  dialect: new PlanetScaleDialect({\n    url: process.env.DATABASE_URL,\n    format: SqlString.format,\n  }),\n})\n```\n\n#### Custom `cast` function\n\n`PlanetScaleDialect` automatically type-casts `DATETIME` and `TIMESTAMP` to JavaScript Dates. If you'd prefer to customize this behavior, you can [pass a custom `cast` function](https://github.com/planetscale/database-js#custom-type-casting-function):\n\n```typescript\nimport {cast} from '@planetscale/database'\nimport {Kysely} from 'kysely'\nimport {PlanetScaleDialect} from 'kysely-planetscale'\nimport SqlString from 'sqlstring'\n\nconst db = new Kysely\u003cDatabase\u003e({\n  dialect: new PlanetScaleDialect({\n    url: process.env.DATABASE_URL,\n    cast: inflate,\n  }),\n})\n\nfunction inflate(field, value) {\n  if (field.type === 'INT64' || field.type === 'UINT64') {\n    return BigInt(value)\n  }\n  return cast(field, value)\n}\n```\n\n#### Experimental: `useSharedConnection`\n\nAs of version 1.3.0, `PlanetScaleDialect` supports using a shared `@planetscale/database` connection for all non-transaction queries, to improve query performance. This option is not enabled by default, but can be enabled by setting the `useSharedConnection` option to `true`. Transaction queries will always run using their own connection.\n\nThis is an experimental feature, and may be removed in a future version.\n\n```typescript\nimport {Kysely} from 'kysely'\nimport {PlanetScaleDialect} from 'kysely-planetscale'\n\nconst db = new Kysely\u003cDatabase\u003e({\n  dialect: new PlanetScaleDialect({\n    url: process.env.DATABASE_URL,\n    useSharedConnection: true,\n  }),\n})\n```\n\n## License\n\nMIT License, see `LICENSE`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdepot%2Fkysely-planetscale","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdepot%2Fkysely-planetscale","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdepot%2Fkysely-planetscale/lists"}