2017-10-21 21:10:33 -04:00
|
|
|
"use strict";
|
|
|
|
|
2021-04-07 22:01:52 +02:00
|
|
|
/**
|
|
|
|
* @module sql
|
|
|
|
*/
|
|
|
|
|
2024-07-18 21:35:17 +03:00
|
|
|
import log from "./log.js";
|
2024-02-16 23:43:41 +02:00
|
|
|
import type { Statement, Database as DatabaseType, RunResult } from "better-sqlite3";
|
2024-07-18 21:35:17 +03:00
|
|
|
import dataDir from "./data_dir.js";
|
|
|
|
import cls from "./cls.js";
|
2024-07-18 21:37:45 +03:00
|
|
|
import fs from "fs-extra";
|
|
|
|
import Database from "better-sqlite3";
|
2024-07-18 22:33:36 +03:00
|
|
|
import ws from "./ws.js";
|
|
|
|
import becca_loader from "../becca/becca_loader.js";
|
|
|
|
import entity_changes from "./entity_changes.js";
|
2017-10-14 23:31:44 -04:00
|
|
|
|
2024-08-15 00:06:37 +03:00
|
|
|
let dbConnection: DatabaseType = buildDatabase();
|
|
|
|
let statementCache: Record<string, Statement> = {};
|
|
|
|
|
|
|
|
function buildDatabase() {
|
2024-08-09 21:51:10 +03:00
|
|
|
if (process.env.TRILIUM_INTEGRATION_TEST === "memory") {
|
2024-12-22 15:42:15 +02:00
|
|
|
return buildIntegrationTestDatabase();
|
2025-03-30 22:26:23 +03:00
|
|
|
} else if (process.env.TRILIUM_INTEGRATION_TEST === "memory-no-store") {
|
|
|
|
return new Database(":memory:");
|
2024-08-09 21:51:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return new Database(dataDir.DOCUMENT_PATH);
|
|
|
|
}
|
|
|
|
|
2025-03-02 19:39:06 +02:00
|
|
|
function buildIntegrationTestDatabase(dbPath?: string) {
|
|
|
|
const dbBuffer = fs.readFileSync(dbPath ?? dataDir.DOCUMENT_PATH);
|
2024-08-15 00:06:37 +03:00
|
|
|
return new Database(dbBuffer);
|
|
|
|
}
|
|
|
|
|
2025-03-03 20:00:52 +02:00
|
|
|
function rebuildIntegrationTestDatabase(dbPath?: string) {
|
2025-03-02 19:39:06 +02:00
|
|
|
if (dbConnection) {
|
|
|
|
dbConnection.close();
|
|
|
|
}
|
|
|
|
|
2024-08-15 00:06:37 +03:00
|
|
|
// This allows a database that is read normally but is kept in memory and discards all modifications.
|
2025-03-02 19:39:06 +02:00
|
|
|
dbConnection = buildIntegrationTestDatabase(dbPath);
|
2024-08-15 00:06:37 +03:00
|
|
|
statementCache = {};
|
|
|
|
}
|
|
|
|
|
2024-08-09 21:32:12 +03:00
|
|
|
if (!process.env.TRILIUM_INTEGRATION_TEST) {
|
2025-01-09 18:07:02 +02:00
|
|
|
dbConnection.pragma("journal_mode = WAL");
|
2024-08-09 21:32:12 +03:00
|
|
|
}
|
2017-12-03 22:29:23 -05:00
|
|
|
|
2021-12-29 23:19:05 +01:00
|
|
|
const LOG_ALL_QUERIES = false;
|
|
|
|
|
2024-02-16 22:44:12 +02:00
|
|
|
type Params = any;
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
[`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `SIGTERM`].forEach((eventType) => {
|
2020-04-14 22:15:55 +02:00
|
|
|
process.on(eventType, () => {
|
|
|
|
if (dbConnection) {
|
|
|
|
// closing connection is especially important to fold -wal file into the main DB file
|
|
|
|
// (see https://sqlite.org/tempfiles.html for details)
|
|
|
|
dbConnection.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-02-16 22:44:12 +02:00
|
|
|
function insert<T extends {}>(tableName: string, rec: T, replace = false) {
|
2023-09-19 23:48:55 +02:00
|
|
|
const keys = Object.keys(rec || {});
|
2017-10-25 22:39:21 -04:00
|
|
|
if (keys.length === 0) {
|
2022-12-21 15:19:05 +01:00
|
|
|
log.error(`Can't insert empty object into table ${tableName}`);
|
2017-10-25 22:39:21 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const columns = keys.join(", ");
|
2025-01-09 18:07:02 +02:00
|
|
|
const questionMarks = keys.map((p) => "?").join(", ");
|
2017-10-25 22:39:21 -04:00
|
|
|
|
2022-12-21 15:19:05 +01:00
|
|
|
const query = `INSERT
|
|
|
|
${replace ? "OR REPLACE" : ""} INTO
|
|
|
|
${tableName}
|
|
|
|
(
|
|
|
|
${columns}
|
|
|
|
)
|
|
|
|
VALUES (${questionMarks})`;
|
2017-10-14 23:31:44 -04:00
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
const res = execute(query, Object.values(rec));
|
2017-10-14 23:31:44 -04:00
|
|
|
|
2021-02-27 21:09:13 +01:00
|
|
|
return res ? res.lastInsertRowid : null;
|
2017-10-14 23:31:44 -04:00
|
|
|
}
|
|
|
|
|
2024-02-16 23:43:41 +02:00
|
|
|
function replace<T extends {}>(tableName: string, rec: T): number | null {
|
|
|
|
return insert(tableName, rec, true) as number | null;
|
2019-03-25 22:06:17 +01:00
|
|
|
}
|
|
|
|
|
2024-02-16 22:44:12 +02:00
|
|
|
function upsert<T extends {}>(tableName: string, primaryKey: string, rec: T) {
|
2023-09-19 23:48:55 +02:00
|
|
|
const keys = Object.keys(rec || {});
|
2019-03-25 22:06:17 +01:00
|
|
|
if (keys.length === 0) {
|
2022-12-21 15:19:05 +01:00
|
|
|
log.error(`Can't upsert empty object into table ${tableName}`);
|
2019-03-25 22:06:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const columns = keys.join(", ");
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
const questionMarks = keys.map((colName) => `@${colName}`).join(", ");
|
2019-03-25 22:06:17 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
const updateMarks = keys.map((colName) => `${colName} = @${colName}`).join(", ");
|
2019-03-25 22:06:17 +01:00
|
|
|
|
2024-12-22 15:42:15 +02:00
|
|
|
const query = `INSERT INTO ${tableName} (${columns}) VALUES (${questionMarks})
|
|
|
|
ON CONFLICT (${primaryKey}) DO UPDATE SET ${updateMarks}`;
|
2019-03-25 22:06:17 +01:00
|
|
|
|
2020-06-17 23:03:46 +02:00
|
|
|
for (const idx in rec) {
|
|
|
|
if (rec[idx] === true || rec[idx] === false) {
|
2024-02-16 22:44:12 +02:00
|
|
|
(rec as any)[idx] = rec[idx] ? 1 : 0;
|
2020-06-17 23:03:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
execute(query, rec);
|
2017-10-29 22:22:30 -04:00
|
|
|
}
|
|
|
|
|
2024-02-16 22:44:12 +02:00
|
|
|
function stmt(sql: string) {
|
2020-06-17 23:03:46 +02:00
|
|
|
if (!(sql in statementCache)) {
|
|
|
|
statementCache[sql] = dbConnection.prepare(sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
return statementCache[sql];
|
|
|
|
}
|
|
|
|
|
2024-02-16 22:44:12 +02:00
|
|
|
function getRow<T>(query: string, params: Params = []): T {
|
2025-01-09 18:07:02 +02:00
|
|
|
return wrap(query, (s) => s.get(params)) as T;
|
2017-10-14 23:31:44 -04:00
|
|
|
}
|
|
|
|
|
2024-02-16 22:44:12 +02:00
|
|
|
function getRowOrNull<T>(query: string, params: Params = []): T | null {
|
2020-06-20 12:31:38 +02:00
|
|
|
const all = getRows(query, params);
|
2024-02-16 22:44:12 +02:00
|
|
|
if (!all) {
|
|
|
|
return null;
|
|
|
|
}
|
2017-10-28 19:55:55 -04:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
return (all.length > 0 ? all[0] : null) as T | null;
|
2017-10-29 22:22:30 -04:00
|
|
|
}
|
|
|
|
|
2024-02-16 23:56:32 +02:00
|
|
|
function getValue<T>(query: string, params: Params = []): T {
|
2025-01-09 18:07:02 +02:00
|
|
|
return wrap(query, (s) => s.pluck().get(params)) as T;
|
2017-10-28 19:55:55 -04:00
|
|
|
}
|
|
|
|
|
2020-08-16 22:57:48 +02:00
|
|
|
// smaller values can result in better performance due to better usage of statement cache
|
|
|
|
const PARAM_LIMIT = 100;
|
2018-05-30 20:28:10 -04:00
|
|
|
|
2024-02-17 11:24:50 +02:00
|
|
|
function getManyRows<T>(query: string, params: Params): T[] {
|
2024-02-16 22:44:12 +02:00
|
|
|
let results: unknown[] = [];
|
2018-05-30 20:28:10 -04:00
|
|
|
|
|
|
|
while (params.length > 0) {
|
2019-05-13 20:40:00 +02:00
|
|
|
const curParams = params.slice(0, Math.min(params.length, PARAM_LIMIT));
|
2018-05-30 20:28:10 -04:00
|
|
|
params = params.slice(curParams.length);
|
|
|
|
|
2024-02-16 22:44:12 +02:00
|
|
|
const curParamsObj: Record<string, any> = {};
|
2020-06-17 23:03:46 +02:00
|
|
|
|
|
|
|
let j = 1;
|
|
|
|
for (const param of curParams) {
|
2025-01-09 18:07:02 +02:00
|
|
|
curParamsObj["param" + j++] = param;
|
2020-06-17 23:03:46 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 20:28:10 -04:00
|
|
|
let i = 1;
|
2020-06-17 23:03:46 +02:00
|
|
|
const questionMarks = curParams.map(() => ":param" + i++).join(",");
|
2018-05-30 20:28:10 -04:00
|
|
|
const curQuery = query.replace(/\?\?\?/g, questionMarks);
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
const statement = curParams.length === PARAM_LIMIT ? stmt(curQuery) : dbConnection.prepare(curQuery);
|
2020-08-16 22:57:48 +02:00
|
|
|
|
|
|
|
const subResults = statement.all(curParamsObj);
|
2020-06-20 23:24:34 +02:00
|
|
|
results = results.concat(subResults);
|
2018-05-30 20:28:10 -04:00
|
|
|
}
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
return (results as T[] | null) || [];
|
2018-05-30 20:28:10 -04:00
|
|
|
}
|
|
|
|
|
2024-02-16 23:56:32 +02:00
|
|
|
function getRows<T>(query: string, params: Params = []): T[] {
|
2025-01-09 18:07:02 +02:00
|
|
|
return wrap(query, (s) => s.all(params)) as T[];
|
2020-06-20 21:42:41 +02:00
|
|
|
}
|
|
|
|
|
2024-02-17 20:45:31 +02:00
|
|
|
function getRawRows<T extends {} | unknown[]>(query: string, params: Params = []): T[] {
|
2025-01-09 18:07:02 +02:00
|
|
|
return (wrap(query, (s) => s.raw().all(params)) as T[]) || [];
|
2021-07-24 12:04:48 +02:00
|
|
|
}
|
|
|
|
|
2024-02-18 01:01:17 +02:00
|
|
|
function iterateRows<T>(query: string, params: Params = []): IterableIterator<T> {
|
2021-12-29 23:19:05 +01:00
|
|
|
if (LOG_ALL_QUERIES) {
|
|
|
|
console.log(query);
|
|
|
|
}
|
|
|
|
|
2024-02-18 01:01:17 +02:00
|
|
|
return stmt(query).iterate(params) as IterableIterator<T>;
|
2017-10-14 23:31:44 -04:00
|
|
|
}
|
|
|
|
|
2024-02-16 22:44:12 +02:00
|
|
|
function getMap<K extends string | number | symbol, V>(query: string, params: Params = []) {
|
|
|
|
const map: Record<K, V> = {} as Record<K, V>;
|
2024-02-17 18:55:41 +02:00
|
|
|
const results = getRawRows<[K, V]>(query, params);
|
2017-11-02 22:55:22 -04:00
|
|
|
|
2024-02-16 22:44:12 +02:00
|
|
|
for (const row of results || []) {
|
2024-02-17 18:55:41 +02:00
|
|
|
map[row[0]] = row[1];
|
2017-11-02 22:55:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2024-02-16 23:56:32 +02:00
|
|
|
function getColumn<T>(query: string, params: Params = []): T[] {
|
2025-01-09 18:07:02 +02:00
|
|
|
return wrap(query, (s) => s.pluck().all(params)) as T[];
|
2017-10-24 23:14:26 -04:00
|
|
|
}
|
|
|
|
|
2024-02-16 23:43:41 +02:00
|
|
|
function execute(query: string, params: Params = []): RunResult {
|
2025-01-09 18:07:02 +02:00
|
|
|
return wrap(query, (s) => s.run(params)) as RunResult;
|
2017-10-14 23:31:44 -04:00
|
|
|
}
|
|
|
|
|
2024-02-16 22:44:12 +02:00
|
|
|
function executeMany(query: string, params: Params) {
|
2021-12-29 23:19:05 +01:00
|
|
|
if (LOG_ALL_QUERIES) {
|
|
|
|
console.log(query);
|
|
|
|
}
|
|
|
|
|
2020-07-09 23:59:27 +02:00
|
|
|
while (params.length > 0) {
|
|
|
|
const curParams = params.slice(0, Math.min(params.length, PARAM_LIMIT));
|
|
|
|
params = params.slice(curParams.length);
|
|
|
|
|
2024-02-16 22:44:12 +02:00
|
|
|
const curParamsObj: Record<string, any> = {};
|
2020-07-09 23:59:27 +02:00
|
|
|
|
|
|
|
let j = 1;
|
|
|
|
for (const param of curParams) {
|
2025-01-09 18:07:02 +02:00
|
|
|
curParamsObj["param" + j++] = param;
|
2020-07-09 23:59:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
let i = 1;
|
|
|
|
const questionMarks = curParams.map(() => ":param" + i++).join(",");
|
|
|
|
const curQuery = query.replace(/\?\?\?/g, questionMarks);
|
|
|
|
|
|
|
|
dbConnection.prepare(curQuery).run(curParamsObj);
|
|
|
|
}
|
2019-11-01 22:09:51 +01:00
|
|
|
}
|
|
|
|
|
2024-02-16 23:43:41 +02:00
|
|
|
function executeScript(query: string): DatabaseType {
|
2021-12-29 23:19:05 +01:00
|
|
|
if (LOG_ALL_QUERIES) {
|
|
|
|
console.log(query);
|
|
|
|
}
|
|
|
|
|
2020-06-20 21:42:41 +02:00
|
|
|
return dbConnection.exec(query);
|
2017-10-15 17:31:49 -04:00
|
|
|
}
|
|
|
|
|
2024-02-16 23:43:41 +02:00
|
|
|
function wrap(query: string, func: (statement: Statement) => unknown): unknown {
|
2020-06-20 21:42:41 +02:00
|
|
|
const startTimestamp = Date.now();
|
2020-08-30 22:29:38 +02:00
|
|
|
let result;
|
2020-05-03 21:27:24 +02:00
|
|
|
|
2021-12-29 23:19:05 +01:00
|
|
|
if (LOG_ALL_QUERIES) {
|
|
|
|
console.log(query);
|
|
|
|
}
|
|
|
|
|
2020-08-30 22:29:38 +02:00
|
|
|
try {
|
|
|
|
result = func(stmt(query));
|
2025-01-09 18:07:02 +02:00
|
|
|
} catch (e: any) {
|
2020-08-30 22:29:38 +02:00
|
|
|
if (e.message.includes("The database connection is not open")) {
|
|
|
|
// this often happens on killing the app which puts these alerts in front of user
|
|
|
|
// in these cases error should be simply ignored.
|
|
|
|
console.log(e.message);
|
|
|
|
|
2023-04-08 19:51:39 +08:00
|
|
|
return null;
|
2020-08-30 22:29:38 +02:00
|
|
|
}
|
2020-12-16 20:58:43 +01:00
|
|
|
|
|
|
|
throw e;
|
2020-08-30 22:29:38 +02:00
|
|
|
}
|
2017-11-21 22:11:27 -05:00
|
|
|
|
2020-06-20 21:42:41 +02:00
|
|
|
const milliseconds = Date.now() - startTimestamp;
|
2019-12-01 12:51:47 +01:00
|
|
|
|
2023-10-20 09:36:57 +02:00
|
|
|
if (milliseconds >= 20 && !cls.isSlowQueryLoggingDisabled()) {
|
2020-06-20 21:42:41 +02:00
|
|
|
if (query.includes("WITH RECURSIVE")) {
|
|
|
|
log.info(`Slow recursive query took ${milliseconds}ms.`);
|
2025-01-09 18:07:02 +02:00
|
|
|
} else {
|
2020-12-11 15:24:44 +01:00
|
|
|
log.info(`Slow query took ${milliseconds}ms: ${query.trim().replace(/\s+/g, " ")}`);
|
2020-06-20 21:42:41 +02:00
|
|
|
}
|
2017-11-01 20:31:44 -04:00
|
|
|
}
|
2017-11-18 18:57:50 -05:00
|
|
|
|
2020-06-20 21:42:41 +02:00
|
|
|
return result;
|
2017-11-01 20:31:44 -04:00
|
|
|
}
|
|
|
|
|
2024-02-16 23:43:41 +02:00
|
|
|
function transactional<T>(func: (statement: Statement) => T) {
|
2021-03-12 23:48:14 +01:00
|
|
|
try {
|
2024-02-16 22:44:12 +02:00
|
|
|
const ret = (dbConnection.transaction(func) as any).deferred();
|
2021-03-12 23:48:14 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
if (!dbConnection.inTransaction) {
|
|
|
|
// i.e. transaction was really committed (and not just savepoint released)
|
2024-07-18 22:33:36 +03:00
|
|
|
ws.sendTransactionEntityChangesToAllClients();
|
2021-03-12 23:48:14 +01:00
|
|
|
}
|
2017-10-29 18:50:28 -04:00
|
|
|
|
2025-04-09 08:34:42 +02:00
|
|
|
return ret as T;
|
2025-01-09 18:07:02 +02:00
|
|
|
} catch (e) {
|
2025-03-10 17:04:17 +02:00
|
|
|
console.warn("Got error ", e);
|
2022-06-08 22:25:00 +02:00
|
|
|
const entityChangeIds = cls.getAndClearEntityChangeIds();
|
2021-04-14 22:57:45 +02:00
|
|
|
|
2022-06-08 22:25:00 +02:00
|
|
|
if (entityChangeIds.length > 0) {
|
2021-04-16 23:00:08 +02:00
|
|
|
log.info("Transaction rollback dirtied the becca, forcing reload.");
|
2021-04-14 22:57:45 +02:00
|
|
|
|
2024-07-18 22:33:36 +03:00
|
|
|
becca_loader.load();
|
2021-04-14 22:57:45 +02:00
|
|
|
}
|
2017-10-31 00:15:49 -04:00
|
|
|
|
2023-01-24 09:35:00 +01:00
|
|
|
// the maxEntityChangeId has been incremented during failed transaction, need to recalculate
|
2024-07-18 22:33:36 +03:00
|
|
|
entity_changes.recalculateMaxEntityChangeId();
|
2023-01-24 09:35:00 +01:00
|
|
|
|
2021-03-12 23:48:14 +01:00
|
|
|
throw e;
|
|
|
|
}
|
2017-10-29 18:50:28 -04:00
|
|
|
}
|
|
|
|
|
2024-04-06 21:55:27 +03:00
|
|
|
function fillParamList(paramIds: string[] | Set<string>, truncate = true) {
|
|
|
|
if ("length" in paramIds && paramIds.length === 0) {
|
2020-12-10 21:27:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (truncate) {
|
|
|
|
execute("DELETE FROM param_list");
|
|
|
|
}
|
|
|
|
|
2021-03-14 22:54:39 +01:00
|
|
|
paramIds = Array.from(new Set(paramIds));
|
2020-12-10 21:27:21 +01:00
|
|
|
|
2021-03-14 22:54:39 +01:00
|
|
|
if (paramIds.length > 30000) {
|
|
|
|
fillParamList(paramIds.slice(30000), false);
|
2020-12-10 21:27:21 +01:00
|
|
|
|
2021-03-14 22:54:39 +01:00
|
|
|
paramIds = paramIds.slice(0, 30000);
|
2020-12-10 21:27:21 +01:00
|
|
|
}
|
|
|
|
|
2024-08-15 00:06:37 +03:00
|
|
|
// doing it manually to avoid this showing up on the slow query list
|
2025-01-09 18:07:02 +02:00
|
|
|
const s = stmt(`INSERT INTO param_list VALUES ${paramIds.map((paramId) => `(?)`).join(",")}`);
|
2020-12-10 21:27:21 +01:00
|
|
|
|
2021-03-14 22:54:39 +01:00
|
|
|
s.run(paramIds);
|
2020-12-10 21:27:21 +01:00
|
|
|
}
|
|
|
|
|
2024-02-16 22:44:12 +02:00
|
|
|
async function copyDatabase(targetFilePath: string) {
|
2022-01-17 23:47:26 +01:00
|
|
|
try {
|
|
|
|
fs.unlinkSync(targetFilePath);
|
2025-01-09 18:07:02 +02:00
|
|
|
} catch (e) {} // unlink throws exception if the file did not exist
|
2022-01-17 23:47:26 +01:00
|
|
|
|
|
|
|
await dbConnection.backup(targetFilePath);
|
|
|
|
}
|
|
|
|
|
2024-02-16 22:44:12 +02:00
|
|
|
function disableSlowQueryLogging<T>(cb: () => T) {
|
2023-10-20 09:36:57 +02:00
|
|
|
const orig = cls.isSlowQueryLoggingDisabled();
|
|
|
|
|
|
|
|
try {
|
|
|
|
cls.disableSlowQueryLogging(true);
|
|
|
|
|
|
|
|
return cb();
|
2025-01-09 18:07:02 +02:00
|
|
|
} finally {
|
2023-10-20 09:36:57 +02:00
|
|
|
cls.disableSlowQueryLogging(orig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-18 21:47:30 +03:00
|
|
|
export default {
|
2020-06-20 23:09:34 +02:00
|
|
|
dbConnection,
|
2017-10-14 23:31:44 -04:00
|
|
|
insert,
|
2017-10-29 22:22:30 -04:00
|
|
|
replace,
|
2021-04-07 22:01:52 +02:00
|
|
|
|
|
|
|
/**
|
2025-01-09 18:07:02 +02:00
|
|
|
* Get single value from the given query - first column from first returned row.
|
|
|
|
*
|
|
|
|
* @param query - SQL query with ? used as parameter placeholder
|
|
|
|
* @param params - array of params if needed
|
|
|
|
* @returns single value
|
|
|
|
*/
|
2018-01-29 17:41:59 -05:00
|
|
|
getValue,
|
2021-04-07 22:01:52 +02:00
|
|
|
|
|
|
|
/**
|
2025-01-09 18:07:02 +02:00
|
|
|
* Get first returned row.
|
|
|
|
*
|
|
|
|
* @param query - SQL query with ? used as parameter placeholder
|
|
|
|
* @param params - array of params if needed
|
|
|
|
* @returns - map of column name to column value
|
|
|
|
*/
|
2018-01-29 17:41:59 -05:00
|
|
|
getRow,
|
|
|
|
getRowOrNull,
|
2021-04-07 22:01:52 +02:00
|
|
|
|
|
|
|
/**
|
2025-01-09 18:07:02 +02:00
|
|
|
* Get all returned rows.
|
|
|
|
*
|
|
|
|
* @param query - SQL query with ? used as parameter placeholder
|
|
|
|
* @param params - array of params if needed
|
|
|
|
* @returns - array of all rows, each row is a map of column name to column value
|
|
|
|
*/
|
2018-01-29 17:41:59 -05:00
|
|
|
getRows,
|
2021-07-24 12:04:48 +02:00
|
|
|
getRawRows,
|
2020-06-20 21:42:41 +02:00
|
|
|
iterateRows,
|
2018-05-30 20:28:10 -04:00
|
|
|
getManyRows,
|
2021-04-07 22:01:52 +02:00
|
|
|
|
|
|
|
/**
|
2025-01-09 18:07:02 +02:00
|
|
|
* Get a map of first column mapping to second column.
|
|
|
|
*
|
|
|
|
* @param query - SQL query with ? used as parameter placeholder
|
|
|
|
* @param params - array of params if needed
|
|
|
|
* @returns - map of first column to second column
|
|
|
|
*/
|
2017-11-02 22:55:22 -04:00
|
|
|
getMap,
|
2021-04-07 22:01:52 +02:00
|
|
|
|
|
|
|
/**
|
2025-01-09 18:07:02 +02:00
|
|
|
* Get a first column in an array.
|
|
|
|
*
|
|
|
|
* @param query - SQL query with ? used as parameter placeholder
|
|
|
|
* @param params - array of params if needed
|
|
|
|
* @returns array of first column of all returned rows
|
|
|
|
*/
|
2018-01-29 17:41:59 -05:00
|
|
|
getColumn,
|
2021-04-07 22:01:52 +02:00
|
|
|
|
|
|
|
/**
|
2025-01-09 18:07:02 +02:00
|
|
|
* Execute SQL
|
|
|
|
*
|
|
|
|
* @param query - SQL query with ? used as parameter placeholder
|
|
|
|
* @param params - array of params if needed
|
|
|
|
*/
|
2017-10-14 23:31:44 -04:00
|
|
|
execute,
|
2019-11-01 22:09:51 +01:00
|
|
|
executeMany,
|
2017-10-15 17:31:49 -04:00
|
|
|
executeScript,
|
2019-03-25 22:06:17 +01:00
|
|
|
transactional,
|
2020-12-10 21:27:21 +01:00
|
|
|
upsert,
|
2022-01-17 23:47:26 +01:00
|
|
|
fillParamList,
|
2023-10-20 09:36:57 +02:00
|
|
|
copyDatabase,
|
2024-08-15 00:06:37 +03:00
|
|
|
disableSlowQueryLogging,
|
|
|
|
rebuildIntegrationTestDatabase
|
2020-05-12 13:40:42 +02:00
|
|
|
};
|