122 lines
3.4 KiB
JavaScript
122 lines
3.4 KiB
JavaScript
import { entityKind } from "../entity.js";
|
|
import { DrizzleError, TransactionRollbackError } from "../errors.js";
|
|
import { QueryPromise } from "../query-promise.js";
|
|
import { BaseSQLiteDatabase } from "./db.js";
|
|
class ExecuteResultSync extends QueryPromise {
|
|
constructor(resultCb) {
|
|
super();
|
|
this.resultCb = resultCb;
|
|
}
|
|
static [entityKind] = "ExecuteResultSync";
|
|
async execute() {
|
|
return this.resultCb();
|
|
}
|
|
sync() {
|
|
return this.resultCb();
|
|
}
|
|
}
|
|
class SQLitePreparedQuery {
|
|
constructor(mode, executeMethod, query) {
|
|
this.mode = mode;
|
|
this.executeMethod = executeMethod;
|
|
this.query = query;
|
|
}
|
|
static [entityKind] = "PreparedQuery";
|
|
/** @internal */
|
|
joinsNotNullableMap;
|
|
getQuery() {
|
|
return this.query;
|
|
}
|
|
mapRunResult(result, _isFromBatch) {
|
|
return result;
|
|
}
|
|
mapAllResult(_result, _isFromBatch) {
|
|
throw new Error("Not implemented");
|
|
}
|
|
mapGetResult(_result, _isFromBatch) {
|
|
throw new Error("Not implemented");
|
|
}
|
|
execute(placeholderValues) {
|
|
if (this.mode === "async") {
|
|
return this[this.executeMethod](placeholderValues);
|
|
}
|
|
return new ExecuteResultSync(() => this[this.executeMethod](placeholderValues));
|
|
}
|
|
mapResult(response, isFromBatch) {
|
|
switch (this.executeMethod) {
|
|
case "run": {
|
|
return this.mapRunResult(response, isFromBatch);
|
|
}
|
|
case "all": {
|
|
return this.mapAllResult(response, isFromBatch);
|
|
}
|
|
case "get": {
|
|
return this.mapGetResult(response, isFromBatch);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
class SQLiteSession {
|
|
constructor(dialect) {
|
|
this.dialect = dialect;
|
|
}
|
|
static [entityKind] = "SQLiteSession";
|
|
prepareOneTimeQuery(query, fields, executeMethod, isResponseInArrayMode) {
|
|
return this.prepareQuery(query, fields, executeMethod, isResponseInArrayMode);
|
|
}
|
|
run(query) {
|
|
const staticQuery = this.dialect.sqlToQuery(query);
|
|
try {
|
|
return this.prepareOneTimeQuery(staticQuery, void 0, "run", false).run();
|
|
} catch (err) {
|
|
throw new DrizzleError({ cause: err, message: `Failed to run the query '${staticQuery.sql}'` });
|
|
}
|
|
}
|
|
/** @internal */
|
|
extractRawRunValueFromBatchResult(result) {
|
|
return result;
|
|
}
|
|
all(query) {
|
|
return this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).all();
|
|
}
|
|
/** @internal */
|
|
extractRawAllValueFromBatchResult(_result) {
|
|
throw new Error("Not implemented");
|
|
}
|
|
get(query) {
|
|
return this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).get();
|
|
}
|
|
/** @internal */
|
|
extractRawGetValueFromBatchResult(_result) {
|
|
throw new Error("Not implemented");
|
|
}
|
|
values(query) {
|
|
return this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).values();
|
|
}
|
|
async count(sql) {
|
|
const result = await this.values(sql);
|
|
return result[0][0];
|
|
}
|
|
/** @internal */
|
|
extractRawValuesValueFromBatchResult(_result) {
|
|
throw new Error("Not implemented");
|
|
}
|
|
}
|
|
class SQLiteTransaction extends BaseSQLiteDatabase {
|
|
constructor(resultType, dialect, session, schema, nestedIndex = 0) {
|
|
super(resultType, dialect, session, schema);
|
|
this.schema = schema;
|
|
this.nestedIndex = nestedIndex;
|
|
}
|
|
static [entityKind] = "SQLiteTransaction";
|
|
rollback() {
|
|
throw new TransactionRollbackError();
|
|
}
|
|
}
|
|
export {
|
|
ExecuteResultSync,
|
|
SQLitePreparedQuery,
|
|
SQLiteSession,
|
|
SQLiteTransaction
|
|
};
|
|
//# sourceMappingURL=session.js.map
|