UNPKG

godot-sqlite-kysely

Version:

Kysely dialect for godot-sqlite. Adds SQLite support to Godot/GodotJS.

54 lines (53 loc) 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GodotSQLiteKyselySyncConnection = void 0; const godot_lib_api_1 = require("godot.lib.api"); const utils_1 = require("./utils"); class GodotSQLiteKyselySyncConnection { #sqlite; #nestedTransactionIndex = 0; constructor(sqlite) { this.#sqlite = sqlite; } async executeQuery(compiledQuery) { const sqlite = this.#sqlite; if (!sqlite.query_with_bindings(compiledQuery.sql, godot_lib_api_1.GArray.create(compiledQuery.parameters))) { throw new Error(sqlite.error_message); } return { insertId: compiledQuery.query.kind === 'InsertQueryNode' ? BigInt(sqlite.last_insert_rowid) : undefined, rows: (0, utils_1.getResultRows)(sqlite), }; } streamQuery(_compiledQuery, _chunkSize) { throw new Error('Streaming is not supported with SQLite3'); } async close() { this.#sqlite.close_db(); } async beginTransaction() { const savepointName = `sp${this.#nestedTransactionIndex++}`; if (!this.#sqlite.query(`savepoint ${savepointName}`)) { throw new Error(`beginTransaction (${savepointName}) failed: ${this.#sqlite.error_message}`); } } async commitTransaction() { if (this.#nestedTransactionIndex <= 0) { throw new Error('No transactions in progress'); } const savepointName = `sp${--this.#nestedTransactionIndex}`; if (!this.#sqlite.query(`release savepoint ${savepointName}`)) { throw new Error(`commitTransaction (${savepointName}) failed: ${this.#sqlite.error_message}`); } } async rollbackTransaction() { if (this.#nestedTransactionIndex <= 0) { throw new Error('No transactions in progress'); } const savepointName = `sp${--this.#nestedTransactionIndex}`; if (!this.#sqlite.query(`rollback to savepoint ${savepointName}`)) { throw new Error(`commitTransaction (${savepointName}) failed: ${this.#sqlite.error_message}`); } } } exports.GodotSQLiteKyselySyncConnection = GodotSQLiteKyselySyncConnection;