7.0.2 • Published 9 months ago

st.db v7.0.2

Weekly downloads
-
License
CC BY-NC-ND 4.0
Repository
github
Last release
9 months ago

About

What is ST.db?

  • 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

Installation

You can start install the package on your project:

npm install st.db@beta
yarn add st.db@beta

Then Start define it like this:

const Database = require('st.db')
const db = new Database({path:'FileName.json'})//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 encrypt
  • An example of a method for operating an encryption mode and reading encrypted data
const Database = require('st.db')
const db = new Database({
  path:'FileName.json',
  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 = new Database({path:'FileName.json'})
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 = new Database({
   path:'FileName.json',
   log: true
})

Multiple Files

  • Example
const Database = require('st.db');

const bot = new Database({path:'bot.json'});
const servers = new Database({path:'servers.json'});
const users = new Database({path:'users.json'});

servers.set({
  key: 'guilds',
  value: '800060636041314375'
}); 
bot.set({
  key:'prefix',
  value: '$'
});
users.set({
  key:'blacklist_742070589212327947',
  value: true
}); 

How can I switch data from file to file ?

  • Example
const Database = require('st.db');

const guilds = new Database({path:'guilds-data'});
const users = new Database({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 = new Database({path:'guilds-data.json'});
const users = new Database({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 = new Database({
  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
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:

NameTypeDescription
keystringThe key to set.
valueall typesThe value to set on the key.

Examples

db.set({
 key:'Profile',
 value:{name: "Shuruhatik#0001", id: 742070589212327947}
}); /* Profile: {name: "Shuruhatik#0001", id: 742070589212327947}*/

db.set({
 key:'Array',
 value:['eg', 'ps']
}); /* Array: ['eg', 'ps'] */

Fetches the data from database!

Parameters:

NameTypeDescription
keystringKey

Examples

db.get({key:'profile'}); // Get the value of the data
db.fetch({key:'data'}); // Fetches the value of the data

// 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:

NameTypeDescription
keystringThe 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:

NameTypeDescription
keystringThe key to set.
valueValue 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:

NameTypeDescription
keystringThe 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:

NameTypeDescription
opsobjectClear 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:

NameTypeDescription
limitnumberDefine a limit on the values ​​that reads
opsAll 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:

NameTypeDescription
keystringThe key to set.
operatorstringOne of +, -, %, * or /
valuenumberThe 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

Parameters:

NameTypeDescription
keystringKey.

Returns:

Examples

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:

NameTypeDescription
keystringKey.

Returns:

Examples

db.type({key:"coins"})//To find out the type of value written in the data

Find out the size of the database file

Parameters:

NameTypeDescription
opsobjectSize 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`))
//or
console.log(db.size)

Encrypt and decrypt a value of the same type

Parameters:

NameTypeDescription
keystringKey

Examples

db.encryptValue(`st.db`); // To encrypt a desired value
db.decryptValue(`2b53892389af2e4df96174f48b7bf2c0080337b52e33ec95532f72ad85b9d968c077e4cb247f0f7a47db1dbf4136c9cf9dd2d3df6375781f7d1c26f2b55c808a04d); // 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 = new Client({ intents: [Intents.FLAGS.GUILDS] });
const db = new Database({path:'FileName.json'});
client.db = db;

client.on('ready', () => {
  console.log(`Database size is => ${client.db.size}byte!`);
  client.db.set({key:`botready`,value:true})
});

client.login('token');

Example Bot With Eris

const Database = require('st.db');
const Eris = require("eris");
const bot = new Eris("Bot TOKEN");
const db = new Database({path:'FileName.json'});

bot.on('ready', () => {
  console.log(`Database size is => ${bot.db.size} byte!`);
  db.set({key:`botready`,value:true})
});

bot.connect(); 

Contact

Any bug or suggestion !

Server Support

License

7.0.0

9 months ago

7.0.4

9 months ago

7.0.3

9 months ago

7.0.2

9 months ago

7.0.1

9 months ago

7.0.5

9 months ago

6.0.1

1 year ago

6.0.0

1 year ago

5.1.4

2 years ago

5.1.3

2 years ago

5.1.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.0.7

2 years ago

4.0.6

2 years ago

4.0.5

2 years ago

4.0.4

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

3.3.1

2 years ago

3.3.0

2 years ago

3.2.5

3 years ago

3.2.2

3 years ago

3.2.4

3 years ago

3.2.3

3 years ago

3.2.1

3 years ago

3.2.0

3 years ago

2.1.4

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

1.0.9

3 years ago

2.0.0

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago