Database supports json and yaml, fast, accurate, various advantages, and there are encryption features to increase security and more features
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.
Readme
What is ST.db?
Database supports json and yaml, fast, accurate, various advantages, and there are encryption features to increase security and more features
Features
It contains valuable and useful methods
Strong intelligence in reading, recording and analyzing data
Simple and Easy To get started
Multiple JSON or YAML 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
You can start install the package on your project:
npm install st.db
yarn add st.db
pnpm add st.db
Then Start define it like this:
Example :JSON
const Database =require('st.db')const db =newDatabase({path:'FileName.json'})//You can write the name you want
Example :YAML
const Database =require('st.db')const db =newDatabase({path:'FileName.yaml'})//You can write the name you want
Important Notes
Note that you can write the file extension or you can write the file name without the extension and in both cases it will be recognized from the data easily
If the file dosen't exist, it will create it
In the event that you store more than 50 objects per millisecond, it is recommended to use await before any action
Example to prevent pressure, if there is pressure or without pressure, you can use it
// set`await db.set({key:'Array',value:['eg','ps']});// get
console.log(await db.get({key:'Array'}))
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({path:'FileName.json',crypto:{encrypt:true,password:"shuruhatik"}})
Notes for encryption mode
Note in the event that you do not activate the encryption feature, the data will be recorded directly unencrypted, and when you activate the encryption mode, the data will be encrypted when recording
password It is an important thing in the event that you forgot the password or changed the password, the data recorded with this password could not be read and you must set the correct password
Supports object and array encrypting now
If you do not enter a specific password, the default password will be st.db
Moving Quick.DB data to ST.db data file
const Database =require('st.db')const db =newDatabase({path:'FileName.yml'})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
Debug Mode
To know in console everything is added to the data
const Database =require('st.db')const db =newDatabase({path:'FileName.json',debug:true})
const Database =require('st.db');const guilds =newDatabase({path:'guilds-data'});const users =newDatabase({path:'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({path:'guilds-data.json'});const users =newDatabase({path:'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({path:'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
db.get({key:'profile'});// Get the value of the data
db.fetch({key:'data'});// Fetches the value of the data
db.getByKey({key:'profile'});//It reads the item with its key
db.getByValue({value:true});//You read all the data by its value// It fetches a value from an object/*"1":{age:15,name:`shuruhatik`}*/
db.objectFetch({object:'1',key:'age'});// "15"
Fetches everything and sorts by given target
Parameters:
Name
Type
Description
key
string
The key to set.
Examples
db.includes({key:"tes"});// It fetches the values containing this value
db.startsWith({key:"te"});// It fetches values starting with this value
db.endsWith({key:"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({key:`hello`,value:2021})// "hello":[2020,2021] //Iteratively deletes the value from the array
db.unpush({key:`hello`,value:2020})// "hello":[2021]//It sets at the start
db.unshift({key:`hello`,value:2019})//"hello":[2019,2020,2021]//It removes the first value from the array
db.shift({key:`hello`})//"hello":[2020,2021]//It removes the last value from the array
db.pop({key:`hello`})//"hello":[2019,2020]// It fetches an element from the array by the format number/* Array: ['element', 'element2', 'element3'] */
db.arrayFetch({array:'Array',length: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({key:'Array'});// Deletes each data that includes the given parameter
db.deleteEach({key:'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/*
=> Example
[
{ ID: 'coins', data: 12, typeof: 'number', _v: 0 },
{ ID: 'name', data: 'Shuruhatik', typeof: 'string', _v: 1 }
]
*///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({key:"coins",operator:"+",value:"100",goToNegative:false})// To subtract from value
db.subtract({key:"coins",value:50})// To add from value
db.add({key:"coins",value:50})// To multiply from value
db.multiply({key:"coins",value:2})//To double from value
db.double({key:"coins"})
Checks if there is a data stored with the given key
db.encryptString(`st.db`);// To encrypt a desired value
db.decryptString('83b3031fedd8774b37b5745774be8d1b:744242457637733d');// To decrypt a desired value