# API `@deepkit/sql`

```shell
npm install @deepkit/sql
```

## API reference of @deepkit/sql

### Sql (class)

```typescript
export class Sql {
    constructor(public sql: string = , public params: any[] = []);
    appendSql(sql: Sql);
    append(sql: string, params?: any[]);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-builder.ts#L22

### SqlBuilder (class)

```typescript
export class SqlBuilder {
    rootConverter?: ConvertDataToDict;
    constructor(protected adapter: PreparedAdapter, public params: string[] = []);
    convertRows(schema: ReflectionClass<any>, model: SQLQueryModel<any>, rows: any[]): any[];
    build<T extends OrmEntity>(schema: ReflectionClass<any>, model: SQLQueryModel<T>, head: string): Sql;
    update<T extends OrmEntity>(schema: ReflectionClass<any>, model: SQLQueryModel<T>, set: string[]): Sql;
    select(schema: ReflectionClass<any>, model: SQLQueryModel<any>, options: {
        select?: string[];
    } = {}): Sql;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-builder.ts#L74

### SqlReference (class)

```typescript
export class SqlReference {
    constructor(public readonly field: string);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-builder.ts#L556

### quoteSqlStringBackslash (function)

Quotes a string literal with backslash escapes (MySQL style).

```typescript
(value: string): string
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-escape.ts#L27

### quoteSqlString (function)

Quotes a string literal by doubling single quotes (SQL standard, used by SQLite).

```typescript
(value: string): string
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-escape.ts#L34

### sqlDateToString (function)

Formats a date in local time as quoted literal `'YYYY-MM-DD HH:mm:ss.mmm'`, or NULL for invalid dates.

```typescript
(date: Date): string
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-escape.ts#L45

### sqlEscape (function)

Escapes a primitive value or Date as SQL literal: NULL for null/undefined, true/false, numbers as is,
Dates via sqlDateToString, everything else as quoted string.

Objects and arrays need to be serialized (e.g. JSON.stringify) before.

```typescript
(value: any, quoteString?: (value: string) => string): string
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-escape.ts#L73

### splitDotPath (function)

user.address[0].street => [user, address[0].street]
address[0].street => [address, [0].street]

```typescript
(path: string): [string, string]
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L70

### asAliasName (function)

```typescript
(path: string): string
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L77

### identifier (function)

```typescript
(id: string): SQLQueryIdentifier
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L399

### sql (function)

```typescript
(strings: TemplateStringsArray, ...params: ReadonlyArray<any>): SqlQuery
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L451

### prepareBatchUpdate (function)

```typescript
(platform: DefaultPlatform, entity: PreparedEntity, changeSets: DatabasePersistenceChangeSet<any>[], options?: { setNamesWithTableName?: true; }): { changedFields: string[]; ... 12 more ...; tableName: string; } | undefined
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L963

### SORT_TYPE (type)

```typescript
type SORT_TYPE = SORT_ORDER | { $meta: 'textScore' };
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L63

### DEEP_SORT (type)

```typescript
type DEEP_SORT<T extends OrmEntity> = { [P in keyof T]?: SORT_TYPE } & { [P: string]: SORT_TYPE };
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L64

### SQLQueryModel (class)

```typescript
export class SQLQueryModel<T extends OrmEntity> extends DatabaseQueryModel<T, FilterQuery<T>, DEEP_SORT<T>> {
    where?: SqlQuery;
    sqlSelect?: SqlQuery;
    clone(): this;
    isPartial(): boolean;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L81

### maxPreparedStatementLength (variable)

A statement longer than this is not kept, it is most likely a list that differs every time.

```typescript
number
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L98

### SQLStatement (class)

```typescript
export abstract class SQLStatement {
    abstract get(params?: any[]): Promise<any>;
    abstract all(params?: any[]): Promise<any[]>;
    abstract release(): void;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L100

### SQLConnection (class)

```typescript
export abstract class SQLConnection {
    released: boolean;
    constructor(protected connectionPool: SQLConnectionPool, public logger: Logger, public transaction?: DatabaseTransaction, public stopwatch?: Stopwatch);
    release();
    abstract prepare(sql: string): Promise<SQLStatement>;
    /**
     * Runs a single SQL query.
     */
    abstract run(sql: string, params?: any[]): Promise<any>;
    abstract getChanges(): Promise<number>;
    async execAndReturnSingle(sql: string, params?: any[]): Promise<any>;
    async execAndReturnAll(sql: string, params?: any[]): Promise<any>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L108

### SQLConnectionPool (class)

```typescript
export abstract class SQLConnectionPool {
    /**
     * How many prepared statements each connection keeps to run the same query again, 0 turns it off.
     * Has to be set before the first query. Turn it off when connecting through something that
     * shares connections between clients and doesn't support prepared statements, e.g. PgBouncer in transaction mode.
     */
    maxPreparedStatements: number;
    constructor(protected logger: Logger);
    setLogger(logger: Logger);
    /**
     * Reserves an existing or new connection. It's important to call `.release()` on it when
     * done. When release is not called a resource leak occurs and server crashes.
     */
    abstract getConnection(transaction?: DatabaseTransaction): Promise<SQLConnection>;
    getActiveConnections();
    release(connection: SQLConnection);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L159

### SQLQueryResolver (class)

```typescript
export class SQLQueryResolver<T extends OrmEntity> extends GenericQueryResolver<T> {
    constructor(protected connectionPool: SQLConnectionPool, protected platform: DefaultPlatform, classSchema: ReflectionClass<T>, protected adapter: SQLDatabaseAdapter, session: DatabaseSession<DatabaseAdapter>);
    /**
     * If possible, this method should handle specific SQL errors and convert
     * them to more specific error classes with more information, e.g. unique constraint.
     */
    handleSpecificError(error: Error): Error;
    async count(model: SQLQueryModel<T>): Promise<number>;
    async delete(model: SQLQueryModel<T>, deleteResult: DeleteResult<T>): Promise<void>;
    async find(model: SQLQueryModel<T>): Promise<T[]>;
    async findOneOrUndefined(model: SQLQueryModel<T>): Promise<T | undefined>;
    async has(model: SQLQueryModel<T>): Promise<boolean>;
    async patch(model: SQLQueryModel<T>, changes: Changes<T>, patchResult: PatchResult<T>): Promise<void>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L221

### SqlQueryParameter (class)

```typescript
export class SqlQueryParameter {
    constructor(public value: any);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L389

### SQLQueryIdentifier (class)

```typescript
export class SQLQueryIdentifier {
    constructor(public id: any);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L394

### SqlStatement (type)

```typescript
type SqlStatement = { sql: string, params: any[] };
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L403

### SqlQuery (class)

```typescript
export class SqlQuery {
    constructor(public parts: ReadonlyArray<QueryPart>);
    clone(): SqlQuery;
    convertToSQL(platform: DefaultPlatform, placeholderStrategy: SqlPlaceholderStrategy, tableName?: string): SqlStatement;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L405

### SQLDatabaseQuery (class)

```typescript
export class SQLDatabaseQuery<T extends OrmEntity> extends Query<T> {
    model: SQLQueryModel<T>;
    constructor(classSchema: ReflectionClass<T>, protected databaseSession: DatabaseSession<DatabaseAdapter>, public resolver: SQLQueryResolver<T>);
    /**
     * Adds raw SQL to the where clause of the query.
     * If there is a `filter()` set as well, the where is added after the filter using AND.
     *
     * ```
     * database.query(User).where(`id > ${id}`).find();
     * ```
     *
     * Use `${identifier('name')} = ${'Peter'}` for column names that need to be quoted.
     */
    where(sql: SqlQuery): this;
    /**
     * Adds additional selects to the query.
     * Automatically converts the query to a partial (no class instances).
     */
    sqlSelect(sql: SqlQuery): Replace<this, Pick<Resolve<this>, any>>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L471

### SQLDatabaseQueryFactory (class)

```typescript
export class SQLDatabaseQueryFactory extends DatabaseAdapterQueryFactory {
    constructor(protected connectionPool: SQLConnectionPool, protected platform: DefaultPlatform, protected databaseSession: DatabaseSession<any>);
    createQuery<T extends OrmEntity>(classType: ReceiveType<T> | ClassType<T> | AbstractClassType<T> | ReflectionClass<T>): SQLDatabaseQuery<T>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L510

### MigrationStateEntity (class)

```typescript
@entity.name()
export class MigrationStateEntity {
    created: Date;
    constructor(public version: number & PrimaryKey);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L522

### SqlMigrationHandler (class)

```typescript
export class SqlMigrationHandler {
    constructor(protected database: Database<SQLDatabaseAdapter>);
    async setLatestMigrationVersion(version: number): Promise<void>;
    async removeMigrationVersion(version: number): Promise<void>;
    async getLatestMigrationVersion(): Promise<number>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L530

### RawQuery (class)

```typescript
export class RawQuery<T> implements FindQuery<T> {
    constructor(protected session: DatabaseSession<SQLDatabaseAdapter>, protected connectionPool: SQLConnectionPool, protected platform: DefaultPlatform, protected sql: SqlQuery, protected type: Type);
    /**
     * Executes the raw query and returns nothing.
     */
    async execute(): Promise<void>;
    /**
     * Returns the SQL statement with placeholders replaced with the actual values.
     */
    getSql(): SqlStatement;
    /**
     * Returns the raw result of a single row.
     *
     * Note that this does not resolve/map joins. Use the regular database.query() for that.
     */
    async findOneOrUndefined(): Promise<T>;
    /**
     * Note that this does not resolve/map joins. Use the regular database.query() for that.
     */
    async findOne(): Promise<T>;
    /**
     * Returns the full result of a raw query.
     *
     * Note that this does not resolve/map joins. Use the regular database.query() for that.
     */
    async find(): Promise<T[]>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L566

### SqlRawFactory (class)

```typescript
export class SqlRawFactory implements RawFactory<[
    SqlQuery
]> {
    constructor(protected session: DatabaseSession<SQLDatabaseAdapter>, protected connectionPool: SQLConnectionPool, protected platform: DefaultPlatform);
    create<T = unknown>(sql: SqlQuery, type?: ReceiveType<T>): RawQuery<T>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L634

### SQLDatabaseAdapter (class)

```typescript
export abstract class SQLDatabaseAdapter extends DatabaseAdapter {
    abstract platform: DefaultPlatform;
    abstract connectionPool: SQLConnectionPool;
    preparedEntities;
    abstract queryFactory(databaseSession: DatabaseSession<this>): SQLDatabaseQueryFactory;
    abstract createPersistence(databaseSession: DatabaseSession<this>): SQLPersistence;
    abstract getSchemaName(): string;
    rawFactory(session: DatabaseSession<this>): SqlRawFactory;
    async getInsertBatchSize(schema: ReflectionClass<any>): Promise<number>;
    async getUpdateBatchSize(schema: ReflectionClass<any>): Promise<number>;
    isNativeForeignKeyConstraintSupported();
    createSelectSql(query: Query<any>): Sql;
    /**
     * Creates (and re-creates already existing) tables in the database.
     * This is only for testing purposes useful.
     *
     * WARNING: THIS DELETES ALL AFFECTED TABLES AND ITS CONTENT.
     */
    async createTables(entityRegistry: DatabaseEntityRegistry): Promise<void>;
    /**
     * Returns the migration SQL per entity, e.g. to display them. To apply them, use migrate(),
     * since single entity migrations can reference tables that are only created in a later one.
     */
    async getMigrations(options: MigrateOptions, entityRegistry: DatabaseEntityRegistry): Promise<{
        [name: string]: {
            sql: string[];
            diff: string;
        };
    }>;
    async migrate(options: MigrateOptions, entityRegistry: DatabaseEntityRegistry): Promise<void>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L648

### SQLPersistence (class)

```typescript
export class SQLPersistence extends DatabasePersistence {
    constructor(protected platform: DefaultPlatform, public connectionPool: SQLConnectionPool, protected session: DatabaseSession<SQLDatabaseAdapter>);
    /**
     * If possible, this method should handle specific SQL errors and convert
     * them to more specific error classes with more information, e.g. unique constraint.
     */
    handleSpecificError(error: Error): Error;
    async getConnection(): Promise<ReturnType<this[][]>>;
    release();
    async insert<T extends OrmEntity>(classSchema: ReflectionClass<T>, items: T[]): Promise<void>;
    async update<T extends OrmEntity>(classSchema: ReflectionClass<T>, changeSets: DatabasePersistenceChangeSet<T>[]): Promise<void>;
    async batchUpdate<T extends OrmEntity>(entity: PreparedEntity, changeSets: DatabasePersistenceChangeSet<T>[]): Promise<void>;
    async remove<T extends OrmEntity>(classSchema: ReflectionClass<T>, items: T[]): Promise<void>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-adapter.ts#L774

### LruCache (class)

Keeps the most recently used values, the oldest is dropped when it is full.

```typescript
export class LruCache<T> {
    constructor(public readonly maxSize: number, protected onEvict?: (key: string, value: T) => void);
    get size(): number;
    get(key: string): T | undefined;
    set(key: string, value: T): void;
    delete(key: string): void;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/lru-cache.ts#L14

### getRowFactory (function)

Returns a function that turns the column values of a row into an object with the given column names.

Drivers are faster when they return arrays, and all rows of a factory share one object shape,
which makes reading them in the deserializer faster too. As with a driver that returns objects,
the last column wins when a name is used twice.

```typescript
(names: string[]): RowFactory
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/row-factory.ts#L26

### createRows (function)

Replaces each array in rows, in place, with its object.

```typescript
(rows: any[][], factory: RowFactory): any[]
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/row-factory.ts#L45

### RowFactory (type)

```typescript
type RowFactory = (values: any[]) => any;
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/row-factory.ts#L15

### SQLFilterBuilder (class)

```typescript
export class SQLFilterBuilder {
    params: any[];
    constructor(protected adapter: PreparedAdapter, protected schema: ReflectionClass<any>, protected tableName: string, protected serializer: Serializer, public placeholderStrategy: SqlPlaceholderStrategy);
    isNull();
    regexpComparator(lvalue: string, value: RegExp): string;
    isNotNull();
    convert(filter: Filter): string;
    /**
     * Normalizes values necessary for the connection driver to bind parameters for prepared statements.
     * E.g. SQLite does not support boolean, so we convert boolean to number.
     */
    bindValue(value: any): any;
    requiresJson(type: Type): boolean;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/sql-filter-builder.ts#L27

### Migration (type)

```typescript
interface Migration {
    databaseName: string;
    version: number;
    name?: string;

    up(): string[];

    down(): string[];
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/migration/migration.ts#L11

### MigrationProvider (class)

```typescript
export class MigrationProvider {
    constructor(public databases: DatabaseRegistry);
    getMigrationDir(): string;
    setMigrationDir(dir: string);
    /**
     * Registers the Database instances exported by the given files (e.g. `export const database = new Database(...)`),
     * for using the migration commands without the FrameworkModule (deepkit-sql --path database.ts).
     *
     * TypeScript files are loaded with ts-node (registered if it is not already), so that entities get runtime types.
     */
    addDatabasesFromFiles(paths: string[]): void;
    async getMigrationsPerDatabase(limitDatabase?: string);
    async getMigrations(migrationDir: string): Promise<Migration[]>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/migration/migration-provider.ts#L23

### schemaMigrationRoundTrip (function)

```typescript
(types: (Type | ClassType | ReflectionClass<any>)[], adapter: SQLDatabaseAdapter): Promise<string>
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/test.ts#L7

### DatabaseModel (class)

```typescript
export class DatabaseModel {
    schemaName: string;
    schemaMap;
    constructor(public tables: Table[] = [], public adapterName: string = );
    getTableForClass(schema: ReflectionClass<any>): Table;
    removeUnknownTables(other: DatabaseModel);
    removeTable(name: string, schemaName?: string);
    addTable(name: string);
    getTable(name: string, schemaName?: string): Table;
    getTableNames(): string[];
    getTableForFull(fullName: string, schemaDelimiter: string): Table;
    hasTable(name: string, schemaName?: string): boolean;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/schema/table.ts#L15

### Table (class)

```typescript
export class Table {
    schemaName: string;
    alias: string;
    columnForProperty: Map<ReflectionProperty, Column>;
    columns: Column[];
    indices: IndexModel[];
    foreignKeys: ForeignKey[];
    constructor(public name: string);
    isName(name: string, schemaName?: string): boolean;
    getName(): string;
    getFullName(schemaDelimiter: string): string;
    addColumn(name: string, property?: ReflectionProperty): Column;
    addIndex(name: string, unique = false): IndexModel;
    addForeignKey(name: string, foreignTable: Table): ForeignKey;
    hasColumn(name: string): boolean;
    getColumn(name: string): Column;
    getColumnForProperty(property: ReflectionProperty): Column;
    getPrimaryKeys(): Column[];
    getAutoIncrements(): Column[];
    getIndices();
    getIndex(name: string);
    getUnices();
    hasPrimaryKey();
    hasCompositePrimaryKey();
    getForeignKeyOfLocalColumn(column: Column): ForeignKey | undefined;
    hasIndexByName(name: string): boolean;
    hasIndex(columns: Column[], unique = false): boolean;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/schema/table.ts#L73

### Column (class)

```typescript
export class Column {
    description: string;
    type?: string;
    size?: number;
    scale?: number;
    unsigned: boolean;
    defaultValue?: any;
    defaultExpression?: string;
    isNotNull;
    isPrimaryKey;
    isAutoIncrement;
    constructor(public table: Table, public name: string);
    getName(): string;
    getFullName(): string;
    getSizeDefinition();
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/schema/table.ts#L190

### IndexModel (class)

```typescript
export class IndexModel {
    columns: Column[];
    spatial: boolean;
    partial: boolean;
    size: number;
    constructor(public table: Table, public name: string, public isUnique = false);
    getName(): string;
    hasColumn(columnName: string);
    addColumn(columnName: string);
    valueOf(): string;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/schema/table.ts#L228

### ForeignKeyAction (type)

```typescript
type ForeignKeyAction = 'RESTRICT' | 'NO ACTION' | 'CASCADE' | 'SET NULL' | 'SET DEFAULT';
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/schema/table.ts#L263

### ForeignKey (class)

```typescript
export class ForeignKey {
    localColumns: Column[];
    foreignColumns: Column[];
    onUpdate: ForeignKeyAction;
    onDelete: ForeignKeyAction;
    constructor(public table: Table, public name: string, public foreign: Table);
    getName(): string;
    addReference(localColumnName: string, foreignColumnName: string);
    getColumnMapping(): [
        from: Column,
        to: Column
    ][];
    valueOf();
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/schema/table.ts#L265

### ColumnPropertyDiff (class)

```typescript
export class ColumnPropertyDiff {
    constructor(public readonly from: any, public readonly to: any);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/schema/table.ts#L304

### ColumnDiff (class)

```typescript
export class ColumnDiff {
    constructor(public from: Column, public to: Column, public changedProperties = new Map<keyof Column, ColumnPropertyDiff>());
    valueOf();
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/schema/table.ts#L309

### ColumnComparator (class)

```typescript
export class ColumnComparator {
    static computeDiff(from: Column, to: Column);
    static compareColumns(from: Column, to: Column);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/schema/table.ts#L326

### IndexComparator (class)

```typescript
export class IndexComparator {
    static computeDiff(from: IndexModel, to: IndexModel);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/schema/table.ts#L347

### ForeignKeyComparator (class)

```typescript
export class ForeignKeyComparator {
    static computeDiff(from: ForeignKey, to: ForeignKey);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/schema/table.ts#L358

### TableDiff (class)

```typescript
export class TableDiff {
    addedColumns: Column[];
    removedColumns: Column[];
    modifiedColumns: ColumnDiff[];
    renamedColumns: [
        from: Column,
        to: Column
    ][];
    addedPKColumns: Column[];
    removedPKColumns: Column[];
    renamedPKColumns: [
        from: Column,
        to: Column
    ][];
    addedIndices: IndexModel[];
    removedIndices: IndexModel[];
    modifiedIndices: [
        from: IndexModel,
        to: IndexModel
    ][];
    addedFKs: ForeignKey[];
    modifiedFKs: [
        from: ForeignKey,
        to: ForeignKey
    ][];
    removedFKs: ForeignKey[];
    constructor(public from: Table, public to: Table);
    hasModifiedPk(): boolean;
    toString();
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/schema/table.ts#L377

### TableComparator (class)

```typescript
export class TableComparator {
    readonly diff: TableDiff;
    constructor(public from: Table, public to: Table);
    static computeDiff(from: Table, to: Table): TableDiff | undefined;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/schema/table.ts#L484

### DatabaseDiff (class)

```typescript
export class DatabaseDiff {
    addedTables: Table[];
    removedTables: Table[];
    modifiedTables: TableDiff[];
    renamedTables: [
        from: Table,
        to: Table
    ][];
    constructor(public from: DatabaseModel, public to: DatabaseModel);
    removeTable(name: string, schema?: string);
    forTable(table: Table);
    getDiff(table: Table): TableDiff | undefined;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/schema/table.ts#L661

### DatabaseComparator (class)

```typescript
export class DatabaseComparator {
    readonly diff: DatabaseDiff;
    withRemoveTable: boolean;
    withRenaming: boolean;
    constructor(public from: DatabaseModel, public to: DatabaseModel);
    static computeDiff(from: DatabaseModel, to: DatabaseModel);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/schema/table.ts#L691

### parseDefaultLiteral (function)

Parses the default value of a column as reported by the database, if it is a literal (number, string,
true, false, null). A string containing JSON is parsed as JSON. Returns undefined for expressions like
CURRENT_TIMESTAMP, which are never evaluated.

```typescript
(dbDefault: string): { value: any; } | undefined
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/reverse/schema-parser.ts#L23

### parseType (function)

```typescript
(column: Column, type: string): void
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/reverse/schema-parser.ts#L43

### SchemaParser (class)

```typescript
export abstract class SchemaParser {
    constructor(protected connection: SQLConnection, protected platform: DefaultPlatform);
    abstract parse(database: DatabaseModel, limitTableNames?: string[]): Promise<void>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/reverse/schema-parser.ts#L66

### isSet (function)

```typescript
(v: any): boolean
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L32

### isNonUndefined (function)

```typescript
(type: Type): boolean
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L36

### typeResolvesToString (function)

```typescript
(type: Type): boolean
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L41

### typeResolvesToNumber (function)

```typescript
(type: Type): boolean
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L49

### typeResolvesToBigInt (function)

```typescript
(type: Type): boolean
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L57

### typeResolvesToInteger (function)

```typescript
(type: Type): boolean
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L65

### typeRequiresJSONCast (function)

```typescript
(type: Type): boolean
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L75

### typeResolvesToBoolean (function)

```typescript
(type: Type): boolean
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L83

### typeResolvesToDate (function)

```typescript
(type: Type): boolean
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L91

### noopSqlTypeCaster (function)

```typescript
(placeholder: string): string
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L96

### NamingStrategy (type)

```typescript
interface NamingStrategy {
    getColumnName(property: ReflectionProperty, databaseAdapterAnnotationId: string): string;

    getTableName(reflectionClass: ReflectionClass<any>): string;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L100

### DefaultNamingStrategy (class)

```typescript
export class DefaultNamingStrategy implements NamingStrategy {
    getColumnName(property: ReflectionProperty, databaseAdapterAnnotationId: string): string;
    getTableName(reflectionClass: ReflectionClass<any>): string;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L106

### SqlPlaceholderStrategy (class)

```typescript
export class SqlPlaceholderStrategy {
    constructor(public offset: number = );
    getPlaceholder(): string;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L118

### TypeMappingChecker (type)

```typescript
type TypeMappingChecker = (type: Type) => boolean;
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L132

### TypeMapping (type)

```typescript
interface TypeMapping {
    sqlType: string;
    size?: number;
    scale?: number;
    unsigned?: boolean;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L134

### DefaultPlatform (class)

```typescript
export abstract class DefaultPlatform {
    /**
     * The ID used in annotation to get database related type information (like `type`, `default`, `defaultExpr`, ...) via databaseAnnotation.getDatabase.
     */
    annotationId;
    abstract schemaParserType: ClassType<SchemaParser>;
    serializer: Serializer;
    namingStrategy: NamingStrategy;
    placeholderStrategy: ClassType<SqlPlaceholderStrategy>;
    applyLimitAndOffset(sql: Sql, limit?: number, offset?: number): void;
    createSqlFilterBuilder(adapter: PreparedAdapter, reflectionClass: ReflectionClass<any>, tableName: string): SQLFilterBuilder;
    getMigrationTableName();
    quoteValue(value: any): string;
    getAggregateSelect(tableName: string, property: ReflectionProperty, func: string);
    addBinaryType(sqlType: string, size?: number, scale?: number);
    /**
     * Last matching check wins.
     */
    addType(kind: ReflectionKind | TypeMappingChecker, sqlType: string, size?: number, scale?: number, unsigned?: boolean);
    getColumnListDDL(columns: Column[]);
    getSchemaDelimiter(): string;
    /**
     * If the platform supports the `SELECT FOR UPDATE` or `SELECT FOR SHARE`.
     */
    supportsSelectFor(): boolean;
    /**
     * If the platform supports the `PRIMARY KEY` section in `CREATE TABLE(column, column, PRIMARY KEY())`;
     */
    supportsInlinePrimaryKey(): boolean;
    /**
     * If the platform supports the `CONSTRAINT %s FOREIGN KEY` section in `CREATE TABLE(column, column, CONSTRAINT %s FOREIGN KEY)`;
     */
    supportsInlineForeignKey(): boolean;
    getPrimaryKeyDDL(table: Table);
    normalizeTables(tables: Table[]);
    getEntityFields(schema: ReflectionClass<any>): ReflectionProperty[];
    /**
     * Whether an accessor to e.g. "shippingAddress"->'$.street' = ?
     * requires real json at ? or SQL value is enough.
     * If this returns true, the value for ? is passed through JSON.stringify().
     */
    deepColumnAccessorRequiresJsonString(): boolean;
    getDeepColumnAccessor(table: string, column: string, path: string);
    getColumnAccessor(table: string, path: string);
    getModifyDatabaseDDL(databaseDiff: DatabaseDiff, options: MigrateOptions): string[];
    createTables(entityRegistry: DatabaseEntityRegistry, database: DatabaseModel = new DatabaseModel()): Table[];
    quoteIdentifier(id: string): string;
    isJson(type: Type): boolean;
    getSqlTypeCaster(type: Type): (placeholder: string) => string;
    getTableIdentifier(schema: ReflectionClass<any>): string;
    getIdentifier(object: Table | Column | IndexModel | ForeignKey, append: string = ): string;
    getFullIdentifier(object: Table | Column, append: string = ): string;
    getPrimaryKeyName(table: Table): string;
    getDropPrimaryKeyDDL(table: Table);
    getAddPrimaryKeyDDL(table: Table);
    getBeginDDL(): string;
    getEndDDL(): string;
    getAddTablesDDL(database: DatabaseModel): string[];
    getAddSchemasDDL(database: DatabaseModel): string;
    getAddSchemaDDL(schemaName: string): string;
    getUseSchemaDDL(table: Table);
    getResetSchemaDDL(table: Table): string;
    getRenameTableDDL(from: Table, to: Table): string;
    supportsAggregatedAlterTable(): boolean;
    getModifyTableDDL(diff: TableDiff, options: MigrateOptions): string[];
    getAddTableDDL(table: Table, withForeignKey: boolean = true): string[];
    getCreateTableDDL(table: Table, withForeignKey: boolean = true): string;
    getAddForeignKeysDDL(table: Table): string[];
    getAddIndicesDDL(table: Table): string[];
    getAddForeignKeyDDL(foreignKey: ForeignKey): string;
    getForeignKeyDDL(foreignKey: ForeignKey): string;
    getAddIndexDDL(index: IndexModel): string;
    getDropTableDDL(table: Table): string;
    getRemoveColumnDDL(column: Column): string;
    getRenameColumnDDL(from: Column, to: Column): string;
    getModifyColumnDDL(diff: ColumnDiff): string;
    getAddColumnDDL(column: Column);
    getDropForeignKeyDDL(foreignKey: ForeignKey): string;
    getDropIndexDDL(index: IndexModel): string;
    getUniqueDDL(unique: IndexModel): string;
    getColumnDDL(column: Column);
    getColumnDefaultValueDDL(column: Column);
    getDefaultExpression(column: Column): string;
    getAutoIncrement();
    getNotNullString();
    getNullString();
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/platform/default-platform.ts#L141

### getPreparedEntity (function)

```typescript
(adapter: PreparedAdapter, entity: ReflectionClass<any>): PreparedEntity
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/prepare.ts#L48

### getDeepTypeCaster (function)

```typescript
(entity: PreparedEntity, path: string): SqlTypeCast
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/prepare.ts#L95

### SqlTypeCast (type)

```typescript
type SqlTypeCast = (placeholder: string) => string;
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/prepare.ts#L5

### PreparedField (type)

```typescript
interface PreparedField {
    type: Type;
    name: string; // actual name from property
    columnName: string; // after naming strategy
    optional: boolean;

    json: boolean;
    autoIncrement: boolean;

    columnNameEscaped: string; // .e.g `{column}`
    columnEscapedWithTable: string; // .e.g `user`.`{column}`
    sqlTypeCast: SqlTypeCast;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/prepare.ts#L7

### CachedSelect (type)

The SQL of a query, and how to convert the values of its filter to the parameters.

```typescript
interface CachedSelect {
    sql: string;
    binders: ((value: any) => any)[];
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/prepare.ts#L22

### PreparedEntity (type)

```typescript
interface PreparedEntity {
    /** the SQL of queries that differ only in the values of their filter */
    selectCache?: LruCache<CachedSelect>;
    platform: DefaultPlatform,
    type: TypeClass | TypeObjectLiteral;
    name: string;
    tableName: string;
    tableNameEscaped: string; // .e.g `{table}`

    primaryKey: PreparedField;
    fieldMap: { [name: string]: PreparedField };
    fields: PreparedField[];
    sqlTypeCaster: { [path: string]: SqlTypeCast };
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/prepare.ts#L27

### PreparedAdapter (type)

```typescript
interface PreparedAdapter {
    getName(): string;
    platform: DefaultPlatform;
    preparedEntities: Map<ReflectionClass<any>, PreparedEntity>;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/prepare.ts#L42

### isDirectPropertyOfEntity (function)

Only direct properties of an entity will be serialized in some special way.
Deeper types get the normal JSON serialization.

```typescript
(state: TemplateState): boolean
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/serializer/sql-serializer.ts#L46

### uuid4Binary (function)

```typescript
(u: any): Buffer
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/serializer/sql-serializer.ts#L309

### uuid4Stringify (function)

```typescript
(buffer: Buffer): string
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/serializer/sql-serializer.ts#L313

### hexTable (variable)

```typescript
string[]
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/serializer/sql-serializer.ts#L37

### SqlSerializer (class)

```typescript
export class SqlSerializer extends Serializer {
    name;
    override setExplicitUndefined(type: Type, state: TemplateState): boolean;
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/serializer/sql-serializer.ts#L209

### sqlSerializer (variable)

```typescript
Serializer
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/sql/src/serializer/sql-serializer.ts#L307
