Allows you to use SQLite style queries with nanoSQL 2
Documentation | Bugs | Chat
The SQL AST generator is courtesy of alasql.
npm i @nano-sql/query-sqlite --save
import { nanoSQL } from "@nano-sql/core";
import { nSQLite } from "@nano-sql/query-sqlite";
const sqlite = new nSQLite(new nanoSQL());
// sqlite.nSQL => same as normal nSQL usage.
// sqlite.query => use SQLite syntax on nSQL database.
sqlite.nSQL().createDatabase({
id: "my-db",
mode: "PERM"
}).then(() => {
return sqlite.query(`CREATE TABLE IF NOT EXISTS users (
id INT PRIMARY KEY AUTO_INCREMENT,
name TEXT,
pass TEXT,
email TEXT
)`, []).exec();
}).then(() => {
return sqlite.query(
`INSERT INTO users (name, pass, email) VALUES (?, ?, ?)`,
["bill", "123", "bill@gmail.com"]
).exec();
}).then(() => {
return sqlite.query(`SELECT * FROM users;`).exec();
}).then((rows) => {
console.log(rows);
/*
[
{id: 1, name: "bill", pass: "123", email: "bill@gmail.com"}
]
*/
})
- You can't do multiple SQL statements in one query, only one statement per query.
CREATE TABLE
does the same asCREATE TABLE IF NOT EXISTS
.INSERT
andUPDATE
both act as upsert queries.
Copyright (c) 2019 Scott Lott
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- First release