@allnulled/simplest-db
v1.0.3
Published
Small synchronous database implementation for node.js and browsers
Downloads
11
Maintainers
Readme
simplest-db
Small synchronous database implementation for node.js and browsers.
1. Installation
~$ npm i -s @allnulled/simplest-db2. How it works
This script works the same for node.js and browser.
What the script is thought for, is to be used as synchronous database for both javascript environments.
On the node.js side, it works with files and the require("fs") API.
On the browser side, it works with localStorage API.
3. Usage
3.1. Install:
In node.js you rely on require function and the node_modules of the npm.
In browser you need to import simplest-db.js by a script tag like:
<script src="/path/to/some/cdn/network/and/find/simplest-db.js"></script>If case you use webpack or browserify or some tool to pack your browser scripts, you can use import and require syntax too with "simplest-db" parameter.
3.2. Import:
In node.js:
const SimplestDB = global.SimplestDB || require("@allnulled/simplest-db");In browser:
const SimplestDB = window.SimplestDB;Note: the import syntax of ES6 will also work.
3.3. Create database:
const db = SimplestDB.create({
schema: "Unique schema id",
attributes: { /* custom schema attributes */ },
tables: {
fichero: {
attributes: { /* custom table attributes */ }.
columns: {
ruta: {
attributes: { /* custom column attributes */ },
is_type: "string",
}
}
}
}
});3.4. Insert into database:
db.insert("fichero", {
ruta: "/root/index.js",
contenido: "console.log('hi!!!')"
});3.5. Select from database:
db.select("fichero", f => {
return f.ruta && f.ruta.startsWith("/root/");
});3.6. Update from database:
db.update("fichero", 1, {
contenido: "console.log('bye!')"
});3.7. Delete from database:
db.delete("fichero", 1);4. Features
Some enjoyable features:
- Fully synchronous API.
- Browser (
localStorage) and node.js (require("fs")) support.
Some missing features:
- NO support for automatic column checkings, only for table checking. To do so, override
validateRowmethod.
4.1. Extra features
Since version 1.0.3, @allnulled/simplest-db comes with 2 extra APIs: Cache API and Filesystem API.
The Filesystem API:
- Included API for files at:
SimplestDB.getFS().- Contains a
SimplestDBinstance with"system"as schema (so:./sdb_modules/system.data.jsonorlocalStorage.SDB_STORAGE_FOR_system). - Accepts tables:
fs. - Accepts columns:
fs.path,fs.contents,fs.metadata.
- Contains a
The Cache API:
- Included API for cache at:
SimplestDB.getCache().- Contains a
SimplestDBinstance with"system"as schema too (so also:./sdb_modules/system.data.jsonorlocalStorage.SDB_STORAGE_FOR_system). - Accepts tables:
cache. - Accepts columns:
cache.key,cache.value.
- Contains a
5. License
No license.
6. Why?
To have another awesome javascript database. Synchronous. Light. Simpler.
