Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
sqlite-worker
Advanced tools
A simple, and persistent, SQLite database for Web and Workers, based on sql.js and sqlite-tag.
Social Media Photo by benjamin lehman on Unsplash
Both init([options])
and SQLiteWorker(path[, options])
optionally accept a configuration/options object with the following fields:
'sqlite-worker'
sql.js
files. By default it's the string 'https://sql.js.org/dist'
Uint8Array
instance. This is used only the very first time, and it fallbacks to new Uint8Array(0)
.Uint8Array
, whenever some query executed an INSERT
, a DELETE
, or an UPDATE
.250
.sqlite-worker
library. By default is the string https://unpkg.com/sqlite-worker?module
Both init(...)
and SQLiteWorker(...)
resolves with the sqlite-tag API, except for the raw
utility, which is not implemented via the Worker interface, but it's exported within the init(...)
, as it requires a special instance that won't survive postMessage
dance.
The API in a nutshell is:
All tags are asynchronous, so that it's possible to await their result.
This is the suggested way to use this module. The Worker can be as simple as this:
// simple-worker.js
let db = null;
const retrieve = (db, method, id, {template, values}) => {
db.then((module) => {
module[method].apply(null, [template].concat(values)).then(result => {
postMessage({id, result});
});
});
};
addEventListener('message', ({data: {id, action, options}}) => {
switch (action) {
case 'init':
if (!db)
db = import(options.library).then(({init}) => init(options));
return db.then(() => postMessage({id, result: 'OK'}));
case 'all':
return retrieve(db, 'all', id, options);
case 'get':
return retrieve(db, 'get', id, options);
case 'query':
return retrieve(db, 'query', id, options);
}
});
And the library can be initialized as such:
import {SQLiteWorker} from 'sqlite-worker';
// SQLiteWorker(workerPath[, options])
SQLiteWorker('simple-worker.js', {
name: 'my-db',
library: '//unpkg.com/sqlite-worker?module'
})
.then(async ({all, get, query}) => {
await query`CREATE TABLE IF NOT EXISTS todos (id INTEGER PRIMARY KEY, value TEXT)`;
const {total} = await get`SELECT COUNT(id) as total FROM todos`;
if (total < 1) {
console.log('Inserting some value');
await query`INSERT INTO todos (value) VALUES (${'a'})`;
await query`INSERT INTO todos (value) VALUES (${'b'})`;
await query`INSERT INTO todos (value) VALUES (${'c'})`;
}
console.log(await all`SELECT * FROM todos`);
});
This module can be used in the main thread, or be imported directly within a Service Worker, as opposite of creating a new worker from the main page.
import {init} from 'sqlite-worker';
// init([options])
init({name: 'my-db'}).then(async ({all, get, query}) => {
await query`CREATE TABLE IF NOT EXISTS todos (id INTEGER PRIMARY KEY, value TEXT)`;
const {total} = await get`SELECT COUNT(id) as total FROM todos`;
if (total < 1) {
console.log('Inserting some value');
await query`INSERT INTO todos (value) VALUES (${'a'})`;
await query`INSERT INTO todos (value) VALUES (${'b'})`;
await query`INSERT INTO todos (value) VALUES (${'c'})`;
}
console.log(await all`SELECT * FROM todos`);
});
FAQs
A simple, and persistent, SQLite database for Web and Workers
The npm package sqlite-worker receives a total of 48 weekly downloads. As such, sqlite-worker popularity was classified as not popular.
We found that sqlite-worker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.