github
DocsBlog
fontcolor_theme
package

API @deepkit/mysql

npm install @deepkit/mysql
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);

Classes

MySQLStatement [source]
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();
}
MySQLConnection [source]
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>;
}
MySQLDatabaseTransaction [source]
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();
}
MySQLConnectionPool [source]
export class MySQLConnectionPool extends SQLConnectionPool {
    constructor(protected pool: Pool, protected logger: Logger, protected stopwatch?: Stopwatch);
    async getConnection(transaction?: MySQLDatabaseTransaction): Promise<MySQLConnection>;
    release(connection: MySQLConnection);
}
MySQLPersistence [source]
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>;
}
MySQLQueryResolver [source]
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>;
}
MySQLDatabaseQuery [source]
export class MySQLDatabaseQuery<T extends OrmEntity> extends SQLDatabaseQuery<T> {
}
MySQLDatabaseQueryFactory [source]
export class MySQLDatabaseQueryFactory extends SQLDatabaseQueryFactory {
    createQuery<T extends OrmEntity>(type?: ReceiveType<T> | ClassType<T> | AbstractClassType<T> | ReflectionClass<T>): MySQLDatabaseQuery<T>;
}
MySQLDatabaseAdapter [source]
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;
}
MySQLPlatform [source]
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;
}
MysqlSchemaParser [source]
export class MysqlSchemaParser extends SchemaParser {
    defaultSchema;
    async parse(database: DatabaseModel, limitTableNames?: string[]);
}

Const

mySqlSerializer [source]
MySQLSerializer

Functions

parseConnectionString [source]
(url: string): PoolConfig
mysqlJsonTypeCaster [source]
(placeholder: string): string

Types

TransactionTypes [source]
type TransactionTypes = 'REPEATABLE READ' | 'READ UNCOMMITTED' | 'READ COMMITTED' | 'SERIALIZABLE';