Database in JSON format is simple and fast, and you can read data from one project to another and supports data encryption if you want it and many distinct functions
Package Exports
st.db
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (st.db) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Database in JSON format is simple and fast, and you can read data from one project to another and supports data encryption if you want it and many distinct functions
Features
It contains valuable and useful methods
Strong intelligence in reading, recording and analyzing data
Simple and Easy To get started
Multiple JSON Files
There are more than one mode and you can switch between them
can I switch data from file to file
Supports data encryption mode which enables you to encrypt data
Supports data encryption mode if you want it
Methods are strict
Supports moving Quick.DB data to ST.db data file
System for reading data from one project to another
Increase in performance and increase in reading and writing
Supports filters
Getting Started
You can start install the package on your project:
npm i st.db
You can update to a newer version to receive updates using npm.
npm update st.db@latest
Then Start define it like this:
const Database =require('st.db')const db =newDatabase('FileName')//You can write the name you want
Important Notes
For the Database class, you can pass in a parameter to set a file rather than using the default file!
If the file dosen't exist, it will create it
How do I turn on data encryption mode?
Now your data is encrypted in ST.db
An example of a method for operating an encryption mode and reading encrypted data
const Database =require('st.db')const db =newDatabase(`FileName`,{encrypt:true})
Notes for encryption mode
If you activate the encryption mode, then data is recorded encrypted and when fetching it, it is decrypted
Data is not encrypted as true / false
One of the strongest encryption types is the aes-256-gcm encryption type we are using
If it is in old data and this data is not encrypted, then there is no problem, and it will read normal. And if you are locked, encrypted and there is encrypted data, then it will be decrypted and read is normal.
Moving Quick.DB data to ST.db data file
const Database =require('st.db')const db =newDatabase(`FileName`)const quickdb =require("quick.db");
db.importFromQuickDB(quickdb)
Note! The sql format is converted to json format so that it can be fully stored and used in our data
Log Mode
To know in console everything is added to the data
const Database =require('st.db')const db =newDatabase(`FileName`,{log:true})
const Database =require('st.db');const guilds =newDatabase('guilds-data');const users =newDatabase('users-data');// switch data from users-data to guilds-data
guilds.transferDB(users)
How to transfer data from file to file ?
Example
const Database =require('st.db');const guilds =newDatabase('guilds-data.json');const users =newDatabase('users-data.json');// Data is transferred from users to guilds
guilds.overwrite(users.load())
Data reading system in more than one place
API mode
const Database =require('st.db')const db =newDatabase(`FileName.json`,{api:true//If you want to create an API for your data, normal mode it is not enabled})
The data you record is stored in your own api, and the api is like that
http://localhost/Filename.json
localhost Type in the URL for your project
Filename Type the filename without the folder extension and without the json syntax
https://YouName.ProjectName.repl.co/Filename.json
Here is an example URL for repl it
How can I read data in another project?
Very simply, you are now data that has become an api, which you can read what is in it using the node-fetch or got package
Sets a value to the specified key on the database!
Parameters:
Name
Type
Description
key
string
The key to set.
value
all types
The value to set on the key.
Examples
db.set(`login`,true)
db.set('Profile',{name:"Shuruhatik#0001",id:742070589212327947});/* Profile: {name: "Shuruhatik#0001", id: 742070589212327947}
*/var example1 =['eg','ps']
db.set('Array', example1);/* example1: ['eg', 'ps'] *///It deletes all data and writes the statement you want with the knowledge that it is written directly without adding {}
db.overwrite({name:'Mohamed'});
Fetches the data from database!
Parameters:
Name
Type
Description
key
string
Key
Examples
db.get('profile');// Get the value of the data
db.fetch('data');// Fetches the value of the data// It fetches a value from an object/*"1":{age:15,name:`shuruhatik`}*/
db.objectFetch('1','age');// "15"
Fetches everything and sorts by given target
Parameters:
Name
Type
Description
key
string
The key to set.
Examples
db.includes("tes");// It fetches the values containing this value
db.startsWith("te");// It fetches values starting with this value
db.endsWith("st");// It fetches values ending with this value
Set, get, delete and control the array in the database
Parameters:
Name
Type
Description
key
string
The key to set.
value
Value to push.
Examples
//"hello":[2020]//It sets at the end
db.push(`hello`,2021)// "hello":[2020,2021] //Iteratively deletes the value from the array
db.push(`hello`,2020)// "hello":[2021]//It sets at the start
db.unshift(`hello`,2019)//"hello":[2019,2020,2021]//It removes the first value from the array
db.shift(`hello`)//"hello":[2020,2021]//It removes the last value from the array
db.pop(`hello`)//"hello":[2019,2020]// It fetches an element from the array by the format number/* Array: ['element', 'element2', 'element3'] */
db.arrayFetch('Array',1);/* element2 */
Deletes a key from the database!
Parameters:
Name
Type
Description
key
string
The key to delete.
Examples
// Removing something from an array using value/index
db.remove('Array','element3');// Deletes each data that starts with the given parameter
db.deleteEach('data');
Delete's all of the data from the database!
Parameters:
Name
Type
Description
ops
object
Clear options.
Examples
db.clear();// Clears everything from the database
db.destroy();// Delete the database file (And Clear All Data)
Returns everything from the database
Parameters:
Name
Type
Description
limit
number
Define a limit on the values that reads
ops
All options
Examples
//Returns everything from the database
db.all();|| db.fetchAll()
db.all(5);|| db.fetchAll(5)//You can select the number you want to read//Return everything from the database and decrypt the data that is required if you are using an encryption mode
db.decryptAll()//Return all values from the database
db.valuesAll()//Return all keys from the database
db.keysAll()
Does a math calculation and stores the value in the database!
Parameters:
Name
Type
Description
key
string
The key to set.
operator
string
One of +, -, %, * or /
value
number
The value, must be a number.
Examples
db.math("coins","+",100)// To subtract from value
db.subtract("coins",50)// To add from value
db.add("coins",50)// To multiply from value
db.multiply("coins",2)//To double from value
db.double("coins")
Checks if there is a data stored with the given key
db.type("coins")//To find out the type of value written in the data
Find out the size of the database file
Parameters:
Name
Type
Description
ops
object
Size options.
Examples
db.size()//To find out the size of the data file in byte
db.size('KB')//To find out the size of the data file in kb
db.size('MB')//To find out the size of the data file in mb//Example
console.log(db.size(`MB`))
Encrypt and decrypt a value of the same type
Parameters:
Name
Type
Description
key
string
Key
Examples
db.encryptValue(`st.db`);// To encrypt a desired value
db.decryptValue(`2b53892389af2e4df96174f48b7bf2c0080337b52e33ec95532f72ad85b9d968c077e4cb247f0f7a47db1dbf4136c9cf9dd2d3df6375781f7d1c26f2b55c808a04d);// To decrypt a desired value