@onurege3467/zerohelper 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/database/index.js +9 -0
- package/database/jsondatabase/index.js +127 -0
- package/database/mongodb/index.js +49 -0
- package/database/mongodb/src/client/Client.js +37 -0
- package/database/mongodb/src/structers/Collection.js +136 -0
- package/database/mongodb/src/structers/Data.js +228 -0
- package/database/mongodb/src/structers/Database.js +53 -0
- package/database/mongodb/src/tools/FormatTool.js +5 -0
- package/database/mysql/examples/example.js +301 -0
- package/database/mysql/index.js +1 -0
- package/database/mysql/structures/classes/MySQL.js +37 -0
- package/database/mysql/structures/errors/strings.js +23 -0
- package/database/mysql/structures/methods/add.js +21 -0
- package/database/mysql/structures/methods/all.js +24 -0
- package/database/mysql/structures/methods/auto_increment.js +13 -0
- package/database/mysql/structures/methods/base_get.js +12 -0
- package/database/mysql/structures/methods/base_set.js +13 -0
- package/database/mysql/structures/methods/clear.js +15 -0
- package/database/mysql/structures/methods/connect.js +15 -0
- package/database/mysql/structures/methods/create.js +11 -0
- package/database/mysql/structures/methods/create_db.js +10 -0
- package/database/mysql/structures/methods/delete.js +24 -0
- package/database/mysql/structures/methods/drop.js +13 -0
- package/database/mysql/structures/methods/end.js +7 -0
- package/database/mysql/structures/methods/exists.js +13 -0
- package/database/mysql/structures/methods/get.js +40 -0
- package/database/mysql/structures/methods/has.js +40 -0
- package/database/mysql/structures/methods/includes.js +13 -0
- package/database/mysql/structures/methods/ping.js +11 -0
- package/database/mysql/structures/methods/process.js +7 -0
- package/database/mysql/structures/methods/pull.js +19 -0
- package/database/mysql/structures/methods/push.js +20 -0
- package/database/mysql/structures/methods/query.js +9 -0
- package/database/mysql/structures/methods/rename.js +16 -0
- package/database/mysql/structures/methods/set.js +48 -0
- package/database/mysql/structures/methods/stats.js +10 -0
- package/database/mysql/structures/methods/sub.js +21 -0
- package/database/mysql/structures/methods/tables.js +8 -0
- package/database/mysql/structures/methods/variables.js +20 -0
- package/database/test.js +37 -0
- package/functions/functions.js +47 -0
- package/index.js +7 -0
- package/package.json +29 -0
- package/readme.md +91 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const errors = require('../errors/strings.js');
|
|
4
|
+
|
|
5
|
+
module.exports = async function(){
|
|
6
|
+
let tables = await this.tables();
|
|
7
|
+
if(!tables.length) throw new TypeError(errors.noTablesExisted);
|
|
8
|
+
let ms = Date.now();
|
|
9
|
+
await this.query(`SELECT * from \`${tables[0]}\``);
|
|
10
|
+
return Date.now() - ms;
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const errors = require('../errors/strings.js');
|
|
4
|
+
|
|
5
|
+
module.exports = async function(table, key, value, option){
|
|
6
|
+
if(!table || typeof table !== "string") throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
7
|
+
if(!key || typeof key !== "string") throw new TypeError(errors.key.replace("{received}", typeof key));
|
|
8
|
+
if(value === undefined) throw new TypeError(errors.value.replace("{received}", typeof value));
|
|
9
|
+
|
|
10
|
+
let data = await this.get(table, key);
|
|
11
|
+
if(!data) throw new TypeError(errors.dataNotFound.replace("{key}", key));
|
|
12
|
+
if(!Array.isArray(data)) throw new TypeError(errors.array.replace("{key}", key));
|
|
13
|
+
if(option && (option === true || option.toLowerCase() === "all")){
|
|
14
|
+
data = data.filter(obj => obj !== value);
|
|
15
|
+
}else{
|
|
16
|
+
if(data.includes(value)) data.splice(data.indexOf(value), 1);
|
|
17
|
+
}
|
|
18
|
+
return this.set(table, key, data);
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const errors = require('../errors/strings.js');
|
|
4
|
+
|
|
5
|
+
module.exports = async function(table, key, value, option){
|
|
6
|
+
if(!table || typeof table !== "string") throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
7
|
+
if(!key || typeof key !== "string") throw new TypeError(errors.key.replace("{received}", typeof key));
|
|
8
|
+
if(value === undefined) throw new TypeError(errors.value.replace("{received}", typeof value));
|
|
9
|
+
|
|
10
|
+
await this.create(table);
|
|
11
|
+
|
|
12
|
+
let data = await this.get(table, key) || [];
|
|
13
|
+
if(!Array.isArray(data)) throw new TypeError(errors.array.replace("{key}", key));
|
|
14
|
+
if(option === true){
|
|
15
|
+
if(!data.includes(value)) data.push(value);
|
|
16
|
+
}else{
|
|
17
|
+
data.push(value);
|
|
18
|
+
}
|
|
19
|
+
return this.set(table, key, data);
|
|
20
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const errors = require('../errors/strings.js');
|
|
4
|
+
|
|
5
|
+
module.exports = async function(table, newTable){
|
|
6
|
+
if(!table || !newTable || typeof table !== "string" || typeof newTable !== "string") throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
7
|
+
if(table === newTable) throw new TypeError(errors.tableRenameSameName);
|
|
8
|
+
|
|
9
|
+
let tables = await this.tables();
|
|
10
|
+
if(!tables.includes(table)) throw new TypeError(errors.tableNotFound.replace("{table}", table));
|
|
11
|
+
if(tables.includes(newTable)) throw new TypeError(errors.tableAlreadyExists.replace("{table}", newTable));
|
|
12
|
+
|
|
13
|
+
await this.query(`ALTER TABLE \`${table}\` RENAME TO \`${newTable}\``);
|
|
14
|
+
this.emit("tableRename", table, newTable);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const set = require('lodash/set');
|
|
4
|
+
const errors = require('../errors/strings.js');
|
|
5
|
+
|
|
6
|
+
module.exports = async function(table, key, value, isBaseValue){
|
|
7
|
+
if(!table || typeof table !== "string") throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
8
|
+
if(!key || typeof key !== "string") throw new TypeError(errors.key.replace("{received}", typeof key));
|
|
9
|
+
if(value === undefined) throw new TypeError(errors.value.replace("{received}", typeof value));
|
|
10
|
+
|
|
11
|
+
await this.create(table);
|
|
12
|
+
|
|
13
|
+
let oldData = await this.get(table, key);
|
|
14
|
+
|
|
15
|
+
let keys = key.split('.'),
|
|
16
|
+
keys2 = key.split('.');
|
|
17
|
+
if(keys.length > 1) key = keys.shift();
|
|
18
|
+
|
|
19
|
+
let data = await this.query({
|
|
20
|
+
sql: `SELECT value FROM \`${table}\` WHERE \`key_name\` = ?`,
|
|
21
|
+
values: [key]
|
|
22
|
+
});
|
|
23
|
+
if(!data.length){
|
|
24
|
+
await this.query({
|
|
25
|
+
sql: `INSERT INTO \`${table}\` (\`key_name\`, \`value\`) VALUES (?, ?)`,
|
|
26
|
+
values: [key,JSON.stringify({})]
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
data = await this.get(table, key) || {};
|
|
30
|
+
if(keys2.length > 1 && typeof data === 'object'){
|
|
31
|
+
value = set(data, keys.join("."), value);
|
|
32
|
+
}else if(keys2.length > 1){
|
|
33
|
+
throw new ReferenceError(errors.targetNotObject.replace("{key}", key));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try{
|
|
37
|
+
value = JSON.stringify(value);
|
|
38
|
+
}catch(e){}
|
|
39
|
+
await this.query({
|
|
40
|
+
sql: `UPDATE \`${table}\` SET \`value\` = ? WHERE \`key_name\` = ?`,
|
|
41
|
+
values: [value,key]
|
|
42
|
+
});
|
|
43
|
+
let modifiedAt = Date.now()
|
|
44
|
+
|
|
45
|
+
let newData = await this.get(table, (keys2.length > 1) ? key + "." + keys.join(".") : key);
|
|
46
|
+
this.emit("dataModification", {oldData: (isBaseValue ? Buffer.from(oldData, 'base64').toString('binary') : oldData), newData: (isBaseValue ? Buffer.from(newData, 'base64').toString('binary') : newData), type: (oldData == null && newData != null) ? "SET" : "UPDATE", table, modifiedAt});
|
|
47
|
+
return newData;
|
|
48
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const errors = require('../errors/strings.js');
|
|
4
|
+
|
|
5
|
+
module.exports = async function(table){
|
|
6
|
+
if(!table || typeof table !== "string") throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
7
|
+
|
|
8
|
+
let res = await this.query(`SHOW TABLE STATUS FROM ${this.db.pool.config.connectionConfig.database} WHERE name LIKE '${table}';`);
|
|
9
|
+
return res[0] || null;
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const errors = require('../errors/strings.js');
|
|
4
|
+
|
|
5
|
+
module.exports = async function(table, key, value){
|
|
6
|
+
if(!table || typeof table !== "string") throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
7
|
+
if(!key || typeof key !== "string") throw new TypeError(errors.key.replace("{received}", typeof key));
|
|
8
|
+
if(value === undefined) throw new TypeError(errors.value.replace("{received}", typeof value));
|
|
9
|
+
if(isNaN(value) || value <= 0) throw new TypeError(errors.numberType.replace("{received}", typeof value));
|
|
10
|
+
|
|
11
|
+
let res;
|
|
12
|
+
let tables = await this.tables();
|
|
13
|
+
if(!tables.includes(table)){
|
|
14
|
+
res = await this.set(table, key, 0 - Number(value));
|
|
15
|
+
}else{
|
|
16
|
+
let data = await this.get(table, key) || 0;
|
|
17
|
+
if(isNaN(data)) throw new TypeError(errors.notNumber.replace("{key}", key));
|
|
18
|
+
res = await this.set(table, key, data - Number(value));
|
|
19
|
+
}
|
|
20
|
+
return res;
|
|
21
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const errors = require('../errors/strings.js');
|
|
4
|
+
|
|
5
|
+
module.exports = async function(variables){
|
|
6
|
+
if(!variables) throw new TypeError(errors.variables.replace("{received}", variables));
|
|
7
|
+
if(typeof variables !== "object" || Array.isArray(variables)) throw new TypeError(errors.variablesNotObject.replace("{received}", typeof variables));
|
|
8
|
+
|
|
9
|
+
let res = {};
|
|
10
|
+
let keys = Object.keys(variables);
|
|
11
|
+
for(var i = 0; i < keys.length; i++){
|
|
12
|
+
let returned = await this.query(`SET GLOBAL ${keys[i]}=${variables[keys[i]]};`);
|
|
13
|
+
if(!returned.message){
|
|
14
|
+
res[keys[i]] = variables[keys[i]];
|
|
15
|
+
}else{
|
|
16
|
+
res[keys[i]] = returned;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return res;
|
|
20
|
+
}
|
package/database/test.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require('dotenv').config();
|
|
2
|
+
const runMongoDB = async()=>{
|
|
3
|
+
const { MongoDB} = require('./index')
|
|
4
|
+
|
|
5
|
+
var db = await MongoDB.createData('database','collection','data',undefined,'mongourl')
|
|
6
|
+
|
|
7
|
+
db.set('foo','bar')
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
runMongoDB()
|
|
11
|
+
const runMySQL = async()=>{
|
|
12
|
+
const {MySQLDatabase}=require('./index')
|
|
13
|
+
const db = new MySQLDatabase();
|
|
14
|
+
await db.connect({
|
|
15
|
+
host: 'localhost',
|
|
16
|
+
port: '3306',
|
|
17
|
+
user: 'root',
|
|
18
|
+
password: '',
|
|
19
|
+
database: 'database',
|
|
20
|
+
charset: 'utf8mb4',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
db.on('connected', async connection => {
|
|
24
|
+
console.log('Database Connected');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
db.set('table','foo','bar')
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//runMySQL()
|
|
32
|
+
|
|
33
|
+
const runJsonDatabase = async()=>{
|
|
34
|
+
const {JsonDatabase} = require('./index')
|
|
35
|
+
var db = new JsonDatabase()
|
|
36
|
+
db.set('foo','bar')
|
|
37
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
function makeUniqueId() {
|
|
2
|
+
return Date.now().toString(36) + Math.random().toString(36).substr(2);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function randomArray(arr){
|
|
6
|
+
var random1 = Math.floor(Math.random()*(arr.length-0+0)+0);
|
|
7
|
+
var random = arr[random1]
|
|
8
|
+
return random;
|
|
9
|
+
}
|
|
10
|
+
function randomText(length){
|
|
11
|
+
if(!length) length = 8;
|
|
12
|
+
var result = '';
|
|
13
|
+
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
14
|
+
var charactersLength = characters.length;
|
|
15
|
+
for ( var i = 0; i < length; i++ ) {
|
|
16
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
function randomNumber(bas,son){
|
|
21
|
+
if(!bas) bas = 0
|
|
22
|
+
if(!son) son = 9999999
|
|
23
|
+
return Math.floor(Math.random() * (son - bas + 1)) + bas;
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
function randomEmoji() {
|
|
27
|
+
var emojiler = [
|
|
28
|
+
'😄','😃','😀','😊','☺','😉','😍','😘','😚','😗','😙','😜','😝','😛','😳','😁','😔','😌','😒','😞','😣','😢','😂','😭','😪','😥','😰','😅','😓','😩','😫','😨','😱','😠','😡','😤','😖','😆','😋','😷','😎','😴','😵','😲','😟','😦','😧','😈','👿','😮','😬','😐','😕','😯','😶','😇','😏','😑','👲','👳','👮','👷','💂','👶','👦','👧','👨','👩','👴','👵','👱','👼','👸','😺','😸','😻','😽','😼','🙀','😿','😹','😾','👹','👺','🙈','🙉','🙊','💀','👽','💩','🔥','✨','🌟','💫','💥','💢','💦','💧','💤','💨','👂','👀','👃','👅','👄','👍','👎','👌','👊','✊','✌','👋','✋','👐','👆','👇','👉','👈','🙌','🙏','☝','👏','💪','🚶','🏃','💃','👫','👪','👬','👭','💏','💑','👯','🙆','🙅','💁','🙋','💆','💇','💅','👰','🙎','🙍','🙇','🎩','👑','👒','👟','👞','👡','👠','👢','👕','👔','👚','👗','🎽','👖','👘','👙','💼','👜','👝','👛','👓','🎀','🌂','💄','💛','💙','💜','💚','❤','💔','💗','💓','💕','💖','💞','💘','💌','💋','💍','💎','👤','👥','💬','👣','💭','🐶','🐺','🐱','🐭','🐹','🐰','🐸','🐯','🐨','🐻','🐷','🐽','🐮','🐗','🐵','🐒','🐴','🐑','🐘','🐼','🐧','🐦','🐤','🐥','🐣','🐔','🐍','🐢','🐛','🐝','🐜','🐞','🐌','🐙','🐚','🐠','🐟','🐬','🐳','🐋','🐄','🐏','🐀','🐃','🐅','🐇','🐉','🐎','🐐','🐓','🐕','🐖','🐁','🐂','🐲','🐡','🐊','🐫','🐪','🐆','🐈','🐩','🐾','💐','🌸','🌷','🍀','🌹','🌻','🌺','🍁','🍃','🍂','🌿','🌾','🍄','🌵','🌴','🌲','🌳','🌰','🌱','🌼','🌐','🌞','🌝','🌚','🌑','🌒','🌓','🌔','🌕','🌖','🌗','🌘','🌜','🌛','🌙','🌍','🌎','🌏','🌋','🌌','🌠','⭐','☀','⛅','☁','⚡','☔','❄','⛄','🌀','🌁','🌈','🌊','🎍','💝','🎎','🎒','🎓','🎏','🎆','🎇','🎐','🎑','🎃','👻','🎅','🎄','🎁','🎋','🎉','🎊','🎈','🎌','🔮','🎥','📷','📹','📼','💿','📀','💽','💾','💻','📱','☎','📞','📟','📠','📡','📺','📻','🔊','🔉','🔈','🔇','🔔','🔕','📢','📣','⏳','⌛','⏰','⌚','🔓','🔒','🔏','🔐','🔑','🔎','💡','🔦','🔆','🔅','🔌','🔋','🔍','🛁','🛀','🚿','🚽','🔧','🔩','🔨','🚪','🚬','💣','🔫','🔪','💊','💉','💰','💴','💵','💷','💶','💳','💸','📲','📧','📥','📤','✉','📩','📨','📯','📫','📪','📬','📭','📮','📦','📝','📄','📃','📑','📊','📈','📉','📜','📋','📅','📆','📇','📁','📂','✂','📌','📎','✒','✏','📏','📐','📕','📗','📘','📙','📓','📔','📒','📚','📖','🔖','📛','🔬','🔭','📰','🎨','🎬','🎤','🎧','🎼','🎵','🎶','🎹','🎻','🎺','🎷','🎸','👾','🎮','🃏','🎴','🀄','🎲','🎯','🏈','🏀','⚽','⚾','🎾','🎱','🏉','🎳','⛳','🚵','🚴','🏁','🏇','🏆','🎿','🏂','🏊','🏄','🎣','☕','🍵','🍶','🍼','🍺','🍻','🍸','🍹','🍷','🍴','🍕','🍔','🍟','🍗','🍖','🍝','🍛','🍤','🍱','🍣','🍥','🍙','🍘','🍚','🍜','🍲','🍢','🍡','🍳','🍞','🍩','🍮','🍦','🍨','🍧','🎂','🍰','🍪','🍫','🍬','🍭','🍯','🍎','🍏','🍊','🍋','🍒','🍇','🍉','🍓','🍑','🍈','🍌','🍐','🍍','🍠','🍆','🍅','🌽','🏠','🏡','🏫','🏢','🏣','🏥','🏦','🏪','🏩','🏨','💒','⛪','🏬','🏤','🌇','🌆','🏯','🏰','⛺','🏭','🗼','🗾','🗻','🌄','🌅','🌃','🗽','🌉','🎠','🎡','⛲','🎢','🚢','⛵','🚤','🚣','⚓','🚀','✈','💺','🚁','🚂','🚊','🚉','🚞','🚆','🚄','🚅','🚈','🚇','🚝','🚋','🚃','🚎','🚌','🚍','🚙','🚘','🚗','🚕','🚖','🚛','🚚','🚨','🚓','🚔','🚒','🚑','🚐','🚲','🚡','🚟','🚠','🚜','💈','🚏','🎫','🚦','🚥','⚠','🚧','🔰','⛽','🏮','🎰','♨','🗿','🎪','🎭','📍','🚩','⬆','⬇','⬅','➡','🔠','🔡','🔤','↗','↖','↘','↙','↔','↕','🔄','◀','▶','🔼','🔽','↩','↪','ℹ','⏪','⏩','⏫','⏬','⤵','⤴','🆗','🔀','🔁','🔂','🆕','🆙','🆒','🆓','🆖','📶','🎦','🈁','🈯','🈳','🈵','🈴','🈲','🉐','🈹','🈺','🈶','🈚','🚻','🚹','🚺','🚼','🚾','🚰','🚮','🅿','♿','🚭','🈷','🈸','🈂','Ⓜ','🛂','🛄','🛅','🛃','🉑','㊙','㊗','🆑','🆘','🆔','🚫','🔞','📵','🚯','🚱','🚳','🚷','🚸','⛔','✳','❇','❎','✅','✴','💟','🆚','📳','📴','🅰','🅱','🆎','🅾','💠','➿','♻','♈','♉','♊','♋','♌','♍','♎','♏','♐','♑','♒','♓','⛎','🔯','🏧','💹','💲','💱','©','®','™','〽','〰','🔝','🔚','🔙','🔛','🔜','❌','⭕','❗','❓','❕','❔','🔃','🕛','🕧','🕐','🕜','🕑','🕝','🕒','🕞','🕓','🕟','🕔','🕠','🕕','🕖','🕗','🕘','🕙','🕚','🕡','🕢','🕣','🕤','🕥','🕦','✖','➕','➖','➗','♠','♥','♣','♦','💮','💯','✔','☑','🔘','🔗','➰','🔱','🔲','🔳','◼','◻','◾','◽','▪','▫','🔺','⬜','⬛','⚫','⚪','🔴','🔵','🔻','🔶','🔷','🔸','🔹'
|
|
29
|
+
];
|
|
30
|
+
return emojiler[Math.floor(Math.random() * emojiler.length)];
|
|
31
|
+
}
|
|
32
|
+
function randomHex() {
|
|
33
|
+
var letters = '0123456789ABCDEF';
|
|
34
|
+
var color = '#';
|
|
35
|
+
for (var i = 0; i < 6; i++) {
|
|
36
|
+
color += letters[Math.floor(Math.random() * 16)];
|
|
37
|
+
}
|
|
38
|
+
return color;
|
|
39
|
+
}
|
|
40
|
+
module.exports ={
|
|
41
|
+
makeUniqueId,
|
|
42
|
+
randomArray,
|
|
43
|
+
randomText,
|
|
44
|
+
randomNumber,
|
|
45
|
+
randomEmoji,
|
|
46
|
+
randomHex
|
|
47
|
+
}
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@onurege3467/zerohelper",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "node test.js"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [
|
|
9
|
+
"helper",
|
|
10
|
+
"zerohelper",
|
|
11
|
+
"database",
|
|
12
|
+
"uuid",
|
|
13
|
+
"mongodb",
|
|
14
|
+
"mysql",
|
|
15
|
+
"db",
|
|
16
|
+
"jsondatabase"
|
|
17
|
+
],
|
|
18
|
+
"author": "Onure9e",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"dotenv": "^16.4.7",
|
|
22
|
+
"fs": "^0.0.1-security",
|
|
23
|
+
"lodash": "^4.17.21",
|
|
24
|
+
"mongodb": "^6.12.0",
|
|
25
|
+
"path": "^0.12.7",
|
|
26
|
+
"promise-mysql": "^5.2.0"
|
|
27
|
+
},
|
|
28
|
+
"description": ""
|
|
29
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# ZeroHelper
|
|
2
|
+
ZeroHelper is a package with database and some functions.
|
|
3
|
+
|
|
4
|
+
## Installing ZeroHelper
|
|
5
|
+
```bash
|
|
6
|
+
npm i @onurege3467/zerohelper
|
|
7
|
+
```
|
|
8
|
+
## Using ZeroHelper for helper functions
|
|
9
|
+
```js
|
|
10
|
+
var {functions} = require('@onurege3467/zerohelper')
|
|
11
|
+
|
|
12
|
+
console.log(functions.makeUniqueId()) // returns like this m63ku5dsi45hppk24i
|
|
13
|
+
console.log(functions.randomArray([1,2,3,4,5])) // selects random variable in this array
|
|
14
|
+
console.log(functions.randomEmoji()) // returns a random emoji
|
|
15
|
+
console.log(functions.randomHex()) // returns a random hex code
|
|
16
|
+
console.log(functions.randomNumber()) // returns random number
|
|
17
|
+
console.log(functions.randomText()) // returns random text
|
|
18
|
+
```
|
|
19
|
+
## Using ZeroHelper As Database
|
|
20
|
+
ZeroHelper's database is divided into 3 parts.
|
|
21
|
+
### Firtst Step
|
|
22
|
+
```js
|
|
23
|
+
const zerohelper = require('@onurege3467/zerohelper') // if you don't do this the functions may crush
|
|
24
|
+
```
|
|
25
|
+
### 1. JsonDatabase
|
|
26
|
+
```js
|
|
27
|
+
const JsonDatabase = require('@onurege3467/zerohelper/database/jsondatabase')
|
|
28
|
+
const db = new JsonDatabase()
|
|
29
|
+
|
|
30
|
+
db.set('foo','bar') // sets foo to bar
|
|
31
|
+
db.push('array','x') // pushs x to array
|
|
32
|
+
db.delete('foo') // deletes foo
|
|
33
|
+
|
|
34
|
+
db.add('number',1) // adds 1 to number
|
|
35
|
+
db.sub('number',1) // subtracts 1 from number
|
|
36
|
+
|
|
37
|
+
db.get('foo') // gets foo value
|
|
38
|
+
db.has('foo') // returns true or false
|
|
39
|
+
```
|
|
40
|
+
### 2. MongoDB
|
|
41
|
+
```js
|
|
42
|
+
(async function () {
|
|
43
|
+
const MongoDB = require('@onurege3467/zerohelper/database/mongodb')
|
|
44
|
+
var db = await MongoDB.createData('database','collection','data',undefined,'mongourl')
|
|
45
|
+
db.set('foo','bar') // sets foo to bar
|
|
46
|
+
db.push('array','x') // pushs x to array
|
|
47
|
+
db.delete('foo') // deletes foo
|
|
48
|
+
|
|
49
|
+
db.add('number',1) // adds 1 to number
|
|
50
|
+
db.sub('number',1) // subtracts 1 from number
|
|
51
|
+
|
|
52
|
+
db.get('foo') // gets foo value
|
|
53
|
+
db.has('foo') // returns true or false
|
|
54
|
+
|
|
55
|
+
db.ping() // returns database ping
|
|
56
|
+
|
|
57
|
+
})()
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
### 3. MySQL
|
|
61
|
+
```js
|
|
62
|
+
(async function () {
|
|
63
|
+
const mysql = require('@onurege3467/zerohelper/database/mysql')
|
|
64
|
+
|
|
65
|
+
const db = new mysql();
|
|
66
|
+
await db.connect({
|
|
67
|
+
host: 'localhost',
|
|
68
|
+
port: '3306',
|
|
69
|
+
user: 'root',
|
|
70
|
+
password: '',
|
|
71
|
+
database: 'database',
|
|
72
|
+
charset: 'utf8mb4',
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
db.on('connected', async connection => {
|
|
76
|
+
console.log('Database Connected');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
db.set('foo','bar') // sets foo to bar
|
|
80
|
+
db.push('array','x') // pushs x to array
|
|
81
|
+
db.delete('foo') // deletes foo
|
|
82
|
+
|
|
83
|
+
db.add('number',1) // adds 1 to number
|
|
84
|
+
db.sub('number',1) // subtracts 1 from number
|
|
85
|
+
|
|
86
|
+
db.get('foo') // gets foo value
|
|
87
|
+
db.has('foo') // returns true or false
|
|
88
|
+
|
|
89
|
+
db.ping() // returns database ping
|
|
90
|
+
})()
|
|
91
|
+
```
|