sqlite-electron
Advanced tools
Comparing version 2.2.5 to 2.2.8
@@ -1,19 +0,1 @@ | ||
/* | ||
sqlite-electron CJS for sqlite-electron module | ||
Copyright (C) 2022-2023 Motagamwala Taha Arif Ali | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
"use strict"; | ||
@@ -30,8 +12,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function () { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g; | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -57,2 +39,9 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
}; | ||
var __asyncValues = (this && this.__asyncValues) || function (o) { | ||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
var m = o[Symbol.asyncIterator], i; | ||
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); | ||
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } | ||
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } | ||
}; | ||
exports.__esModule = true; | ||
@@ -62,21 +51,19 @@ exports.executeScript = exports.executeMany = exports.executeQuery = exports.setdbPath = void 0; | ||
var path_1 = require("path"); | ||
(function () { | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
var error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4, Promise.resolve().then(function () { return require("electron"); })]; | ||
case 1: | ||
_a.sent(); | ||
return [3, 3]; | ||
case 2: | ||
error_1 = _a.sent(); | ||
return [3, 3]; | ||
case 3: return [2]; | ||
} | ||
}); | ||
(function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4, Promise.resolve().then(function () { return require("electron"); })]; | ||
case 1: | ||
_a.sent(); | ||
return [3, 3]; | ||
case 2: | ||
error_1 = _a.sent(); | ||
return [3, 3]; | ||
case 3: return [2]; | ||
} | ||
}); | ||
}); | ||
}); }); | ||
var sqlite = null; | ||
@@ -104,127 +91,324 @@ var electronNodeDetection = function (path) { | ||
}; | ||
var exitHandler = function (options) { | ||
if (options.cleanup) { | ||
if (process.platform === "win32") { | ||
(0, child_process_1.exec)("taskkill /F /T /IM sqlite-win32-".concat(process.arch, ".exe")); | ||
} | ||
else if (process.platform === "linux") { | ||
(0, child_process_1.exec)("killall -e sqlite-linux-".concat(process.arch)); | ||
} | ||
var exitHandler = function () { | ||
if (sqlite !== null) { | ||
sqlite.kill(); | ||
} | ||
if (options.exit) | ||
process.exit(); | ||
}; | ||
var setdbPath = function (path) { | ||
var dbPath = ""; | ||
if (path === ":memory:") { | ||
dbPath = path; | ||
} | ||
else { | ||
dbPath = electronNodeDetection(path); | ||
} | ||
if (sqlite === null) { | ||
var sqlitePath = ""; | ||
if (process.platform === "win32") { | ||
sqlitePath = (0, path_1.join)(__dirname, "..", "sqlite-".concat(process.platform, "-").concat(process.arch, ".exe")); | ||
} | ||
else { | ||
sqlitePath = (0, path_1.join)(__dirname, "..", "sqlite-".concat(process.platform, "-").concat(process.arch)); | ||
} | ||
sqlite = (0, child_process_1.execFile)(sqlitePath); | ||
if (sqlite !== null) { | ||
process.on("exit", exitHandler.bind(null, { cleanup: true, exit: true })); | ||
process.on("SIGINT", exitHandler.bind(null, { cleanup: true, exit: true })); | ||
process.on("SIGUSR1", exitHandler.bind(null, { cleanup: true, exit: true })); | ||
process.on("SIGUSR2", exitHandler.bind(null, { cleanup: true, exit: true })); | ||
process.on("uncaughtException", function (err) { | ||
console.error(err, "Uncaught Exception thrown"); | ||
exitHandler.bind(null, { cleanup: true, exit: false }); | ||
}); | ||
} | ||
} | ||
return new Promise(function (resolve, reject) { | ||
try { | ||
if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) { | ||
return reject("Sqlite not defined"); | ||
} | ||
var string_1 = ""; | ||
sqlite.stdin.write("".concat(JSON.stringify(["newConnection", dbPath]), "\n")); | ||
sqlite.stdout.on("data", function (data) { | ||
string_1 += data.toString(); | ||
if (string_1.substring(string_1.length - 3) === "EOF") { | ||
if (JSON.parse(string_1.split("EOF")[0]) === true) { | ||
resolve(true); | ||
var setdbPath = function (path) { return __awaiter(void 0, void 0, void 0, function () { | ||
var dbPath, sqlitePath, string, _a, _b, _c, chunk, e_1_1; | ||
var _d, e_1, _e, _f; | ||
return __generator(this, function (_g) { | ||
switch (_g.label) { | ||
case 0: | ||
dbPath = ""; | ||
if (path === ":memory:") { | ||
dbPath = path; | ||
} | ||
else { | ||
dbPath = electronNodeDetection(path); | ||
} | ||
if (sqlite === null) { | ||
sqlitePath = ""; | ||
if (process.platform === "win32") { | ||
sqlitePath = (0, path_1.join)(__dirname, "..", "sqlite-".concat(process.platform, "-").concat(process.arch), "sqlite-".concat(process.platform, "-").concat(process.arch, ".exe")); | ||
} | ||
reject(JSON.parse(string_1.split("EOF")[0])); | ||
else { | ||
sqlitePath = (0, path_1.join)(__dirname, "..", "sqlite-".concat(process.platform, "-").concat(process.arch), "sqlite-".concat(process.platform, "-").concat(process.arch)); | ||
} | ||
sqlite = (0, child_process_1.execFile)(sqlitePath); | ||
if (sqlite !== null) { | ||
process.on("exit", exitHandler.bind(null)); | ||
process.on("SIGINT", exitHandler.bind(null)); | ||
process.on("SIGUSR1", exitHandler.bind(null)); | ||
process.on("SIGUSR2", exitHandler.bind(null)); | ||
process.on("uncaughtException", function () { | ||
exitHandler.bind(null); | ||
}); | ||
} | ||
} | ||
}); | ||
if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) { | ||
throw "Sqlite not defined"; | ||
} | ||
string = ""; | ||
sqlite.stdin.write("".concat(JSON.stringify(["newConnection", dbPath]), "\n")); | ||
_g.label = 1; | ||
case 1: | ||
_g.trys.push([1, 6, 7, 12]); | ||
_a = true, _b = __asyncValues(sqlite.stdout); | ||
_g.label = 2; | ||
case 2: return [4, _b.next()]; | ||
case 3: | ||
if (!(_c = _g.sent(), _d = _c.done, !_d)) return [3, 5]; | ||
_f = _c.value; | ||
_a = false; | ||
try { | ||
chunk = _f; | ||
string += chunk; | ||
if (string.substring(string.length - 3) === "EOF") { | ||
return [3, 5]; | ||
} | ||
} | ||
finally { | ||
_a = true; | ||
} | ||
_g.label = 4; | ||
case 4: return [3, 2]; | ||
case 5: return [3, 12]; | ||
case 6: | ||
e_1_1 = _g.sent(); | ||
e_1 = { error: e_1_1 }; | ||
return [3, 12]; | ||
case 7: | ||
_g.trys.push([7, , 10, 11]); | ||
if (!(!_a && !_d && (_e = _b["return"]))) return [3, 9]; | ||
return [4, _e.call(_b)]; | ||
case 8: | ||
_g.sent(); | ||
_g.label = 9; | ||
case 9: return [3, 11]; | ||
case 10: | ||
if (e_1) throw e_1.error; | ||
return [7]; | ||
case 11: return [7]; | ||
case 12: | ||
if (JSON.parse(string.split("EOF")[0]) === true) { | ||
return [2, true]; | ||
} | ||
throw JSON.parse(string.split("EOF")[0]); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
}; | ||
}); }; | ||
exports.setdbPath = setdbPath; | ||
var executeQuery = function (Query, fetch, values) { | ||
return new Promise(function (resolve, reject) { | ||
try { | ||
if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) { | ||
return reject("Sqlite not defined"); | ||
if (fetch === void 0) { fetch = ""; } | ||
if (values === void 0) { values = []; } | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
var string, l, i, _a, _b, _c, chunk, e_2_1, d, i, de, i_1, element, i, element; | ||
var _d, e_2, _e, _f; | ||
return __generator(this, function (_g) { | ||
switch (_g.label) { | ||
case 0: | ||
if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) { | ||
throw "Sqlite not defined"; | ||
} | ||
string = ""; | ||
if (values !== undefined) { | ||
l = values.length; | ||
for (i = 0; i < l; i++) { | ||
if (!Buffer.isBuffer(values[i])) { | ||
continue; | ||
} | ||
values[i] = JSON.stringify(values[i]); | ||
} | ||
} | ||
sqlite.stdin.write("".concat(JSON.stringify(["executeQuery", Query, fetch, values]), "\n")); | ||
_g.label = 1; | ||
case 1: | ||
_g.trys.push([1, 6, 7, 12]); | ||
_a = true, _b = __asyncValues(sqlite.stdout); | ||
_g.label = 2; | ||
case 2: return [4, _b.next()]; | ||
case 3: | ||
if (!(_c = _g.sent(), _d = _c.done, !_d)) return [3, 5]; | ||
_f = _c.value; | ||
_a = false; | ||
try { | ||
chunk = _f; | ||
string += chunk; | ||
if (string.substring(string.length - 3) === "EOF") { | ||
return [3, 5]; | ||
} | ||
} | ||
finally { | ||
_a = true; | ||
} | ||
_g.label = 4; | ||
case 4: return [3, 2]; | ||
case 5: return [3, 12]; | ||
case 6: | ||
e_2_1 = _g.sent(); | ||
e_2 = { error: e_2_1 }; | ||
return [3, 12]; | ||
case 7: | ||
_g.trys.push([7, , 10, 11]); | ||
if (!(!_a && !_d && (_e = _b["return"]))) return [3, 9]; | ||
return [4, _e.call(_b)]; | ||
case 8: | ||
_g.sent(); | ||
_g.label = 9; | ||
case 9: return [3, 11]; | ||
case 10: | ||
if (e_2) throw e_2.error; | ||
return [7]; | ||
case 11: return [7]; | ||
case 12: | ||
d = JSON.parse(string.split("EOF")[0]); | ||
if (typeof d !== "boolean") { | ||
if (Array.isArray(d[0])) { | ||
for (i = 0; i < d.length; i++) { | ||
de = d[i]; | ||
for (i_1 = 0; i_1 < de.length; i_1++) { | ||
element = de[i_1]; | ||
if (typeof element === "object" && | ||
!Array.isArray(element) && | ||
element !== null && | ||
element.type == "Buffer" && | ||
Array.isArray(element.data)) { | ||
de[i_1] = Buffer.from(element.data); | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
for (i = 0; i < d.length; i++) { | ||
element = d[i]; | ||
if (typeof element === "object" && | ||
!Array.isArray(element) && | ||
element !== null && | ||
element.type == "Buffer" && | ||
Array.isArray(element.data)) { | ||
d[i] = Buffer.from(element.data); | ||
} | ||
} | ||
} | ||
} | ||
if (string.startsWith('"Error: ')) { | ||
throw d; | ||
} | ||
else { | ||
return [2, d]; | ||
} | ||
return [2]; | ||
} | ||
var string_2 = ""; | ||
sqlite.stdout.on("data", function (data) { | ||
string_2 += data.toString(); | ||
if (string_2.substring(string_2.length - 3) === "EOF") { | ||
resolve(JSON.parse(string_2.split("EOF")[0])); | ||
} | ||
}); | ||
sqlite.stdin.write("".concat(JSON.stringify(["executeQuery", Query, fetch, values]), "\n")); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
}); | ||
}; | ||
exports.executeQuery = executeQuery; | ||
var executeMany = function (Query, v) { | ||
return new Promise(function (resolve, reject) { | ||
try { | ||
if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) { | ||
return reject("Sqlite not defined"); | ||
} | ||
var string_3 = ""; | ||
sqlite.stdout.on("data", function (data) { | ||
string_3 += data.toString(); | ||
if (string_3.substring(string_3.length - 3) === "EOF") { | ||
resolve(JSON.parse(string_3.split("EOF")[0])); | ||
var executeMany = function (Query, v) { return __awaiter(void 0, void 0, void 0, function () { | ||
var string, l, i, sl, j, _a, _b, _c, chunk, e_3_1; | ||
var _d, e_3, _e, _f; | ||
return __generator(this, function (_g) { | ||
switch (_g.label) { | ||
case 0: | ||
if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) { | ||
throw "Sqlite not defined"; | ||
} | ||
}); | ||
sqlite.stdin.write(JSON.stringify(["executeMany", Query, v])); | ||
string = ""; | ||
l = v.length; | ||
for (i = 0; i < l; i++) { | ||
sl = v[i].length; | ||
for (j = 0; j < sl; j++) { | ||
if (!Buffer.isBuffer(v[i][j])) { | ||
continue; | ||
} | ||
v[i][j] = JSON.stringify(v[i][j]); | ||
} | ||
} | ||
sqlite.stdin.write("".concat(JSON.stringify(["executeMany", Query, v]), "\n")); | ||
_g.label = 1; | ||
case 1: | ||
_g.trys.push([1, 6, 7, 12]); | ||
_a = true, _b = __asyncValues(sqlite.stdout); | ||
_g.label = 2; | ||
case 2: return [4, _b.next()]; | ||
case 3: | ||
if (!(_c = _g.sent(), _d = _c.done, !_d)) return [3, 5]; | ||
_f = _c.value; | ||
_a = false; | ||
try { | ||
chunk = _f; | ||
string += chunk; | ||
if (string.substring(string.length - 3) === "EOF") { | ||
return [3, 5]; | ||
} | ||
} | ||
finally { | ||
_a = true; | ||
} | ||
_g.label = 4; | ||
case 4: return [3, 2]; | ||
case 5: return [3, 12]; | ||
case 6: | ||
e_3_1 = _g.sent(); | ||
e_3 = { error: e_3_1 }; | ||
return [3, 12]; | ||
case 7: | ||
_g.trys.push([7, , 10, 11]); | ||
if (!(!_a && !_d && (_e = _b["return"]))) return [3, 9]; | ||
return [4, _e.call(_b)]; | ||
case 8: | ||
_g.sent(); | ||
_g.label = 9; | ||
case 9: return [3, 11]; | ||
case 10: | ||
if (e_3) throw e_3.error; | ||
return [7]; | ||
case 11: return [7]; | ||
case 12: | ||
if (JSON.parse(string.split("EOF")[0]) === true) { | ||
return [2, true]; | ||
} | ||
throw JSON.parse(string.split("EOF")[0]); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
}; | ||
}); }; | ||
exports.executeMany = executeMany; | ||
var executeScript = function (scriptName) { | ||
return new Promise(function (resolve, reject) { | ||
try { | ||
if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) { | ||
return reject("Sqlite not defined"); | ||
} | ||
var string_4 = ""; | ||
sqlite.stdout.on("data", function (data) { | ||
string_4 += data.toString(); | ||
if (string_4.substring(string_4.length - 3) === "EOF") { | ||
resolve(JSON.parse(string_4.split("EOF")[0])); | ||
var executeScript = function (scriptName) { return __awaiter(void 0, void 0, void 0, function () { | ||
var string, _a, _b, _c, chunk, e_4_1; | ||
var _d, e_4, _e, _f; | ||
return __generator(this, function (_g) { | ||
switch (_g.label) { | ||
case 0: | ||
if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) { | ||
throw "Sqlite not defined"; | ||
} | ||
}); | ||
sqlite.stdin.write(JSON.stringify(["executeScript", scriptName])); | ||
string = ""; | ||
sqlite.stdin.write("".concat(JSON.stringify(["executeScript", scriptName]), "\n")); | ||
_g.label = 1; | ||
case 1: | ||
_g.trys.push([1, 6, 7, 12]); | ||
_a = true, _b = __asyncValues(sqlite.stdout); | ||
_g.label = 2; | ||
case 2: return [4, _b.next()]; | ||
case 3: | ||
if (!(_c = _g.sent(), _d = _c.done, !_d)) return [3, 5]; | ||
_f = _c.value; | ||
_a = false; | ||
try { | ||
chunk = _f; | ||
string += chunk; | ||
if (string.substring(string.length - 3) === "EOF") { | ||
return [3, 5]; | ||
} | ||
} | ||
finally { | ||
_a = true; | ||
} | ||
_g.label = 4; | ||
case 4: return [3, 2]; | ||
case 5: return [3, 12]; | ||
case 6: | ||
e_4_1 = _g.sent(); | ||
e_4 = { error: e_4_1 }; | ||
return [3, 12]; | ||
case 7: | ||
_g.trys.push([7, , 10, 11]); | ||
if (!(!_a && !_d && (_e = _b["return"]))) return [3, 9]; | ||
return [4, _e.call(_b)]; | ||
case 8: | ||
_g.sent(); | ||
_g.label = 9; | ||
case 9: return [3, 11]; | ||
case 10: | ||
if (e_4) throw e_4.error; | ||
return [7]; | ||
case 11: return [7]; | ||
case 12: | ||
if (JSON.parse(string.split("EOF")[0]) === true) { | ||
return [2, true]; | ||
} | ||
throw JSON.parse(string.split("EOF")[0]); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
}; | ||
}); }; | ||
exports.executeScript = executeScript; |
{ | ||
"name": "sqlite-electron", | ||
"version": "2.2.5", | ||
"version": "2.2.8", | ||
"description": "A module for electron to use sqlite3 without rebuilding", | ||
@@ -5,0 +5,0 @@ "main": "./cjs/sqlite-electron.js", |
201
README.md
# Sqlite Electron | ||
Sqlite Electron is a module for electron to use sqlite3 database without rebuilding it supports Windows(win32) (x64, x32) and Linux (x64). It now supports ESM and CJS 🎉. | ||
Sqlite Electron is a module for electron to use sqlite3 database without rebuilding it supports Windows (x64, x32) and Linux (x64). It supports ESM and CJS. | ||
Several bugs fixed and now all data types are supported | ||
## Installation | ||
@@ -12,2 +14,3 @@ | ||
``` | ||
OR | ||
@@ -22,2 +25,3 @@ | ||
## Notes | ||
1. The package installs the prebuilt binaries of the sqlite on your system (if your system is supported) if you want any other platform binaries for a specific version go to https://github.com/tmotagam/sqlite-electron/releases. | ||
@@ -30,22 +34,28 @@ | ||
Good parctice example | ||
```javascript | ||
import { executeQuery } from 'sqlite-electron' | ||
executeQuery("INSERT INTO sqlite_main (NAME,AGE,ADDRESS,SALARY) VALUES (?, ?, ?, ?);", [var_name, var_age, var_address, var_salary]) // Do this | ||
import { executeQuery } from "sqlite-electron"; | ||
executeQuery( | ||
"INSERT INTO sqlite_main (NAME,AGE,ADDRESS,SALARY) VALUES (?, ?, ?, ?);", | ||
[var_name, var_age, var_address, var_salary] | ||
); // Do this | ||
``` | ||
Bad parctice example: | ||
```javascript | ||
import { executeQuery } from 'sqlite-electron' | ||
executeQuery(`INSERT INTO sqlite_main (NAME,AGE,ADDRESS,SALARY) VALUES (${var_name}, ${var_age}, ${var_address}, ${var_salary});`) // Never do this | ||
import { executeQuery } from "sqlite-electron"; | ||
executeQuery( | ||
`INSERT INTO sqlite_main (NAME,AGE,ADDRESS,SALARY) VALUES (${var_name}, ${var_age}, ${var_address}, ${var_salary});` | ||
); // Never do this | ||
``` | ||
## API`s | ||
| Api | Description | | ||
| ---------------- |:---------------------:| | ||
| setdbPath(path='') | It opens or creates the database for operation | | ||
| executeQuery(Query = '', fetch = '', values = []) | It Executes single query with fetch and values the fetch must be in string eg:- 'all', '1','2'... '' values must be array | | ||
| executeMany(Query = '', values = []) | It executes single query with multiple values | | ||
| executeScript(scriptName = '') | It execute the sql script scriptName must be name of the script or the script itself | | ||
| Api | Description | | ||
| ------------------------------------------------- | :-----------------------------------------------------------------------------------------------------------------------: | | ||
| setdbPath(path='') | It opens or creates the database for operation | | ||
| executeQuery(Query = '', fetch = '', values = []) | It Executes single query with fetch and values the fetch must be in string eg:- 'all', '1','2'... '' values must be array | | ||
| executeMany(Query = '', values = []) | It executes single query with multiple values | | ||
| executeScript(scriptName = '') | It execute the sql script scriptName must be name of the script or the script itself | | ||
@@ -59,15 +69,15 @@ ## Usage | ||
```javascript | ||
const { app, BrowserWindow } = require('electron') | ||
const sqlite = require('sqlite-electron') | ||
const { app, BrowserWindow } = require("electron"); | ||
const sqlite = require("sqlite-electron"); | ||
function createWindow () { | ||
// Your Code | ||
function createWindow() { | ||
// Your Code | ||
} | ||
app.whenReady().then(() => { | ||
// Your Code | ||
}) | ||
// Your Code | ||
}); | ||
app.on('window-all-closed', () => { | ||
// Your Code | ||
}) | ||
app.on("window-all-closed", () => { | ||
// Your Code | ||
}); | ||
``` | ||
@@ -82,19 +92,19 @@ | ||
```javascript | ||
const { app, BrowserWindow, ipcMain } = require('electron') | ||
const sqlite = require('sqlite-electron') | ||
const { app, BrowserWindow, ipcMain } = require("electron"); | ||
const sqlite = require("sqlite-electron"); | ||
function createWindow () { | ||
// Your Code | ||
function createWindow() { | ||
// Your Code | ||
} | ||
app.whenReady().then(() => { | ||
// Your Code | ||
}) | ||
// Your Code | ||
}); | ||
app.on('window-all-closed', () => { | ||
// Your Code | ||
}) | ||
app.on("window-all-closed", () => { | ||
// Your Code | ||
}); | ||
ipcMain.handle('databasePath', async (event, dbPath) => { | ||
return await sqlite.setdbPath(dbPath) | ||
}) | ||
ipcMain.handle("databasePath", async (event, dbPath) => { | ||
return await sqlite.setdbPath(dbPath); | ||
}); | ||
``` | ||
@@ -105,19 +115,19 @@ | ||
```javascript | ||
const { app, BrowserWindow, ipcMain } = require('electron') | ||
const sqlite = require('sqlite-electron') | ||
const { app, BrowserWindow, ipcMain } = require("electron"); | ||
const sqlite = require("sqlite-electron"); | ||
function createWindow () { | ||
// Your Code | ||
function createWindow() { | ||
// Your Code | ||
} | ||
app.whenReady().then(() => { | ||
// Your Code | ||
}) | ||
// Your Code | ||
}); | ||
app.on('window-all-closed', () => { | ||
// Your Code | ||
}) | ||
app.on("window-all-closed", () => { | ||
// Your Code | ||
}); | ||
ipcMain.handle('createInMemoryDatabase', async() => { | ||
return await sqlite.setdbPath(':memory:') | ||
}) | ||
ipcMain.handle("createInMemoryDatabase", async () => { | ||
return await sqlite.setdbPath(":memory:"); | ||
}); | ||
``` | ||
@@ -127,26 +137,26 @@ | ||
This is the function for executing any single query eg: 'SELECT * FROM sqlite_main' you can give values through value array and tell the function to fetch data by specifying the fetch parameter eg: "all", 1, 2, 3, .., infinity. | ||
This is the function for executing any single query eg: 'SELECT \* FROM sqlite_main' you can give values through value array and tell the function to fetch data by specifying the fetch parameter eg: "all", 1, 2, 3, .., infinity. | ||
```javascript | ||
const { app, BrowserWindow, ipcMain } = require('electron') | ||
const sqlite = require('sqlite-electron') | ||
const { app, BrowserWindow, ipcMain } = require("electron"); | ||
const sqlite = require("sqlite-electron"); | ||
function createWindow () { | ||
// Your Code | ||
function createWindow() { | ||
// Your Code | ||
} | ||
app.whenReady().then(() => { | ||
// Your Code | ||
}) | ||
// Your Code | ||
}); | ||
app.on('window-all-closed', () => { | ||
// Your Code | ||
}) | ||
app.on("window-all-closed", () => { | ||
// Your Code | ||
}); | ||
ipcMain.handle('databasePath', async (event, dbPath) => { | ||
return await sqlite.setdbPath(dbPath) | ||
}) | ||
ipcMain.handle("databasePath", async (event, dbPath) => { | ||
return await sqlite.setdbPath(dbPath); | ||
}); | ||
ipcMain.handle('executeQuery', async (event, query, fetch, value) => { | ||
ipcMain.handle("executeQuery", async (event, query, fetch, value) => { | ||
return await sqlite.executeQuery(query, fetch, value); | ||
}) | ||
}); | ||
``` | ||
@@ -163,23 +173,23 @@ | ||
```javascript | ||
const { app, BrowserWindow, ipcMain } = require('electron') | ||
const sqlite = require('sqlite-electron') | ||
const { app, BrowserWindow, ipcMain } = require("electron"); | ||
const sqlite = require("sqlite-electron"); | ||
function createWindow () { | ||
// Your Code | ||
function createWindow() { | ||
// Your Code | ||
} | ||
app.whenReady().then(() => { | ||
// Your Code | ||
}) | ||
// Your Code | ||
}); | ||
app.on('window-all-closed', () => { | ||
// Your Code | ||
}) | ||
app.on("window-all-closed", () => { | ||
// Your Code | ||
}); | ||
ipcMain.handle('databasePath', async (event, dbPath) => { | ||
return await sqlite.setdbPath(dbPath) | ||
}) | ||
ipcMain.handle("databasePath", async (event, dbPath) => { | ||
return await sqlite.setdbPath(dbPath); | ||
}); | ||
ipcMain.handle('executeMany', async (event, query, values) => { | ||
return await sqlite.executeMany(query, values) | ||
}) | ||
ipcMain.handle("executeMany", async (event, query, values) => { | ||
return await sqlite.executeMany(query, values); | ||
}); | ||
``` | ||
@@ -193,3 +203,2 @@ | ||
eg: script.sql | ||
@@ -202,32 +211,35 @@ | ||
```javascript | ||
const { app, BrowserWindow, ipcMain } = require('electron') | ||
const sqlite = require('sqlite-electron') | ||
const { app, BrowserWindow, ipcMain } = require("electron"); | ||
const sqlite = require("sqlite-electron"); | ||
function createWindow () { | ||
// Your Code | ||
function createWindow() { | ||
// Your Code | ||
} | ||
app.whenReady().then(() => { | ||
// Your Code | ||
}) | ||
// Your Code | ||
}); | ||
app.on('window-all-closed', () => { | ||
// Your Code | ||
}) | ||
app.on("window-all-closed", () => { | ||
// Your Code | ||
}); | ||
ipcMain.handle('databasePath', async (event, dbPath) => { | ||
return await sqlite.setdbPath(dbPath) | ||
}) | ||
ipcMain.handle("databasePath", async (event, dbPath) => { | ||
return await sqlite.setdbPath(dbPath); | ||
}); | ||
ipcMain.handle('executeScript', async (event, scriptpath) => { | ||
ipcMain.handle("executeScript", async (event, scriptpath) => { | ||
return await sqlite.executeScript(scriptpath); | ||
// or | ||
return await sqlite.executeScript('CREATE TABLE IF NOT EXISTS sqlite_main (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,NAME TEXT NOT NULL,AGE INT NOT NULL,ADDRESS CHAR(50) NOT NULL,SALARY REAL NOT NULL);'); | ||
}) | ||
return await sqlite.executeScript( | ||
"CREATE TABLE IF NOT EXISTS sqlite_main (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,NAME TEXT NOT NULL,AGE INT NOT NULL,ADDRESS CHAR(50) NOT NULL,SALARY REAL NOT NULL);" | ||
); | ||
}); | ||
``` | ||
## Example | ||
[See sqlite-electron in action using electron 21.0.1](https://github.com/tmotagam/sqlite-electron/tree/master/example) | ||
[See sqlite-electron in action using electron 25.0.1](https://github.com/tmotagam/sqlite-electron/tree/master/example) | ||
## Contributing | ||
Pull requests and issues are welcome. For major changes, please open an issue first to discuss what you would like to change. | ||
@@ -238,2 +250,3 @@ | ||
## License | ||
[GPL v3.0](https://choosealicense.com/licenses/gpl-3.0/) | ||
[GPL v3.0](https://choosealicense.com/licenses/gpl-3.0/) |
@@ -21,11 +21,17 @@ /* | ||
const fs = require('fs'); | ||
const { resolve, dirname } = require('path') | ||
const extract = require('./dependencies') | ||
if (process.platform === 'win32') { | ||
const file = fs.createWriteStream(`./sqlite-${process.platform}-${process.arch}.exe`); | ||
https.get(`https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.5/sqlite-${process.platform}-${process.arch}.exe`, (response) => { | ||
const file = fs.createWriteStream(`./sqlite-${process.platform}-${process.arch}.zip`); | ||
https.get(`https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.8/sqlite-${process.platform}-${process.arch}.zip`, (response) => { | ||
if (response.statusCode === 200) { | ||
response.pipe(file); | ||
file.on("finish", () => { | ||
file.on("finish", async () => { | ||
file.close(); | ||
console.log("Download Completed") | ||
await extract(resolve(`./sqlite-${process.platform}-${process.arch}.zip`), { dir: dirname(resolve(`./sqlite-${process.platform}-${process.arch}.zip`)) }) | ||
console.log("Extraction Completed") | ||
fs.unlinkSync(resolve(`./sqlite-${process.platform}-${process.arch}.zip`)) | ||
}); | ||
@@ -36,12 +42,15 @@ } else if (response.statusCode === 302) { | ||
response.pipe(file); | ||
file.on("finish", () => { | ||
file.on("finish", async () => { | ||
file.close(); | ||
console.log("Download Completed") | ||
await extract(resolve(`./sqlite-${process.platform}-${process.arch}.zip`), { dir: dirname(resolve(`./sqlite-${process.platform}-${process.arch}.zip`)) }) | ||
console.log("Extraction Completed") | ||
fs.unlinkSync(resolve(`./sqlite-${process.platform}-${process.arch}.zip`)) | ||
}); | ||
} else { | ||
throw { code: response.statusCode, message: response.statusMessage, url: `https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.5/sqlite-${process.platform}-${process.arch}.exe` } | ||
throw { code: response.statusCode, message: response.statusMessage, url: `https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.8/sqlite-${process.platform}-${process.arch}.zip` } | ||
} | ||
}) | ||
} else { | ||
throw { code: response.statusCode, message: response.statusMessage, url: `https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.5/sqlite-${process.platform}-${process.arch}.exe` } | ||
throw { code: response.statusCode, message: response.statusMessage, url: `https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.8/sqlite-${process.platform}-${process.arch}.zip` } | ||
} | ||
@@ -52,9 +61,13 @@ }).on("error", (e) => { | ||
} else { | ||
const file = fs.createWriteStream(`./sqlite-${process.platform}-${process.arch}`, { mode: 0o744 }); | ||
https.get(`https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.5/sqlite-${process.platform}-${process.arch}`, (response) => { | ||
const file = fs.createWriteStream(`./sqlite-${process.platform}-${process.arch}.zip`); | ||
https.get(`https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.8/sqlite-${process.platform}-${process.arch}.zip`, (response) => { | ||
if (response.statusCode === 200) { | ||
response.pipe(file); | ||
file.on("finish", () => { | ||
file.on("finish", async () => { | ||
file.close(); | ||
console.log("Download Completed") | ||
await extract(resolve(`./sqlite-${process.platform}-${process.arch}.zip`), { dir: dirname(resolve(`./sqlite-${process.platform}-${process.arch}.zip`)) }) | ||
console.log("Extraction Completed") | ||
fs.unlinkSync(resolve(`./sqlite-${process.platform}-${process.arch}.zip`)) | ||
fs.chmodSync(resolve(`./sqlite-${process.platform}-${process.arch}/sqlite-${process.platform}-${process.arch}`), 0o744) | ||
}); | ||
@@ -65,12 +78,16 @@ } else if (response.statusCode === 302) { | ||
response.pipe(file); | ||
file.on("finish", () => { | ||
file.on("finish", async () => { | ||
file.close(); | ||
console.log("Download Completed") | ||
await extract(resolve(`./sqlite-${process.platform}-${process.arch}.zip`), { dir: dirname(resolve(`./sqlite-${process.platform}-${process.arch}.zip`)) }) | ||
console.log("Extraction Completed") | ||
fs.unlinkSync(resolve(`./sqlite-${process.platform}-${process.arch}.zip`)) | ||
fs.chmodSync(resolve(`./sqlite-${process.platform}-${process.arch}/sqlite-${process.platform}-${process.arch}`), 0o744) | ||
}); | ||
} else { | ||
throw { code: response.statusCode, message: response.statusMessage, url: `https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.5/sqlite-${process.platform}-${process.arch}` } | ||
throw { code: response.statusCode, message: response.statusMessage, url: `https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.8/sqlite-${process.platform}-${process.arch}.zip` } | ||
} | ||
}) | ||
} else { | ||
throw { code: response.statusCode, message: response.statusMessage, url: `https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.5/sqlite-${process.platform}-${process.arch}` } | ||
throw { code: response.statusCode, message: response.statusMessage, url: `https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.8/sqlite-${process.platform}-${process.arch}.zip` } | ||
} | ||
@@ -77,0 +94,0 @@ }).on("error", (e) => { |
@@ -22,9 +22,9 @@ /* | ||
* | ||
* @param {string} path - A string param for path to database | ||
* @return {Promise<Boolean>} Promise of boolean is returned | ||
* @param {string} path - Relative path of a database since it constructs absolute path by itself | ||
* @return {Promise<Boolean>} boolean | ||
* | ||
* @example | ||
* | ||
* setdbPath(path='/path/to/db/path.db') | ||
* setdbPath(path=':memory:') // now supports In-memory database | ||
* setdbPath(path='./path/to/db/path.db') | ||
* setdbPath(path=':memory:') // In-memory database | ||
*/ | ||
@@ -37,6 +37,6 @@ | ||
* | ||
* @param {string} Query - A string param for SQL query | ||
* @param {string} [fetch] - A optional string param for fetching values from the table | ||
* @param {(string | number | null | Buffer)[]} [values] - A optional array param for values for a SQL query | ||
* @return {Promise<Boolean | []>} Promise of boolean or an array is returned if fetch is defined | ||
* @param {string} Query - SQL query | ||
* @param {string} [fetch] - An optional param for fetching values from the table | ||
* @param {Array<string | number | null | Buffer>} [values] - An optional param for values used in a SQL query | ||
* @return {Promise<Boolean | Array<any> | Array<Array<any>>>} Boolean or an array if fetch is defined | ||
* | ||
@@ -52,4 +52,4 @@ * @example | ||
fetch?: string, | ||
values?: (string | number | null | Buffer)[] | ||
): Promise<Boolean | []>; | ||
values?: Array<string | number | null | Buffer> | ||
): Promise<Boolean | Array<any> | Array<Array<any>>>; | ||
@@ -59,9 +59,9 @@ /** | ||
* | ||
* @param {string} Query - A string param for SQL query | ||
* @param {(string | number | null | Buffer)[]} v - A array param for values for a SQL query | ||
* @return {Promise<Boolean>} Promise of boolean is returned | ||
* @param {string} Query - SQL query | ||
* @param {Array<Array<string | number | null | Buffer>>} v - A param for values used in a SQL query | ||
* @return {Promise<Boolean>} boolean | ||
* | ||
* @example | ||
* | ||
* executeQuery(Query='INSERT INTO sqlite_master (name, email, joining_date, salary) values(?,?,?,?)', fetch='', v=[['John Doe','example@sqlite-electron.com','1250-12-19',8000000], ['John Doe','example@sqlite-electron.com','1250-12-19',8000000]]) | ||
* executeMany(Query='INSERT INTO sqlite_master (name, email, joining_date, salary) values(?,?,?,?)', v=[['John Doe','example@sqlite-electron.com','1250-12-19',8000000], ['John Doe','example@sqlite-electron.com','1250-12-19',8000000]]) | ||
*/ | ||
@@ -71,3 +71,3 @@ | ||
Query: string, | ||
v: (string | number | null | Buffer)[] | ||
v: Array<Array<string | number | null | Buffer>> | ||
): Promise<boolean>; | ||
@@ -79,7 +79,7 @@ | ||
* @param {string} scriptName - A path param for sql script or sql script itself | ||
* @return {Promise<Boolean>} Promise of boolean is returned | ||
* @return {Promise<Boolean>} boolean | ||
* | ||
* @example | ||
* | ||
* executeScript(scriptName='./script.sql') | ||
* executeScript(scriptName='C://database//script.sql') | ||
* executeScript(scriptName='CREATE TABLE IF NOT EXISTS comp (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,NAME TEXT NOT NULL,AGE INT NOT NULL,ADDRESS CHAR(50) NOT NULL,SALARY REAL NOT NULL);') | ||
@@ -86,0 +86,0 @@ */ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
147913
8
2398
242
4
8