1.0.4 • Published 4 years ago
granthaabc v1.0.4
Welcome to Grantha!
This is an API to connect with Grantha Server: https://db.mrsajjal.com
Grantha is a Database as a Service (DBaaS) platform developed by Sajjal Neupane https://mrsajjal.com
This API can be used to perform the following operation on Grantha Server!
- Create Records
- Read Records
- Search Records
- Update Records
- Remove Records
- Create Indexes
Installation
npm i grantha
Create a Record on a Collection
const db = require("grantha");
const token = "aab5feca1e9c2770f3a711efe2f2388d1614cb0afe3e04";
const record = {
token: token,
collection: "userInfo",
data: {
name: "John",
age: "20",
},
};
db.addData(record);
// Adds {name: "John", age: "20"} to the "UserInfo" collection
Get all Records from a Collection
const db = require("grantha");
const token = "aab5feca1e9c2770f3a711efe2f2388d1614cb0afe3e04";
const record = {
token: token,
collection: "userInfo",
};
db.getData(record);
// Returns all records from "UserInfo" collection
Search for Records on a Collection
const db = require("grantha");
const token = "aab5feca1e9c2770f3a711efe2f2388d1614cb0afe3e04";
const record = {
token: token,
collection: "userInfo",
data: {
age: "20",
},
};
db.searchData(record);
// Returns all mathching records where {age: "20"} from "UserInfo" collection
ProTip: You can use any MongoDB find() properties.
Update a Record on a Collection
const db = require("grantha");
const token = "aab5feca1e9c2770f3a711efe2f2388d1614cb0afe3e04";
const record = {
token: token,
collection: "userInfo",
id:"5f47f18ed1637ce1a3942f72",
data: {
name:"Henry"
age: "25",
},
};
db.updateData(record);
// Updates record with {id: "5f47f18ed1637ce1a3942f72"} from "UserInfo" collection
Remove a Record from a Collection
const db = require("grantha");
const token = "aab5feca1e9c2770f3a711efe2f2388d1614cb0afe3e04";
const record = {
token: token,
collection: "userInfo",
id:"5f47f18ed1637ce1a3942f72",
};
db.removeData(record);
// Removes record with {id: "5f47f18ed1637ce1a3942f72"} from "UserInfo" collection
Create an Index on a Collection
const db = require("grantha");
const token = "aab5feca1e9c2770f3a711efe2f2388d1614cb0afe3e04";
const record = {
token: token,
collection: "userInfo",
data:{
name:1
},
};
db.createIndex(record);
// Creates an Index on "UserInfo" collection with "name" sorted in ascending order.
Summary
Here is the summary of all the available functions:
Function | Input | Operation |
---|---|---|
addData() | token, collection_name, data-to-add | Creates a record on a Collection |
getData() | token, collection_name | Returns all records from a Collection |
searchData() | token, collection_name, data-to-search | Returns all the matching records from a Collection |
updateData() | token, collection_name, record-id, data-to-update | Updates record with given-id on a Collection |
removeRecord() | token, collection_name, record-id | Removes record with given-id from a Collection |
createIndex() | token, collection_name, index-info | Creates an Index based on index-info on a collection |
Note: Input must be a valid JSON.
With Love,
Sajjal
https://mrsajjal.com
https://github.com/sajjal