It helps you to store files inside the project or outside the project in YML and JSON formats in shapes such as objects or maps
Package Exports
st.db
st.db/index.js
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?
It helps you to store files inside the project or outside the project in YML and JSON formats in shapes such as objects or maps
Features
It contains valuable and useful methods
Strong intelligence in reading, recording and analyzing data
Simple and Easy To get started
You can store the data in the form of an Object or a Map, as you wish
Multiple JSON or YAML Files
You can store, write and read JSON and YAML files outside the project
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
CommonJS
const Database =require('st.db')
ESM
import Database from'st.db';
Then Start define it like this:
Example :JSON
const db =newDatabase({path:'FileName.json'})//You can write the name you want
Example :YAML
const db =newDatabase({path:'FileName.yml'})//You can write the name you want
What are the features of maps in the database?
A Map does not contain any keys by default. It only contains what is explicitly put into it.
A Map's keys can be any value (including functions, objects, or any primitive).
The keys in Map are ordered in a simple, straightforward way: A Map object iterates entries, keys, and values in the order of entry insertion.
Performs better in scenarios involving frequent additions and removals of key-value pairs.
A Map is an iterable, so it can be directly iterated.
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
// setawait 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
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})
Store data as objects
If you want to store data in the form of objects, but note that if this option "databaseInObject" is not enabled, then the normal situation for data is that it is stored in the form of MAPS because it contains more features, but if you want to store in the form of objects, there is no objection
import Database from'st.db';const db =newDatabase({path:'FileName.json',databaseInObject:true//This option must be enabled if you want to store as objects})
import Database from'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
import Database from'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
import Database from'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
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
Database in files from outside the work project
This option is in the event that you want to store or read in a file inside a hard disk other than the one you are using or even outside the folder you are running, so you can in ST.db control it in a file outside your main project if you want
If you activate the "pathOutsideTheProject" option, you will be able to type any path from your computer in the "path" option.
const db =newData({path:"C:/Users/pc/Desktop/database.yml",pathOutsideTheProject:true//You must activate this option in order for the volume to understand that you want to store this path while it is outside the project})
Events
Events help you know the value of something when a specific event occurs
Data connection event
Parameters:
Name
Type
Description
value
object
Information about your Database settings.
Examples
db.on('isReady',(database)=>{
console.log(`The data is working successfully`)
console.log(database)})
Add an value in the data
Parameters:
Name
Type
Description
value
object
Information about the added value.
Examples
db.on('addElement',(data)=>{
console.log(`Key => ${data.key}`)// Key => test
console.log(`Value => ${data.value}`)// Value => true})
db.set({key:'test',value:true})
Read a value by Element
Parameters:
Name
Type
Description
value
object
Information about the value that was read.
Examples
db.on('getElement',(data)=>{
console.log(`Key => ${data.key}`)// Key => test
console.log(`Value => ${data.value}`)// Value => true})
db.get('test')
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({key:"age",value:16})// or
db.set({key:{id:"742070589212327947",uuid:"a4s7-4qw7-rq84-5fsd"},value:16})// or
db.set([{key:"age",value:16},{key:"name",value:"mohamed"}])
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]
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'});//or
db.delete({key:'Array'});
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
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
console.log(db.OldToNewDatabase("./user.json"))/*
Example return :
Map {
user' => {
id: [ '45451' ],
name: [ 'Mohamed' ],
admin: [ 'true' ]
}
}
*///In case you want to set old items in st.db maps
db.overwrite(db.OldToNewDatabase("user.json"))
console.log(db.fileSize())//To know the file size and details about it
console.log(db.size)// If you want to know the number of registered items/*
Example
=> { byte: 36, megaBytes: 0.000034332275390625, kiloBytes: 0.03515625 }
*/
Reload the data in the database
db.reload()
Encrypt and decrypt a value of the same type
Parameters:
Name
Type
Description
key
string
Key
Examples
db.encryptString(`st.db`);// To encrypt a desired value
db.decryptString('83b3031fedd8774b37b5745774be8d1b:744242457637733d');// To decrypt a desired value
Example usage
Example Bot With Discord.js v13
const Database =require('st.db');const{ Client, Intents }=require('discord.js');const client =newClient({intents:[Intents.FLAGS.GUILDS]});const db =newDatabase({path:'FileName.yml'});
client.db = db;
client.on('ready',()=>{
console.log(`Database size is => ${client.db.fileSize().byte} byte!`);
client.db.set({key:client.user,value:"Ready to use"})});
client.login('token');
Example Bot With Eris
const Database =require('st.db');const Eris =require("eris");const bot =newEris("Bot TOKEN");const db =newDatabase({path:'FileName.yml'});
bot.on('ready',()=>{
console.log(`Database size is => ${bot.db.fileSize().byte} byte!`);
db.set({key:bot.user,value:"Ready to use"})});
bot.connect();