61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
import { entityKind } from "../entity.js";
|
|
import { TransactionRollbackError } from "../errors.js";
|
|
import { sql } from "../sql/sql.js";
|
|
import { MySqlDatabase } from "./db.js";
|
|
class MySqlPreparedQuery {
|
|
static [entityKind] = "MySqlPreparedQuery";
|
|
/** @internal */
|
|
joinsNotNullableMap;
|
|
}
|
|
class MySqlSession {
|
|
constructor(dialect) {
|
|
this.dialect = dialect;
|
|
}
|
|
static [entityKind] = "MySqlSession";
|
|
execute(query) {
|
|
return this.prepareQuery(
|
|
this.dialect.sqlToQuery(query),
|
|
void 0
|
|
).execute();
|
|
}
|
|
async count(sql2) {
|
|
const res = await this.execute(sql2);
|
|
return Number(
|
|
res[0][0]["count"]
|
|
);
|
|
}
|
|
getSetTransactionSQL(config) {
|
|
const parts = [];
|
|
if (config.isolationLevel) {
|
|
parts.push(`isolation level ${config.isolationLevel}`);
|
|
}
|
|
return parts.length ? sql`set transaction ${sql.raw(parts.join(" "))}` : void 0;
|
|
}
|
|
getStartTransactionSQL(config) {
|
|
const parts = [];
|
|
if (config.withConsistentSnapshot) {
|
|
parts.push("with consistent snapshot");
|
|
}
|
|
if (config.accessMode) {
|
|
parts.push(config.accessMode);
|
|
}
|
|
return parts.length ? sql`start transaction ${sql.raw(parts.join(" "))}` : void 0;
|
|
}
|
|
}
|
|
class MySqlTransaction extends MySqlDatabase {
|
|
constructor(dialect, session, schema, nestedIndex, mode) {
|
|
super(dialect, session, schema, mode);
|
|
this.schema = schema;
|
|
this.nestedIndex = nestedIndex;
|
|
}
|
|
static [entityKind] = "MySqlTransaction";
|
|
rollback() {
|
|
throw new TransactionRollbackError();
|
|
}
|
|
}
|
|
export {
|
|
MySqlPreparedQuery,
|
|
MySqlSession,
|
|
MySqlTransaction
|
|
};
|
|
//# sourceMappingURL=session.js.map
|