sqlite-electron
Advanced tools
Comparing version 2.0.5 to 2.2.3
{ | ||
"name": "sqlite-electron", | ||
"version": "2.0.5", | ||
"version": "2.2.3", | ||
"description": "A module for electron to use sqlite3 without rebuilding", | ||
"main": "sqlite-electron.js", | ||
"main": "./cjs/sqlite-electron.js", | ||
"module": "./esm.sqlite-electron.mjs", | ||
"types": "./sqlite-electron.d.ts", | ||
"scripts": { | ||
"postinstall": "node ./scripts/postinstall.js" | ||
}, | ||
"exports": { | ||
"import": "./esm/sqlite-electron.mjs", | ||
"require": "./cjs/sqlite-electron.js" | ||
}, | ||
"author": "Motagamwala Taha Arif Ali", | ||
"files": [ | ||
"sqlite-electron.js", | ||
"cjs", | ||
"esm", | ||
"sqlite-electron.d.ts", | ||
@@ -13,0 +20,0 @@ "scripts" |
# Sqlite Electron | ||
Sqlite Electron is a module for electron to use sqlite3 database without rebuilding as of now supports Windows(win32) (x64, x32) and Linux (x64). | ||
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 🎉. | ||
## Installation | ||
Use the package manager [npm](https://npmjs.com/) to install Sqlite Electron. | ||
Use the package manager [npm](https://www.npmjs.com/package/sqlite-electron) to install Sqlite Electron. | ||
@@ -12,16 +12,38 @@ ```bash | ||
``` | ||
OR | ||
## Note | ||
The package installs the prebuilt binaries of the sqlite on your system (if your system is supported) if you want any other platform binaries go to | ||
https://github.com/tmotagam/sqlite-electron/tree/master/binaries | ||
Use the package manager [yarn](https://yarnpkg.com/package/sqlite-electron) to install Sqlite Electron. | ||
```bash | ||
yarn add sqlite-electron | ||
``` | ||
## Functions | ||
## 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. | ||
| Functions | Description | | ||
2. The example written for this library is not a Boilerplate because of its disregards to the security required for electron so do not use it in your application. | ||
3. Never give values in the query string use values array for giving the values for the query not taking this precaution will result in sql injection attacks !. | ||
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 | ||
``` | ||
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 | ||
``` | ||
## API`s | ||
| Api | Description | | ||
| ---------------- |:---------------------:| | ||
| dbPath | Variable to set your path for the database and also to connect to the database if it already exists | | ||
| 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 | | ||
| executeScript(scriptName = '') | It execute the sql script scriptName must be name of the script or the script itself | | ||
@@ -50,7 +72,7 @@ ## Usage | ||
### dbPath | ||
### setdbPath | ||
This is a exposed variable for setting the path of the new database and also for connecting to the existing database. | ||
This is a function for opening a existing database or creating a new database for operation. | ||
Set this variable before using any of the api. | ||
Call this function before calling the other 3 functions. | ||
@@ -72,8 +94,29 @@ ```javascript | ||
ipcMain.handle('databasePath', (event, dbPath) => { | ||
sqlite.dbPath = dbPath | ||
return true | ||
ipcMain.handle('databasePath', async (event, dbPath) => { | ||
return await sqlite.setdbPath(dbPath) | ||
}) | ||
``` | ||
Now you can also create In-memory database like this. | ||
```javascript | ||
const { app, BrowserWindow, ipcMain } = require('electron') | ||
const sqlite = require('sqlite-electron') | ||
function createWindow () { | ||
// Your Code | ||
} | ||
app.whenReady().then(() => { | ||
// Your Code | ||
}) | ||
app.on('window-all-closed', () => { | ||
// Your Code | ||
}) | ||
ipcMain.handle('createInMemoryDatabase', async() => { | ||
return await sqlite.setdbPath(':memory:') | ||
}) | ||
``` | ||
### executeQuery | ||
@@ -83,6 +126,2 @@ | ||
Note: Never give values in the query string use value array for giving the values for the query not taking this precaution will result in sql injection attacks !. | ||
eg: ("INSERT INTO sqlite_main (NAME,AGE,ADDRESS,SALARY) VALUES (?, ?, ?, ?);", ["name", 900, "example street", 123456789000]) // This is best practice | ||
```javascript | ||
@@ -103,5 +142,4 @@ const { app, BrowserWindow, ipcMain } = require('electron') | ||
ipcMain.handle('databasePath', (event, dbPath) => { | ||
sqlite.dbPath = dbPath | ||
return true | ||
ipcMain.handle('databasePath', async (event, dbPath) => { | ||
return await sqlite.setdbPath(dbPath) | ||
}) | ||
@@ -137,5 +175,4 @@ | ||
ipcMain.handle('databasePath', (event, dbPath) => { | ||
sqlite.dbPath = dbPath | ||
return true | ||
ipcMain.handle('databasePath', async (event, dbPath) => { | ||
return await sqlite.setdbPath(dbPath) | ||
}) | ||
@@ -176,5 +213,4 @@ | ||
ipcMain.handle('databasePath', (event, dbPath) => { | ||
sqlite.dbPath = dbPath | ||
return true | ||
ipcMain.handle('databasePath', async (event, dbPath) => { | ||
return await sqlite.setdbPath(dbPath) | ||
}) | ||
@@ -191,3 +227,3 @@ | ||
## Example | ||
[See sqlite-electron in action using electron 19.0.6](https://github.com/tmotagam/sqlite-electron/tree/master/example) | ||
[See sqlite-electron in action using electron 21.0.1](https://github.com/tmotagam/sqlite-electron/tree/master/example) | ||
@@ -194,0 +230,0 @@ ## Contributing |
/* | ||
Postinstall Script for sqlite-electron module | ||
Copyright (C) 2022 Motagamwala Taha Arif Ali | ||
Copyright (C) 2022-2023 Motagamwala Taha Arif Ali | ||
@@ -24,3 +24,3 @@ This program is free software: you can redistribute it and/or modify | ||
const file = fs.createWriteStream(`./sqlite-${process.platform}-${process.arch}.exe`); | ||
https.get(`https://raw.githubusercontent.com/tmotagam/sqlite-electron/master/binaries/sqlite-${process.platform}-${process.arch}.exe`, (response) => { | ||
https.get(`https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.3/sqlite-${process.platform}-${process.arch}.exe`, (response) => { | ||
if (response.statusCode === 200) { | ||
@@ -33,3 +33,3 @@ response.pipe(file); | ||
} else { | ||
throw {code: response.statusCode, message: response.statusMessage, url: `https://raw.githubusercontent.com/tmotagam/sqlite-electron/master/binaries/sqlite-${process.platform}-${process.arch}.exe`} | ||
throw { code: response.statusCode, message: response.statusMessage, url: `https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.3/sqlite-${process.platform}-${process.arch}.exe` } | ||
} | ||
@@ -41,3 +41,3 @@ }).on("error", (e) => { | ||
const file = fs.createWriteStream(`./sqlite-${process.platform}-${process.arch}`, { mode: 0o744 }); | ||
https.get(`https://raw.githubusercontent.com/tmotagam/sqlite-electron/master/binaries/sqlite-${process.platform}-${process.arch}`, (response) => { | ||
https.get(`https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.3/sqlite-${process.platform}-${process.arch}`, (response) => { | ||
if (response.statusCode === 200) { | ||
@@ -50,3 +50,3 @@ response.pipe(file); | ||
} else { | ||
throw {code: response.statusCode, message: response.statusMessage, url: `https://raw.githubusercontent.com/tmotagam/sqlite-electron/master/binaries/sqlite-${process.platform}-${process.arch}`} | ||
throw { code: response.statusCode, message: response.statusMessage, url: `https://github.com/tmotagam/sqlite-electron/releases/download/v2.2.3/sqlite-${process.platform}-${process.arch}` } | ||
} | ||
@@ -53,0 +53,0 @@ }).on("error", (e) => { |
@@ -1,5 +0,4 @@ | ||
/* | ||
Types for sqlite-electron modules | ||
Copyright (C) 2022 Motagamwala Taha Arif Ali | ||
Copyright (C) 2022-2023 Motagamwala Taha Arif Ali | ||
@@ -21,6 +20,14 @@ This program is free software: you can redistribute it and/or modify | ||
/** | ||
* @param {number} dbPath - Path of the database | ||
* setdbPath function allows for connecting to the database. | ||
* | ||
* @param {string} path - A string param for path to database | ||
* @return {Promise<Boolean>} Promise of boolean is returned | ||
* | ||
* @example | ||
* | ||
* setdbPath(path='/path/to/db/path.db') | ||
* setdbPath(path=':memory:') // now supports In-memory database | ||
*/ | ||
export declare const dbPath: string | ||
export declare function setdbPath(path: string): Promise<Boolean>; | ||
@@ -41,3 +48,7 @@ /** | ||
export declare function executeQuery(Query: string, fetch?: string, values?: (string | number | null | Buffer)[]): Promise<Boolean | []> | ||
export declare function executeQuery( | ||
Query: string, | ||
fetch?: string, | ||
values?: (string | number | null | Buffer)[] | ||
): Promise<Boolean | []>; | ||
@@ -56,3 +67,6 @@ /** | ||
export declare function executeMany(Query: string, v: (string | number | null | Buffer)[]): Promise<boolean> | ||
export declare function executeMany( | ||
Query: string, | ||
v: (string | number | null | Buffer)[] | ||
): Promise<boolean>; | ||
@@ -71,2 +85,2 @@ /** | ||
export declare function executeScript(scriptName: string): Promise<Boolean> | ||
export declare function executeScript(scriptName: string): Promise<Boolean>; |
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
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
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
68418
7
559
228
1
6