bknd
Version:
Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.
81 lines (80 loc) • 3.46 kB
TypeScript
import { type AliasableExpression, type ColumnBuilderCallback, type ColumnDataType, type DatabaseIntrospector, type Dialect, type Expression, type Kysely, type KyselyPlugin, type OnModifyForeignAction, type RawBuilder, type SelectQueryBuilder, type SelectQueryNode, type Simplify } from "kysely";
import type { BaseIntrospector, BaseIntrospectorConfig } from "./BaseIntrospector";
import type { Constructor } from "../../core";
export type QB = SelectQueryBuilder<any, any, any>;
export type IndexMetadata = {
name: string;
table: string;
isUnique: boolean;
columns: {
name: string;
order: number;
}[];
};
export interface SelectQueryBuilderExpression<O> extends AliasableExpression<O> {
get isSelectQueryBuilder(): true;
toOperationNode(): SelectQueryNode;
}
export type SchemaResponse = [string, ColumnDataType, ColumnBuilderCallback] | undefined;
declare const FieldSpecTypes: readonly ["text", "integer", "real", "blob", "date", "datetime", "timestamp", "boolean", "json"];
export type FieldSpec = {
type: (typeof FieldSpecTypes)[number];
name: string;
nullable?: boolean;
dflt?: any;
unique?: boolean;
primary?: boolean;
references?: string;
onDelete?: OnModifyForeignAction;
onUpdate?: OnModifyForeignAction;
};
export type IndexSpec = {
name: string;
columns: string[];
unique?: boolean;
};
export type DbFunctions = {
jsonObjectFrom<O>(expr: SelectQueryBuilderExpression<O>): RawBuilder<Simplify<O> | null>;
jsonArrayFrom<O>(expr: SelectQueryBuilderExpression<O>): RawBuilder<Simplify<O>[]>;
jsonBuildObject<O extends Record<string, Expression<unknown>>>(obj: O): RawBuilder<Simplify<{
[K in keyof O]: O[K] extends Expression<infer V> ? V : never;
}>>;
};
export declare abstract class Connection<DB = any> {
fn: Partial<DbFunctions>;
protected plugins: KyselyPlugin[];
protected initialized: boolean;
kysely: Kysely<DB>;
protected readonly supported: {
batching: boolean;
};
constructor(kysely: Kysely<DB>, fn?: Partial<DbFunctions>, plugins?: KyselyPlugin[]);
init(): Promise<void>;
/**
* This is a helper function to manage Connection classes
* coming from different places
* @param conn
*/
static isConnection(conn: unknown): conn is Connection;
getIntrospector(): BaseIntrospector;
supports(feature: keyof typeof this.supported): boolean;
ping(): Promise<boolean>;
protected batch<Queries extends QB[]>(queries: [...Queries]): Promise<{
[K in keyof Queries]: Awaited<ReturnType<Queries[K]["execute"]>>;
}>;
batchQuery<Queries extends QB[]>(queries: [...Queries]): Promise<{
[K in keyof Queries]: Awaited<ReturnType<Queries[K]["execute"]>>;
}>;
protected validateFieldSpecType(type: string): type is FieldSpec["type"];
abstract getFieldSchema(spec: FieldSpec, strict?: boolean): SchemaResponse;
close(): Promise<void>;
}
export declare function customIntrospector<T extends Constructor<Dialect>>(dialect: T, introspector: Constructor<DatabaseIntrospector>, options?: BaseIntrospectorConfig): {
create(...args: ConstructorParameters<T>): {
createIntrospector(db: Kysely<any>): DatabaseIntrospector;
createDriver(): import("kysely").Driver;
createQueryCompiler(): import("kysely").QueryCompiler;
createAdapter(): import("kysely").DialectAdapter;
} & Dialect;
};
export {};