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
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();
}
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>;
}
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();
}
export class MySQLConnectionPool extends SQLConnectionPool {
constructor(protected pool: Pool, protected logger: Logger, protected stopwatch?: Stopwatch);
async getConnection(transaction?: MySQLDatabaseTransaction): Promise<MySQLConnection>;
release(connection: MySQLConnection);
}
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>;
}
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>;
}
export class MySQLDatabaseQuery<T extends OrmEntity> extends SQLDatabaseQuery<T> {
}
export class MySQLDatabaseQueryFactory extends SQLDatabaseQueryFactory {
createQuery<T extends OrmEntity>(type?: ReceiveType<T> | ClassType<T> | AbstractClassType<T> | ReflectionClass<T>): MySQLDatabaseQuery<T>;
}
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;
}
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;
}
export class MysqlSchemaParser extends SchemaParser {
defaultSchema;
async parse(database: DatabaseModel, limitTableNames?: string[]);
}
Const
MySQLSerializer
Functions
(url: string): PoolConfig
(placeholder: string): string
Types
type TransactionTypes = 'REPEATABLE READ' | 'READ UNCOMMITTED' | 'READ COMMITTED' | 'SERIALIZABLE';