Package Exports
- @nano-sql/core
- @nano-sql/core/lib/adapters/webSQL
- @nano-sql/core/lib/interfaces
- @nano-sql/core/lib/utilities
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@nano-sql/core) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Universal database for the client, server & mobile devices. It's like Lego for databases.




NanoSQL 2.0 is in BETA state right now, tons of undocumented breaking changes from 1.0.
The API is also not stable, not recommended for production environments.
Current minified build: https://cdn.jsdelivr.net/npm/@nano-sql/core@2.0.0-rc10/dist/nano-sql.min.js
NPM Install
npm i @nano-sql/core
2.0 Progress
- Query Engine
- Hook/Filter System
- Memory/Local Storage Adapter
- Graph Query Support
- Event System
- Indexed DB/WebSQL/RocksDB Adapters
- Core Tests
- Adapter Tests
- 2.0 documentation
- 2.0 release
- GraphQL Query Support
- SQLite3, Cordova, Redis, ReactNative, MySQL Adapters
- Net Plugin (Offline Syncing)
- Search Plugin
- History Plugin
- SQLite Query Support
- MongoDB Query Support
- ReQL Query Support
Examples
// Persistent Database
nSQL().connect({
id: "test",
mode: "PERM",
tables: [
{
name: "users",
model: {
"id:uuid": {pk: true},
"name:string": {},
"age:int": {},
"meta:obj": {
model: {
"color:string": {}
}
},
"tags:string[]": {default: []}
}
indexes: {
"tags:string[]": {},
"meta.color:string": {},
"age:int": {}
}
}
],
}).then(() => {
return nSQL("users").query("upsert", {name: "Jeb", age: 20, meta: {color: "blue"}, tags: ["some", "tags", "here"]}).exec();
}).then(() => {
return nSQL("users").query("select").exec();
}).then((rows) => {
console.log(rows);
/*
[
{
"id": "64c611b8-0b1e-42f6-af52-5b8289834bba",
"name": "Billy",
"age": 21,
"meta": {
"color": "blue"
},
"tags": [
"some",
"tags",
"here"
]
}
]
*/
});
// Graph Queries
nSQL().query("select", ["author[0].name AS author", "body", "comments[0].totalComments AS commentsTotal", "id", "title"]).from({
table: () => fetch("https://jsonplaceholder.typicode.com/posts").then(d => d.json()).then(j => ({rows: j, cache: true})),
as: "posts"
}).graph([
{
key: "author",
with: {
table: () => fetch("https://jsonplaceholder.typicode.com/users").then(d => d.json()).then(j => ({rows: j, cache: true})),
as: "author"
},
on: ["author.id", "=", "posts.userId"]
},
{
key: "comments",
select: ["COUNT(*) as totalComments"],
with: {
table: () => fetch("https://jsonplaceholder.typicode.com/comments").then(d => d.json()).then(j => ({rows: j, cache: true})),
as: "comments"
},
on: ["comments.postId", "=", "posts.id"]
}
]).exec().then((rows) => {
console.log(rows);
/*
"author": "Leanne Graham",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto",
"commentsTotal": 5,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit"
},
{
"author": "Leanne Graham",
"body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla",
"commentsTotal": 5,
"id": 2,
"title": "qui est esse"
}
...
*/
});
// Join Queries
nSQL().query("select", ["posts.id AS id", "posts.title AS title", "comments.name AS comment", "users.name AS name"]).from({
table: () => fetch("https://jsonplaceholder.typicode.com/posts").then(d => d.json()).then(j => ({rows: j, cache: true})),
as: "posts"
}).where(["userId", "=", 3]).join([
{
type: "inner",
with: {
table: () => fetch("https://jsonplaceholder.typicode.com/comments").then(d => d.json()).then(j => ({rows: j, cache: true})),
as: "comments"
},
on: ["posts.id", "=", "comments.postId"]
},
{
type: "inner",
with: {
table: () => fetch("https://jsonplaceholder.typicode.com/users").then(d => d.json()).then(j => ({rows: j, cache: true})),
as: "users"
},
on: ["users.id", "=", "posts.userId"]
}
])
.exec().then((rows) => {
console.log(rows);
/*
[
{
"id": 21,
"title": "asperiores ea ipsam voluptatibus modi minima quia sint",
"comment": "perspiciatis magnam ut eum autem similique explicabo expedita",
"name": "Clementine Bauch"
},
{
"id": 21,
"title": "asperiores ea ipsam voluptatibus modi minima quia sint",
"comment": "officia ullam ut neque earum ipsa et fuga",
"name": "Clementine Bauch"
},
.....
]
*/
})