kysely-planetscale
Version:
Kysely dialect for PlanetScale Serverless
57 lines (54 loc) • 1.98 kB
TypeScript
import { Config, Field } from '@planetscale/database';
import { Dialect, MysqlAdapter, Driver, QueryCompiler, Kysely, DatabaseIntrospector } from 'kysely';
/**
* Config for the PlanetScale dialect. It extends {@link Config} from `@planetscale/database`,
* so you can pass any of those options to the constructor.
*
* @see https://github.com/planetscale/database-js#usage
*/
interface PlanetScaleDialectConfig extends Config {
/**
* Use a single `@planetscale/database` connection for all non-transaction queries.
*
* @default false
*/
useSharedConnection?: boolean;
}
/**
* PlanetScale dialect that uses the [PlanetScale Serverless Driver for JavaScript][0].
* The constructor takes an instance of {@link Config} from `@planetscale/database`.
*
* ```typescript
* new PlanetScaleDialect({
* host: '<host>',
* username: '<username>',
* password: '<password>',
* })
*
* // or with a connection URL
*
* new PlanetScaleDialect({
* url: process.env.DATABASE_URL ?? 'mysql://<username>:<password>@<host>/<database>'
* })
* ```
*
* See the [`@planetscale/database` documentation][1] for more information.
*
* [0]: https://github.com/planetscale/database-js
* [1]: https://github.com/planetscale/database-js#readme
*/
declare class PlanetScaleDialect implements Dialect {
#private;
constructor(config: PlanetScaleDialectConfig);
createAdapter(): MysqlAdapter;
createDriver(): Driver;
createQueryCompiler(): QueryCompiler;
createIntrospector(db: Kysely<unknown>): DatabaseIntrospector;
}
/**
* Converts dates returned from the database to JavaScript Date objects. This is the default
* `cast` function passed to the `@planetscale/database` library, but you can override it by
* passing your own alternative `cast` function to {@link Config}.
*/
declare function inflateDates(field: Field, value: string | null): any;
export { PlanetScaleDialect, type PlanetScaleDialectConfig, inflateDates };