Same as sqlite-tag but without the native sqlite3 module dependency

Overview

sqlite-tag-spawned

build status Coverage Status

Social Media Photo by Tomas Kirvėla on Unsplash

The same sqlite-tag ease but without the native sqlite3 dependency, aiming to replace dblite.

import SQLiteTagSpawned from 'sqlite-tag-spawned';
// const SQLiteTagSpawned = require('sqlite-tag-spawned');

const {query, get, all, raw, transaction} = SQLiteTagSpawned('./db.sql');

// single query as any info
console.log(await query`.databases`);

// single query as SQL
await query`CREATE TABLE IF NOT EXISTS names (
  id INTEGER PRIMARY KEY,
  name TEXT
)`;

// transaction (requires .commit() to execute)
const populate = transaction();
for (let i = 0; i < 2; i++)
  populate`INSERT INTO names (name) VALUES (${'Name' + i})`;
await populate.commit();

// get single row (works with LIMIT 1 too, of course)
await get`SELECT name FROM names`;
// { name: 'Name0' }

// get all results, if any, or an empty array
await all`SELECT * FROM names`;
// [ { id: 1, name: 'Name0' }, { id: 2, name: 'Name1' } ]

// use the IN clause through arrays
const list = ['Name 0', 'Name 1'];
await all`SELECT * FROM names WHERE name IN (${list})`;

Differently from dblite

  • requires SQLite 3.33 or higher (it uses the -json output mode)
  • each query is a spawn call except for transactions, grouped as single spawned query
  • performance still similar to sqlite3 native module
  • :memory: database is based on a runtime temporary file and it requires NodeJS 16+
Comments
  • Transactions might not work properly

    Transactions might not work properly

    I think transactions might not work properly here, unless I'm misreading the code what's happening is that basically something like the following is executing:

    BEGIN TRANSACTION;
    QUERY1;
    QUERY2;
    ...
    QUERYN;
    COMMIT;
    

    But say I'm executing the following:

    CREATE TABLE example ( id INTEGER PRIMARY KEY, title TEXT, description TEXT );
    BEGIN TRANSACTION;
    INSERT INTO example VALUES( 1, 'title1', 'description1' );
    INSERT INTO example VALUES( 2, 'title2', 'description2' );
    INSERT INTO example VALUES( 1, 'title1', 'description1' );
    COMMIT;
    

    The result of that is that 2 rows are inserted into the table, while I think what we actually want is something like: "did all the previous query execute successfully? If so we execute a "COMMIT" at the end, otherwise we execute a "ROLLBACK".

    Like I wouldn't expect to see any rows in that table at the end of the transaction.

    opened by fabiospampinato 10
  • Empty get/all results in process termination

    Empty get/all results in process termination

    When get/all returns with 0 rows, result equals "". The parse in the next line then throws an error, which I think is still part of the spawned process and can't be caught by the caller.

            const json = parse(result);
            res(type === 'get' && isArray(json) ? json.shift() : json);
    

    Maybe should just return an empty result instead of exit the process.

    opened by yoavain 6
  • Support for exporting/serializing/deserializing

    Support for exporting/serializing/deserializing

    It'd be nice if the following got implemented:

    • Support for backing up a database into a separate file, something like sqlite3 foo.db ".backup 'foo.db.bak'" interally.
    • Support for serializing a database to a Uint8Array, which is like a backup but the file is read and deleted afterwards.
    • Support for deserializing a serialized database, which is kinda like :memory: but the buffer is written in the temp file.
    wontfix 
    opened by fabiospampinato 5
  • Safer Date escaping

    Safer Date escaping

    I don't know how important this is, but potentially this check is unsafe:

    https://github.com/WebReflection/sqlite-tag-spawned/blob/d29a0247015361f91d398bff160372de439a7781/esm/utils.js#L28-L29

    Something could be an instance of Date and overload the toISOString method to execute an arbitrary query.

    opened by fabiospampinato 3
  • Add to options arguments to be passed to the sqlite process

    Add to options arguments to be passed to the sqlite process

    For example: separator can be very useful. I'm trying to use query instead of get (due to #1) and my data contains the default separator "|"

    opened by yoavain 3
