Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@nano-sql/core
Advanced tools
Universal database layer for the client, server & mobile devices. It's like Lego for databases.
Documentation | API Docs | Bugs | Chat
nanoSQL core provides a standardized query language, data modeling, indexing and plugin system that can use almost any database technology for data storage and query; providing a consistent experience across environments and database engines. You can mix and match database backends, query languages and plugins to get the ideal environnement for rapid development.
One of the big items that lead me to build nanoSQL was how NoSQL stores are becoming so popular and performant yet none of them have SQL semantics when you need them. It’s like you have to choose between good performance (noSQL/Document Store) or having stable data modeling with advanced query capability (SQL Style). It seems to me that you can have both, you just have to be aware of the tradeoffs. The big idea here is to build a SQL style parser on top of noSQL datastores. This buys you the strong data models (which is critical in my opinion) of SQL style systems and noSQL level performance if you play inside a small set of rules. You can jump outside those rules whenever you like at the cost of speed…and that’s the point. YOU the developer get to make the choice when and how that happens.
Run several databases in parallel, each database can use it's own backend adapter. This means you could have one nanoSQL instance running a Redis based database, a MySQL based database and a RocksDB based database at the same time seamlessly!
Develop your application with an embedded database like RocksDB, then deploy into production with Redis, Amazon Dynamo, MySQL or many others. nanoSQL even runs in the browser on top of IndexedDB, WebSQL or LocalStorage. All data is portable and all features are isomorphic; jumping between different databases and environments is trivial.
Classical RDBMS queries like aggregate functions, joins and group bys are also supported. You can even write your own query functions and use foreign keys!
The best of both worlds: Use RDBMS style data models to tune performance but still allow arbitrary columns. Change your data model as often as you want and do type casting only when you need it.
Instantly convert nanoSQL data models into typescript interface files.
Use indexing to build nested graph queries on your data with the power of RDBMS and flexibility of noSQL.
Built in geolocation indexing, autocomplete, observable queries, typescript support, event system, CSV/JSON import & export, fuzzy search, runs in every browser back to IE9 and starts at only 30KB!
nanoSQL | TaffyDB | NeDB | LoveField | PouchDB | alaSQL | RxDB | SQL.js | Lunr | |
---|---|---|---|---|---|---|---|---|---|
Events | ✓ | ✓ | ✕ | ✓ | ✓ | ✕ | ✓ | ✕ | ✕ |
Typescript | ✓ | ✕ | ✓ | ✓ | ✓ | ✕ | ✓ | ✓ | ✓ |
Graph Queries | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
Join Queries | ✓ | ✓ | ✓ | ✓ | ✕ | ✓ | ✕ | ✓ | ✕ |
IndexedDB | ✓ | ✕ | ✕ | ✓ | ✓ | ✓ | ✓ | ✕ | ✕ |
NodeJS | ✓ | ✓ | ✓ | ✕ | ✓ | ✓ | ✓ | ✓ | ✓ |
Foreign Keys | ✓ | ✕ | ✕ | ✓ | ✕ | ✓ | ✕ | ✓ | ✕ |
Query Functions | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✓ | ✕ |
Custom Backends | ✓ | ✕ | ✕ | ✕ | ✓ | ✕ | ✓ | ✕ | ✕ |
Fuzzy Search * | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ |
Size (kb) | 30 | 5 | 27 | 40 | 46 | 88 | 164 | 500 | 8 |
* Requires additional plugin not included in the bundle size shown in the table.
NanoSQL can save data to many different places, depending on the browser or environment it's being ran in.
Included In The Box
npm i @nano-sql/core --save
Using in Typescript/Babel project:
import { nSQL } from "@nano-sql/core";
Using in Node:
const nSQL = require("@nano-sql/core").nSQL;
To use directly in the browser, drop one of the tags below into your <head>
.
<!-- ES6 Only (Faster & Smaller) -->
<script src="https://cdn.jsdelivr.net/npm/@nano-sql/core@2.3.7/dist/nano-sql.min.js" integrity="sha256-W1pVgKda7GC4fwXqq9jfOrssBDJJXZqck+ultRPVzmc=" crossorigin="anonymous"></script>
<!-- ES5 (Internet Explorer/Old Browser Support) -->
<!-- Promise must be polyfilled as well -->
<script src="https://cdn.jsdelivr.net/npm/@nano-sql/core@2.3.7/dist/nano-sql.min.es5.js" integrity="sha256-1t9VlpFUgHaxlLQy6HM9ROQvTiuUv2M12Fp1oTh3+yg=" crossorigin="anonymous"></script>
If you are migrating from nanoSQL 1.X to 2.X, please read the migration guide.
// Persistent Database
nSQL().createDatabase({
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"
},
.....
]
*/
})
The nanoSQL command line interface allows you to compile data models into typescript interface files.
Usage is as follows:
nsql --outDir www --files file1.ts file2.ts... --watch
If you don't pass --watch
the CLI will compile the files into the given directory, then exit. You can also optionally pass --watchPolling
with an interval to enable polling on the watch system.
It's important to note the files must be formatted specifically for the CLI to read them correctly.
Each file should have an export named tables
that is an array of InanoSQLTableConfig
types. The file below is a working example:
import { InanoSQLTableConfig } from "@nano-sql/core/lib/interfaces";
export const tables: InanoSQLTableConfig[] = [
{
name: "users",
model: {
"id:uuid": {pk: true},
"age:float": {notNull: true},
"name:string[]": {default: []},
"properties:meta[]": {},
"address:obj": {
model: {
"street:string":{},
"city:string":{},
"zip:string":{},
"state:string":{}
}
},
"*:any": {}
}
}
];
export const types = {
meta: {
"key:string": {notNull: true},
"value:any": {notNull: true}
}
}
// using the above object in nSQL
import { nSQL } from "@nano-sql/core";
nSQL().createDatabase({
id: "my_db",
tables: tables,
types: types
}).then..
Assuming the above file is in the root directory of our project named index.ts, we could compile it to a typescript interface file with this command:
nsql --outDir www --files index.ts
The above command would produce the following file:
import { uuid, timeId, timeIdms } from "@nano-sql/core/lib/interfaces";
export interface ItableUsers {
id:uuid;
age:number;
name:string[];
properties?:ItypeMeta[];
address?:{
street?:string;
city?:string;
zip?:string;
state?:string;
};
[key: string]: any;
}
export interface ItypeMeta {
key:string;
value:any;
}
FAQs
Like Lego For Databases
We found that @nano-sql/core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.