# API `@deepkit/mysql`

```shell
npm install @deepkit/mysql
```

```typescript
import { MySQLDatabaseAdapter } from '@deepkit/mysql';
import { Database } from '@deepkit/orm';

const adapter = new PostgresDatabaseAdapter('mysql://user:password@localhost/mydatabase');
// const adapter = new MySQLDatabaseAdapter({host: 'localhost', port: 3306});

const database = new Database(adapter);
```

## API reference of @deepkit/mysql

### parseConnectionString (function)

```typescript
(url: string): PoolConfig
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/mysql/src/config.ts#L52

### MySQLStatement (class)

```typescript
export class MySQLStatement extends SQLStatement {
    constructor(protected logger: Logger, protected sql: string, protected connection: PoolConnection, protected stopwatch?: Stopwatch);
    async get(params: any[] = []);
    async all(params: any[] = []);
    release();
}
```

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

### MySQLConnection (class)

```typescript
export class MySQLConnection extends SQLConnection {
    lastExecResult?: UpsertResult[];
    constructor(public connection: PoolConnection, connectionPool: SQLConnectionPool, logger: Logger, transaction?: DatabaseTransaction, stopwatch?: Stopwatch);
    async prepare(sql: string);
    async run(sql: string, params: any[] = []);
    async getChanges(): Promise<number>;
}
```

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

### TransactionTypes (type)

```typescript
type TransactionTypes = 'REPEATABLE READ' | 'READ UNCOMMITTED' | 'READ COMMITTED' | 'SERIALIZABLE';
```

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

### MySQLDatabaseTransaction (class)

```typescript
export class MySQLDatabaseTransaction extends DatabaseTransaction {
    connection?: MySQLConnection;
    setTransaction?: TransactionTypes;
    /**
     * This is the default for mysql databases.
     */
    repeatableRead(): this;
    readUncommitted(): this;
    readCommitted(): this;
    serializable(): this;
    async begin();
    async commit();
    async rollback();
}
```

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

### MySQLConnectionPool (class)

```typescript
export class MySQLConnectionPool extends SQLConnectionPool {
    constructor(protected pool: Pool, protected logger: Logger, protected stopwatch?: Stopwatch);
    async getConnection(transaction?: MySQLDatabaseTransaction): Promise<MySQLConnection>;
    release(connection: MySQLConnection);
}
```

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

### MySQLPersistence (class)

```typescript
export class MySQLPersistence extends SQLPersistence {
    constructor(protected platform: DefaultPlatform, public connectionPool: MySQLConnectionPool, session: DatabaseSession<any>);
    override handleSpecificError(error: Error): Error;
    async batchUpdate<T extends OrmEntity>(entity: PreparedEntity, changeSets: DatabasePersistenceChangeSet<T>[]): Promise<void>;
}
```

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

### MySQLQueryResolver (class)

```typescript
export class MySQLQueryResolver<T extends OrmEntity> extends SQLQueryResolver<T> {
    override handleSpecificError(error: Error): Error;
    async delete(model: SQLQueryModel<T>, deleteResult: DeleteResult<T>): Promise<void>;
    async patch(model: SQLQueryModel<T>, changes: Changes<T>, patchResult: PatchResult<T>): Promise<void>;
}
```

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

### MySQLDatabaseQuery (class)

```typescript
export class MySQLDatabaseQuery<T extends OrmEntity> extends SQLDatabaseQuery<T> {
}
```

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

### MySQLDatabaseQueryFactory (class)

```typescript
export class MySQLDatabaseQueryFactory extends SQLDatabaseQueryFactory {
    createQuery<T extends OrmEntity>(type?: ReceiveType<T> | ClassType<T> | AbstractClassType<T> | ReflectionClass<T>): MySQLDatabaseQuery<T>;
}
```

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

### MySQLDatabaseAdapter (class)

```typescript
export class MySQLDatabaseAdapter extends SQLDatabaseAdapter {
    connectionPool: MySQLConnectionPool;
    platform: MySQLPlatform;
    constructor(options: PoolConfig | string = {}, additional: Partial<PoolConfig> = {});
    setLogger(logger: Logger);
    getName(): string;
    getSchemaName(): string;
    createPersistence(session: DatabaseSession<any>): SQLPersistence;
    createTransaction(session: DatabaseSession<this>): MySQLDatabaseTransaction;
    queryFactory(databaseSession: DatabaseSession<any>): MySQLDatabaseQueryFactory;
    disconnect(force?: boolean): void;
}
```

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

### mysqlJsonTypeCaster (function)

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

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

### MySQLPlatform (class)

```typescript
export class MySQLPlatform extends DefaultPlatform {
    override annotationId;
    override schemaParserType;
    override readonly serializer: Serializer;
    constructor(protected pool: Pool);
    override createSqlFilterBuilder(adapter: PreparedAdapter, schema: ReflectionClass<any>, tableName: string): MySQLSQLFilterBuilder;
    override getSqlTypeCaster(type: Type): (placeholder: string) => string;
    supportsSelectFor(): boolean;
    /**
     * MySQL can compare SQL values with JSON values directly.
     */
    deepColumnAccessorRequiresJsonString(): boolean;
    getDropIndexDDL(index: IndexModel): string;
    getColumnDDL(column: Column);
    quoteValue(value: any): string;
    quoteIdentifier(id: string): string;
    getAutoIncrement();
    getBeginDDL(): string;
    getEndDDL(): string;
}
```

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

### MysqlSchemaParser (class)

```typescript
export class MysqlSchemaParser extends SchemaParser {
    defaultSchema;
    async parse(database: DatabaseModel, limitTableNames?: string[]);
}
```

Source: https://github.com/deepkit/deepkit-framework/blob/master/packages/mysql/src/mysql-schema-parser.ts#L14

### mySqlSerializer (variable)

```typescript
MySQLSerializer
```

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