Owner
Andrea Giammarchi
Web, Mobile, IoT and all Web & JS things since 00's
Andrea Giammarchi
A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js

bookshelf.js Bookshelf is a JavaScript ORM for Node.js, built on the Knex SQL query builder. It features both Promise-based and traditional callback i

Bookshelf.js 6.3k Jan 2, 2023
sqlite3 in ur indexeddb

This is an absurd project. It implements a backend for sql.js (sqlite3 compiled for the web) that treats IndexedDB like a disk and stores data in bloc

James Long 3.6k Jan 4, 2023
sqlite3 in ur indexeddb

This is an absurd project. It implements a backend for sql.js (sqlite3 compiled for the web) that treats IndexedDB like a disk and stores data in bloc

James Long 3.6k Dec 30, 2022
ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platforms and can be used

null 30.1k Jan 3, 2023
A javascript library to run SQLite on the web.

SQLite compiled to JavaScript sql.js is a javascript SQL database. It allows you to create a relational database and query it entirely in the browser.

SQL.JS 11k Jan 7, 2023
Realm is a mobile database: an alternative to SQLite & key-value stores

Realm is a mobile database that runs directly inside phones, tablets or wearables. This project hosts the JavaScript versions of Realm. Currently we s

Realm 5.1k Jan 3, 2023
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite datab

MikroORM 5.4k Dec 31, 2022
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server & SQLite

Prisma Quickstart • Website • Docs • Examples • Blog • Slack • Twitter • Prisma 1 What is Prisma? Prisma is a next-generation ORM that consists of the

Prisma 28k Jan 2, 2023
WebAssembly SQLite with experimental support for browser storage extensions

wa-sqlite This is a WebAssembly build of SQLite with experimental support for writing SQLite virtual filesystems and virtual table modules completely

Roy Hashimoto 260 Jan 1, 2023
Database manager for MySQL, PostgreSQL, SQL Server, MongoDB, SQLite and others. Runs under Windows, Linux, Mac or as web application

Database manager for MySQL, PostgreSQL, SQL Server, MongoDB, SQLite and others. Runs under Windows, Linux, Mac or as web application

DbGate 2k Dec 30, 2022
Ecommerce-backend-nestjs - Ecommerce app with Nestjs + Prisma ORM + GraphQL + SQLite

ECOMMERCE BACKEND NESTJS APP Nestjs + Prisma ORM + GraphQL + SQLite USER Create Account Login Product Create Product Get Products Get Product Search P

Rui Paulo Calei 5 Apr 6, 2022
A service worker that buffers a full video, so when the video tag ask for ranges, these can be satisfied. Play + pause = buffer the whole video.

Full Video Buffer with Service Workers The specification of the preload attribute on a Video element won't allow you to fully buffer a video. This rep

Tito 51 Nov 2, 2022
A Node.js ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud.

Dittorm A Node.js ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud. Installatio

Waline 21 Dec 25, 2022
A remote nodejs Cached sqlite Database Server, for you to have your perfect MAP Cache Saved and useable remotely.

A remote nodejs Cached sqlite Database Server, for you to have your perfect MAP Cache Saved and useable remotely. Easy Server and Client Creations, fast, stores the Cache before stopping and restores it again! it uses ENMAP

Tomato6966 6 Dec 18, 2022
Explore, create and deploy your SQLite databases right from your browser. Quick and easy, no installation required.

SQLighter (under development, alpha code) SQLighter is a database explorer born for SQLite that helps you design and deploy your application database

sqlighter 11 Sep 20, 2022
The Cassandra/Scylla library you didn't want but got anyways.

Installation Using npm: npm install scyllo or if you prefer to use the yarn package manager: yarn add scyllo Usage import { ScylloClient } from 'scyll

LVK.SH 7 Jul 20, 2022
Like JSON-RPC, but supports streaming.

Earthstar Streaming RPC Similar to JSON-RPC, but also supports streaming (soon). Written to be used in Earthstar (github, docs). Table of Contents Usa

Earthstar Project 5 Feb 10, 2022
🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️

A reactive database framework Build powerful React and React Native apps that scale from hundreds to tens of thousands of records and remain fast ⚡️ W

Nozbe 8.8k Jan 5, 2023