What is ST.db.online?
- Database online is fast and simple. You can read and write data with it in more than one project
Features
- Database online is fast and simple.
- You can read and write data with it in more than one project
- There are more than one mode and you can switch between them
- 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 @online/ST.db data file
- Increase in performance and increase in reading and writing
- Supports filters
- Data encryption with custom password
Content
Getting Started
Installation
You can start install the package on your project:
npm install st.db.online
yarn add st.db.online
pnpm add st.db.online
Then Start define it like this:
const Database = require('st.db.online')
const db = new Database({uuid:'Enter the UUID of your Database'})
import Database from 'st.db.online';
const db = new Database({uuid:'Enter the UUID of your Database'})
→ How to create your own UUID
Important Notes
- Before any method you must use
await
or rely on .then
// set
await db.set({ key:'Array', value:['eg', 'ps'] });
// get
db.set({ key:'Array', value:['eg', 'ps'] }).then(()=> console.log("Done").catch(console.error)
How to create your own UUID
- you should know that creating a UUID is completely free, but each person has a maximum UUID creation limit of 5.
- First, you must join the Discord server by clicking here
- Go to the #commands channel and type
/create_database
- To see your UUIDS do this command
How do I turn on data encryption mode?
- Now your data is encrypted in st.db.online
- An example of a method for operating an encryption mode and reading encrypted data
const Database = require('st.db.online')
const db = new Database({
uuid:'Enter the UUID of your Database',
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.online data file
const Database = require('st.db.online')
const db = new Database({uuid:'Enter the UUID of your Database'})
const quickdb = require("quick.db");
db.importFromQuickDB(quickdb).then(data => console.log(data))
Note!
The sql format is converted to json format so that it can be fully stored and used in our data
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}).then(data => console.log(data))
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').then(data => console.log(data))
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
await db.set({
key:'Profile',
value:{name: "Shuruhatik#0001", id: 742070589212327947}
}); /* Profile: {name: "Shuruhatik#0001", id: 742070589212327947}*/
await db.set({
key:'Array',
value:['eg', 'ps']
}); /* Array: ['eg', 'ps'] */
Fetches the data from database!
Parameters:
Name | Type | Description |
---|
key | string | Key |
Examples
db.get({key:'profile'}).then(data => console.log(data)); // Get the value of the data
db.fetch({key:'data'}).then(data => console.log(data)); // Fetches the value of the data
db.getByKey({key:'profile'}).then(data => console.log(data));//It reads the item with its key
db.getByValue({value:true}).then(data => console.log(data)); //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'}).then(data => console.log(data));// "15"
Fetches everything and sorts by given target
Parameters:
Name | Type | Description |
---|
key | string | The key to set. |
Examples
db.includes({key:"tes"}).then(data => console.log(data));// It fetches the values containing this value
db.startsWith({key:"te"}).then(data => console.log(data));// It fetches values starting with this value
db.endsWith({key:"st"}).then(data => console.log(data));// 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
await db.push({
key:`hello`,
value:2021
})// "hello":[2020,2021]
//Iteratively deletes the value from the array
await db.unpush({
key:`hello`,
value:2020
})// "hello":[2021]
//It sets at the start
await db.unshift({
key:`hello`,
value:2019
})//"hello":[2019,2020,2021]
//It removes the first value from the array
await db.shift({
key:`hello`
})//"hello":[2020,2021]
//It removes the last value from the array
await db.pop({
key:`hello`
})//"hello":[2019,2020]
// It fetches an element from the array by the format number
/* Array: ['element', 'element2', 'element3'] */
await 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
await db.remove({key:'Array'});
// Deletes each data that includes the given parameter
await db.deleteEach({key:'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
await db.all(); || await db.fetchAll()
await db.all(5); || await 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
await db.decryptAll()
//Return all values from the database
await db.valuesAll()
//Return all keys from the database
await 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
await db.math({
key:"coins",
operator:"+",
value:"100",
goToNegative:false
})
// To subtract from value
await db.subtract({key:"coins", value:50})
// To add from value
await db.add({key:"coins", value:50})
// To multiply from value
await db.multiply({key:"coins", value:2})
//To double from value
await db.double({key:"coins"})
Checks if there is a data stored with the given key
Parameters:
Name | Type | Description |
---|
key | string | Key. |
Returns:
Examples
await db.has({key:"coins"})//Returns "true" or "false" if the database has the data or not.
Return's the value type of the key!
Parameters:
Name | Type | Description |
---|
key | string | Key. |
Returns:
Examples
await db.type({key:"coins"})//To find out the type of value written in the data
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.online');
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const db = new Database({uuid:'Enter the UUID of your Database'});
client.db = db;
client.on('ready', async() => {
console.log(`Database is Ready to use!`);
await client.db.set({key:`botready`,value:true})
});
client.login('token');
Example Bot With Eris
const Database = require('st.db.online');
const Eris = require("eris");
const bot = new Eris("Bot TOKEN");
const db = new Database({uuid:'Enter the UUID of your Database'});
bot.on('ready', async() => {
console.log(`Database is Ready to use!`);
await db.set({key:`botready`,value:true})
});
bot.connect();
Contact
Any bug or suggestion !
Server Support
License