Skip to content

Latest commit

 

History

History
272 lines (202 loc) · 10.2 KB

newREADME.md

File metadata and controls

272 lines (202 loc) · 10.2 KB

NoSQL Everywhere

nanoSQL Logo

npm TSlint npm downloads

NPM

NanoSQL is a database abstraction layer that:

  1. Makes running noSQL a breeze anywhere (NodeJS / Browser / Cordova / React Native / Electron).
  2. Lets you scale faster by moving query logic to your application server.
  3. Supports many advanced features like ORM, Map/Reduce, Indexing, Geolocations and Fuzzy Search.

Identical API Everywhere

Develop your application with a simple database like LevelDB, then deploy into production with Redis, Google Cloud Datastore, 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.

Automate NoSQL Housekeeping

NanoSQL includes a full ORM system, secondary indexes, Map/Reduce, fuzzy document search and denormalization helpers to make high performance data modeling simple and easy.

Not Only NoSQL

Classical RDBMS queries like aggregate functions, joins and group bys are also supported.

Flexible Data Models

The best of both worlds: Use RDBMS style data models to tune performance but still allow arbtrary columns. Change your data model as often as you want and do type casting only when you need it.

Other Cool Things

Built in geolocation helpers, undo/redo, multi-tab sync, automatic live backups, typescript support, full event system, CSV/JSON import & export, and runs in every browser back to IE9!

Wait a second, how can all these features be isomorphic and work with simple databases like Redis, LevelDB and LocalStorage?

NanoSQL treats every database backend it uses as nothing more than a key/value store; all features are built ontop of that assumption alone. If it's atleast a key/value store nanoSQL can run ontop of it with no feature loss. For example, secondary indexes are always implemented as a seperate table that acts as an inverted index (even in something like MySQL). Secondary index reads then involve two seperate reads: one of the inverted index table then another from the actual data table. Since both of these reads are jumping directly to keys in the key/value stores or primary keys in RDBMS backends the reads are crazy fast and remain fast regardless of the table sizes. If you avoid full table scans nanoSQL's reads are almost always orders of magnitude faster than sending similar queries to the database it's sitting ontop of.

Browser Support

Chrome Firefox Safari Opera Edge IE
Latest ✔ Latest ✔ Latest ✔ Latest ✔ Latest ✔ 9+ ✔

Database Support

NanoSQL can save data to many different places, depending on the browser or environment it's being ran in.

  1. Included In The Box

    • Memory
    • Level DB
    • Indexed DB
    • WebSQL
    • Local Storage
  2. SQLite (NodeJS)

  3. SQLite (Cordova)

  4. MySQL

  5. React Native

  6. Redis

  7. Google Cloud Datastore

  8. Trival DB (JSON File Store)

Documentation

Installation

npm i nano-sql --save

Using in Typescript/Babel project:

import { nSQL } from "nano-sql";

Using in Node:

const nSQL = require("nano-sql").nSQL;

To use directly in the browser, drop the tag below into your <head>.

<script src="https://cdn.jsdelivr.net/npm/nano-sql@1.4.5/dist/nano-sql.min.js"></script>

Quick Start

Organize or filter existing arrays of row data:

nSQL([
    {name: "bill", age: 20},
    {name: "bob",  age: 25},
    {name: "jeb",  age: 27}
]).query("select", ["name", "MAX(age) AS age"]).exec().then((rows) => {
    console.log(rows); // <= [{name: "jeb", age: 27}]
})

Use as a database:

nSQL('users') //  "users" is our table name.
.model([ // Declare data model
    {key: 'id',   type: 'uuid', props:['pk']}, // pk == primary key,
    {key: 'name', type: 'string'}, // name column, string
    {key: 'age',  type: 'int'}, // age column, integer
    {key: '*',    type: '*'} // allow any other columns of any type
])
.config({ // set configuration options (only need to do this once)
    id: "KSP"
})
.connect() // Init the data store for usage. (only need to do this once)
.then((result) => {
    return nSQL("users").query("upsert", { // Add a record
        name:"bill", 
        age: 20, 
        somethingElse: "yo"
    }).exec();
})
.then((result) => {
    return nSQL("users").query("select").exec(); // select all rows
})
.then((result) => {
    console.log(result) // <= [{id:"93716b41-7e71-4c55-bf5e-bd1cf09416c9", name:"bill", age: 20, somethingElse: "yo"}]
})

Documentation

Feature Highlight (Open To See Details)

All features are universal/isomorphic and work with any database adapter.

Advanced Document Search

Have lots of data that needs searching? Many concepts have been taken from Apache Solr/ElasticSearch then streamlined and implimented in nanoSQL.

example code

ORM (Object Relation Mapping)

Just because we're running No-SQL doesn't mean we can't have relationships.

example code

Observables

Use the observable pattern to wire your application views to database queries with ease.

example code

Multi Tab Support

Want two browser tabs to remain in sync? With a single config change nanoSQL can keep two tabs in perfect sync.

example code

Denormalization & Map/Reduce

Get the performance advantages of No-SQL without the housework. Just let nanoSQL know when and where you want your data and it takes care of the rest.

example code

Geolocation Helpers

Need to find which retail store your client is closest to? nanoSQL can do it in no time at all.

example code

Import / Export

It's easy to move CSV and JSON data into and out of nanoSQL.

example code

History (Undo / Redo)

NanoSQL can keep track of changes to your data so you can scrub back and forth through time.

example code

Live Backups

NanoSQL can optionally write to any number of database backends at the same time. This allows you to have always accurate, in place backups of your data.

example code

Events

Want to know when something is happening? Just ask!

example code

SQL Commands

Want to do a join with a group by and a query function? No problem!

example code

Documentation

Help

Contributing

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.

MIT License

Copyright (c) 2018 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.