skbase-client v1.0.2
SkBase Client
Project
This project was created with the intent to make MySql query's more easier. Inspired by Firebase i decided to create something like it, so, SkBase was built! You can see the documentation right after installation.
Installation
#npm
npm install --save skbase-client
#yarn
yarn add skbase-client
Documentation
// CommonJS
const skbase = require("skbase-client");
// ES6
import skbase from "skbase-client";
List of functionabilities
Initialize App
skbase.initializeApp(...);
Initializes the app, so then you can start programming.
Required Options:
url
: The hosted server url.
Datastore
const db = skbase.datastore();
Get the registered database
Table
const table = db.table("NAME");
Get the mentioned table on database
const table = db.table("NAME").limit(10);
// or
const table = db.table("NAME").orderBy("COLUMN");
//or
const table = db.table("NAME").limit(10).orderBy("COLUMN");
On this you can execute after table limit
or orderBy
for creating something more specific.
Requires:
NAME
: The table name
Table On
table.on("EVENT_NAME", function (event) {
// ...
});
This is an event listner, at moment just for snapshots.
Requires:
EVENT_NAME
: The event name, you can see right below
Events:
snapshot
: Listen to every database changes
Table Add
table.add(...).then((response) => {
console.log(response); // Added response
});;
This is for adding a new document on current table Requires the rows you want to add on database.
Table Where
table.where("PARAMETER", "CONDITIONAL", "VALUE");
Selects specific document(s) on table based on PARAMETER
, CONDITIONAL
and VALUE
Requires:
PARAMETER
: The database columnCONDITIONAL
: The conditional for parameter on valueVALUE
: The value to be conditionaly to the parameter
List of conditionals:
==
: Equal to.!=
: Not equal to.<
: Less than.>
: Greater than.<=
: Less than or equal to.>=
: Greater than or equal to.
Table Where Get
table
.where("PARAMETER", "CONDITIONAL", "VALUE")
.get()
.then((response) => {
console.log(response); // Document response
});
With the document(s) selected by where
, you can get the document(s) data with get
Table Where Update
table.where("PARAMETER", "CONDITIONAL", "VALUE").update(...).then((response) => {
console.log(response); // Update response
});
With the document(s) selected by where
, you can rewrite the document(s) data with update
.
Required the rows you want to rewrite.
Table Where Delete
table
.where("PARAMETER", "CONDITIONAL", "VALUE")
.del()
.then((response) => {
console.log(response); // Update response
});
With the document(s) selected by where
, you can delete the document(s) with del
Full Example
import skbase from "skbase-client";
skbase.initializeApp({ url: "..." }); // Starting application
const store = skbase.datastore();
const table = store.table("users");
// Adding new Document
table.add({ id: 1523, username: "Felps" }).then((response) => {
console.log(response);
});
// Getting Document
table
.where("username", "==", "Owl")
.get()
.then((response) => {
console.log(response);
});
// Updating Document
table
.where("id", "==", "3")
.update({ username: "Lucas" })
.then((response) => {
console.log(response);
});
// Deleting Document
table
.where("id", ">=", "42")
.del()
.then((response) => {
console.log(response);
});
// Getting the snapshots
table.on("snapshot", (data) => {
console.log(data);
});
License
- See LICENSE