import { Dialect, DialectAdapter, Driver, Kysely, DatabaseIntrospector, QueryCompiler, DatabaseConnection, TransactionSettings, CompiledQuery, QueryResult, JSONColumnType as JSONColumnType$1, Generated as Generated$1, GeneratedAlways as GeneratedAlways$1 } from 'kysely'; import { DataSource, QueryRunner } from 'typeorm'; interface KyselyTypeORMDialectConfig { kyselySubDialect: KyselySubDialect; typeORMDataSource: DataSource; } type KyselySubDialect = Omit; declare class KyselyTypeORMDialect implements Dialect { #private; constructor(config: KyselyTypeORMDialectConfig); createAdapter(): DialectAdapter; createDriver(): Driver; createIntrospector(db: Kysely): DatabaseIntrospector; createQueryCompiler(): QueryCompiler; } declare class KyselyTypeORMConnection implements DatabaseConnection { #private; constructor(queryRunner: QueryRunner); beginTransaction(settings: TransactionSettings): Promise; commitTransaction(): Promise; release(): Promise; rollbackTransaction(): Promise; executeQuery(compiledQuery: CompiledQuery): Promise>; streamQuery(compiledQuery: CompiledQuery): AsyncIterableIterator>; } declare class KyselyTypeORMDriver implements Driver { #private; constructor(config: KyselyTypeORMDialectConfig); acquireConnection(): Promise; beginTransaction(connection: KyselyTypeORMConnection, settings: TransactionSettings): Promise; commitTransaction(connection: KyselyTypeORMConnection): Promise; destroy(): Promise; init(): Promise; releaseConnection(connection: KyselyTypeORMConnection): Promise; rollbackTransaction(connection: KyselyTypeORMConnection): Promise; } /** * This is used to mark entity properties that have their values generated by TypeORM * or the database, so that {@link KyselifyEntity} can mark them as Kysely Generated. * * Kysely treats Generated properties as write-optional. * * Also see {@link GeneratedAlways} and {@link NonAttribute}. * * ### example * * ```ts * import type { Generated, GeneratedAlways, NonAttribute } from 'kysely-typeorm' * import { * Column, * CreateDateColumn, * DeleteDateColumn, * Entity, * Generated as TypeORMGenerated, * PrimaryGeneratedColumn, * UpdateDateColumn, * VersionColumn * } from 'typeorm' * * \@Entity({ name: 'user' }) * export class UserEntity { * \@PrimaryGeneratedColumn() * id: GeneratedAlways * * \@Column({ type: 'varchar', length: 255, unique: true }) * username: string * * \@Column({ type: 'varchar', length: 255, nullable: true }) * steamAccountId: string | null * * \@CreateDateColumn() * createdAt: Generated * * \@UpdateDateColumn() * updatedAt: Generated * * \@DeleteDateColumn() * deletedAt: Generated * * \@VersionColumn() * version: Generated * * \@Column() * \@TypeORMGenerated('uuid') * uuid: Generated * } * * type User = KyselifyEntity * // ^? { id: GeneratedAlways, username: string, steamAccountId: string | null, createdAt: Generated, updatedAt: Generated, deletedAt: Generated, version: Generated, uuid: Generated } * ``` */ type Generated = (Exclude & { readonly __kysely__generated__?: unique symbol; }) | Extract; /** * This is used to mark entity properties that have their values generated by TypeORM * or the database, so that {@link KyselifyEntity} can mark them as Kysely GeneratedAlways. * * Kysely treats GeneratedAlways properties as read-only. * * Also see {@link Generated} and {@link NonAttribute}. * * ### example * * ```ts * import type { Generated, GeneratedAlways, NonAttribute } from 'kysely-typeorm' * import { * Column, * CreateDateColumn, * DeleteDateColumn, * Generated as TypeORMGenerated, * PrimaryGeneratedColumn, * UpdateDateColumn, * VersionColumn * } from 'typeorm' * * \@Entity({ name: 'user' }) * export class UserEntity { * \@PrimaryGeneratedColumn() * id: GeneratedAlways * * \@Column({ type: 'varchar', length: 255, unique: true }) * username: string * * \@Column({ type: 'varchar', length: 255, nullable: true }) * steamAccountId: string | null * * \@CreateDateColumn() * createdAt: Generated * * \@UpdateDateColumn() * updatedAt: Generated * * \@DeleteDateColumn() * deletedAt: Generated * * \@VersionColumn() * version: Generated * * \@Column() * \@TypeORMGenerated('uuid') * uuid: Generated * } * * type User = KyselifyEntity * // ^? { id: GeneratedAlways, username: string, steamAccountId: string | null, createdAt: Generated, updatedAt: Generated, deletedAt: Generated, version: Generated, uuid: Generated } * ``` */ type GeneratedAlways = (Exclude & { readonly __kysely__generated__always__?: unique symbol; }) | Extract; /** * This is used to mark entity properties that are populated at runtime by TypeORM and do * not exist in the database schema, so that {@link KyselifyEntity} can exclude * them. * * ### example * * ```ts * import type { GeneratedAlways, NonAttribute } from 'kysely-typeorm' * import { * Column, * Entity, * JoinColumn, * ManyToMany, * ManyToOne, * OneToMany, * PrimaryGeneratedColumn, * RelationId, * VirtualColumn * } from 'typeorm' * import { ClanEntity } from './Clan' * import { PostEntity } from './Post' * import { RoleEntity } from './Role' * * \@Entity({ name: 'user' }) * export class UserEntity { * \@PrimaryGeneratedColumn() * id: GeneratedAlways * * \@Column({ type: 'varchar', length: 255, unique: true }) * username: string * * \@Column({ type: 'varchar', length: 255, nullable: true }) * steamAccountId: string | null * * \@OneToMany(() => PostEntity, (post) => post.user) * posts: NonAttribute * * \@ManyToOne(() => ClanEntity, (clan) => clan.users) * \@JoinColumn({ name: 'clanId', referencedColumnName: 'id' }) * clan: NonAttribute * * \@RelationId((user) => user.clan) * clanId: number | null * * \@ManyToMany(() => RoleEntity) * \@JoinTable() * roles: NonAttribute * * \@RelationId((role) => role.users) * roleIds: NonAttribute * * \@VirtualColumn({ query: (alias) => `select count("id") from "posts" where "author_id" = ${alias}.id` }) * totalPostsCount: NonAttribute * } * * type User = KyselifyEntity * // ^? { id: Generated, username: string, steamAccountId: string | null, clanId: number | null } * ``` */ type NonAttribute = (Exclude & { readonly __kysely__non__attribute__?: unique symbol; }) | Extract; /** * This is used to mark entity properties of type `'simple-array'` that are stored as * comma-separated string values in the database, and are transformed into arrays in the * TypeORM entity, so that they are properly represented as string values when * fetched from the database using Kysely. */ type SimpleArray = (Exclude & { readonly __kysely__simple__array__?: unique symbol; }) | Extract; /** * This is used to mark entity properties of type `'simple-json'` or other JSON types that are stored as * `JSON.stringify`d values in the database, and are `JSON.parse`d in the * TypeORM entity, so that they are properly represented as string values when * fetched from the database using Kysely. */ type JSONColumnType = (Exclude & { readonly __kysely__json__?: unique symbol; }) | Extract; /** * This is used to transform TypeORM entities into Kysely entities. * * Also see {@link Generated}, {@link GeneratedAlways} and {@link NonAttribute}. * * ### example * * ```ts * import type { Generated, GeneratedAlways, NonAttribute } from 'kysely-typeorm' * import { * Column, * CreateDateColumn, * DeleteDateColumn, * Entity, * Generated as TypeORMGenerated, * JoinColumn, * JoinTable, * ManyToMany, * ManyToOne, * OneToMany, * PrimaryGeneratedColumn, * RelationId, * UpdateDateColumn, * VersionColumn, * VirtualColumn * } from 'typeorm' * import { ClanEntity } from './Clan' * import { PostEntity } from './Post' * import { RoleEntity } from './Role' * * \@Entity({ name: 'user' }) * export class UserEntity { * \@PrimaryGeneratedColumn() * id: GeneratedAlways * * \@Column({ type: 'varchar', length: 255, unique: true }) * username: string * * \@Column({ type: 'varchar', length: 255, nullable: true }) * steamAccountId: string | null * * \@CreateDateColumn() * createdAt: Generated * * \@UpdateDateColumn() * updatedAt: Generated * * \@DeleteDateColumn() * deletedAt: Generated * * \@VersionColumn() * version: Generated * * \@Column() * \@TypeORMGenerated('uuid') * uuid: Generated * * \@OneToMany(() => PostEntity, (post) => post.user) * posts: NonAttribute * * \@ManyToOne(() => ClanEntity, (clan) => clan.users) * \@JoinColumn({ name: 'clanId', referencedColumnName: 'id' }) * clan: NonAttribute * * \@RelationId((user) => user.clan) * clanId: number | null * * \@ManyToMany(() => RoleEntity) * \@JoinTable() * roles: NonAttribute * * \@RelationId((role) => role.users) * roleIds: NonAttribute * * \@VirtualColumn({ query: (alias) => `select count("id") from "posts" where "author_id" = ${alias}.id` }) * totalPostsCount: NonAttribute * } * * export type User = KyselifyEntity * // ^? { id: GeneratedAlways, username: string, steamAccountId: string | null, createdAt: Generated, updatedAt: Generated, deletedAt: Generated, version: Generated, uuid: Generated, clandId: number | null } * ``` * * and then you can use it like this: * * ```ts * import { Clan } from './Clan' * import { Post } from './Post' * import { Role } from './Role' * import { User } from './User' * * export interface Database { * clan: Clan * post: Post * role: Role * user: User * } * * export const kysely = new Kysely( * // ... * ) * ``` */ type KyselifyEntity = { [K in keyof E as E[K] extends (...args: any) => any ? never : string extends keyof NonNullable ? K : '__kysely__non__attribute__' extends keyof NonNullable ? never : K]-?: string extends keyof NonNullable ? '__kysely__json__' extends keyof NonNullable ? E[K] extends JSONColumnType ? JSONColumnType$1 : never : E[K] extends object | null ? JSONColumnType$1 : never : '__kysely__generated__' extends keyof NonNullable ? E[K] extends Generated ? Generated$1> : never : '__kysely__generated__always__' extends keyof NonNullable ? E[K] extends GeneratedAlways ? GeneratedAlways$1> : never : '__kysely__simple__array__' extends keyof NonNullable ? E[K] extends SimpleArray ? string | Extract : never : '__kysely__json__' extends keyof NonNullable ? E[K] extends JSONColumnType ? JSONColumnType$1 : never : Exclude; }; export { type Generated, type GeneratedAlways, type JSONColumnType, type KyselifyEntity, type KyselySubDialect, KyselyTypeORMDialect, type KyselyTypeORMDialectConfig, KyselyTypeORMDriver, type NonAttribute, type SimpleArray };