nano-sql1.8.3 • Public • Published
Super flexible database/datastore for the client, server & mobile devices.
NanoSQL is the smallest and quickest way to get SQL power into your app. You get tons of RDBMS perks like joins, groupby, functions and orderby with strong runtime type casting, events, IndexedDB support, transactions and an ORM.
Indexed DB, and
WebSQL in the browser, and
Level DB in NodeJS with the same API. The storage engine is automatically selected based on the browser/environment, or can be manually selected.
- Runs in Node, IE9+ & modern browsers.
- Supports all common RDBMS queries.
- Import and Export CSV/JSON.
- Simple & elegant undo/redo.
- Full Typescript support.
- Runtime type casting.
- Complete ORM support.
- Fast secondary indexes.
- Full events system.
NEW: Observable Queries
Use observables to subscribe to table changes and automatically update your views.
nSQL.observable.debounce1000 // dont trigger more than every second (optional).distinct // only trigger if the previous record doesn't match the next record to trigger (optional).filterrows.length // use a filter function to only emit changes based on provided fn. (optional).maprows // mutate the results (optional).first // only emit the first change (optional).skip10 // skip the first n elements (optional).take10 // only get the first n elements (optional).subscribe
NEW: Fuzzy Search
// first set which columns are indexednSQL"posts".model.connect.then....
|Latest ✔||Latest ✔||Latest ✔||Latest ✔||Latest ✔||9+ ✔|
Comparison With Other Projects
NanoSQL can save data to several different places, depending on the browser or environment it's being ran in.
Included In The Box
- Level DB
- Indexed DB
- Local Storage
npm i nano-sql --save
Using in Typescript/Babel project:
Using in Node:
const nSQL = nSQL;
To use directly in the browser, drop the tag below into your
1 minute minimal quick start:
// Use an instance table to query and organize existing tables of data.// Or declare database models and store data in nanoSQL, using it as a self contained RDBMS// "users" is our table name.// Init the data store for usage. (only need to do this once)
First you declare your models, connect the db, then you execute queries.
1. Declare Model & Setup
// Table/Store Name, required to declare model and attach it to this store.
2. Connect the DB and execute queries
// Initializes the db.;
Some examples of queries you can do.
// Listen for changes on the users table;// Listen for changes on any table;// Get all rows, only provide the "name" column.;// find all users who's name begins with "fr".// must have props: ["trie"] on the name column in the data model....// Select all users with the name "John".;// Use a function for WHERE;// Get rows based on the internal property of an object in the row;// Get all users with moe than 4 posts.;// Compound where statements, supports AND & OR;// Order results by name ascending, then age descending.;// Limit and offset are easy to use as well;// AS and aggregate functions also work.;// Mix and match as you like// Where statements can't use AS aliases// But order by does!
And here are some more advanced query examples.
// Relatively simple join// Group By also works// Multiple group bys aren't a problem!// Having uses the same syntax as WHERE, but runs after the GROUP BY command.// Look mah, I used every feature!
The Undo/Redo system is super easy to use. First, enable it in the config object.
Then use it! Every query that changes row data will be tracked as a history point.
// Roll the database back one query.;// Roll it forward one query.;// Delete all history points// Get the status of the history system;
Writes are quite a bit slower when the history system is used, and your database takes up more space. You can disable the history system from being activated by not calling
history in the config object.
nanoSQL is an OPEN Open Source Project. This means that:
Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
Read more details here.
Copyright (c) 2017 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.
- level DB
- Indexed DB