Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

multiple.db

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multiple.db - npm Package Compare versions

Package version was removed
This package version has been unpublished, mostly likely due to security reasons
Comparing version
0.0.3
to
0.0.5
+67
-103
index.js
const mongoose = require('mongoose');
const fs = require('fs');
const path = require('path');
const colors = require('colors');
let storageType = 'json';
if (!fs.existsSync(`data.json`)) {
fs.writeFileSync(`data.json`, "{}");
}
let storageType = 'json';
const dataPath = path.resolve('data.json');
// All Copyrights By </SmSm>#8700
let data = {};
let dataChanged = false;
if (!fs.existsSync(dataPath) && storageType === 'json') {
fs.writeFileSync(dataPath, "{}");
}
function readData() {

@@ -21,3 +22,3 @@ try {

}
// All Copyrights By </SmSm>#8700
function writeData() {

@@ -27,6 +28,5 @@ fs.writeFileSync(dataPath, JSON.stringify(data));

const dataSchema = new mongoose.Schema({
key: String,
value: mongoose.Mixed
value: mongoose.Mixed,
});

@@ -36,125 +36,93 @@

// All Copyrights By </SmSm>#8700
async function connect(uri) {
await mongoose.connect(uri, { useNewUrlParser: true });
console.log('Connected to MongoDB');
mongoose.set('strictQuery', true)
await mongoose.connect(uri);
storageType = 'mongoose';
const db = mongoose.connection;
db.on('error', (err) => {
throw Error('MongoDB connection error:', err)
});
db.once('open', async () => {
console.log('Connected to the Mongodb'.green);
})
}
async function useJSON() {
storageType = 'json';
}
async function useMongoDB() {
storageType = 'mongoose';
}
async function add(key, value) {
if (storageType === 'json') {
if (data[key]) {
data[key] += value;
data[key] = (data[key] || 0) + value;
dataChanged = true;
} else {
data[key] = value;
const doc = await Data.findOneAndUpdate({ key }, { $inc: { value } }, { upsert: true, new: true }).exec();
return doc ? doc.value : value;
}
dataChanged = true;
} else {
const doc = await Data.findOne({ key }).exec();
if (!doc) {
await Data.create({ key, value });
} else {
doc.value += value;
await doc.save();
}
return doc ? doc.value : value;
}
async function subtract(key, value) {
return add(key, -value);
}
async function subtract(key, value) {
async function set(key, value) {
if (storageType === 'json') {
if (data[key]) {
data[key] -= value;
data[key] = value;
dataChanged = true;
} else {
data[key] = -value;
const doc = await Data.findOneAndUpdate({ key }, { value }, { upsert: true, new: true }).exec();
return doc ? doc.value : value;
}
dataChanged = true;
} else {
const doc = await Data.findOne({ key }).exec();
if (!doc) {
await Data.create({ key, value: -value });
} else {
doc.value -= value;
await doc.save();
}
return doc ? doc.value : -value;
}
}
// All Copyrights By </SmSm>#8700
async function set(key, value) {
async function get(key) {
if (storageType === 'json') {
data[key] = value;
dataChanged = true;
return data[key];
} else {
const doc = await Data.findOneAndUpdate({ key }, { value }, { upsert: true, new: true }).exec();
return doc.value;
const doc = await Data.findOne({ key }).exec();
return doc ? doc.value : undefined;
}
}
}
// All Copyrights By </SmSm>#8700
async function get(key) {
async function deleteKey(key) {
if (storageType === 'json') {
return data[key];
const value = data[key];
delete data[key];
dataChanged = true;
return value;
} else {
const doc = await Data.findOne({ key }).exec();
return doc ? doc.value : undefined;
const doc = await Data.findOneAndDelete({ key }).exec();
return doc ? doc.value : undefined;
}
}
}
// All Copyrights By </SmSm>#8700
async function trash(key) {
if (storageType === 'json') {
const value = data[key];
delete data[key];
dataChanged = true;
return value;
} else {
const doc = await Data.findOneAndDelete({ key }).exec();
return doc ? doc.value : undefined;
}
}
// All Copyrights By </SmSm>#8700
async function has(key) {
if (storageType === 'json') {
return data.hasOwnProperty(key);
return data.hasOwnProperty(key);
} else {
const doc = await Data.findOne({ key }).exec();
return !!doc;
const doc = await Data.findOne({ key }).exec();
return !!doc;
}
}
}
// All Copyrights By </SmSm>#8700
async function all() {
if (storageType === 'json') {
return Object.entries(data).map(([key, value]) => ({ key, value }));
return Object.entries(data).map(([key, value]) => ({ key, value }));
} else {
const docs = await Data.find().exec();
return docs.map(doc => ({ key: doc.key, value: doc.value }));
const docs = await Data.find().exec();
return docs.map(doc => ({ key: doc.key, value: doc.value }));
}
}
}
// All Copyrights By </SmSm>#8700
async function fetch(key) {
if (storageType === 'json') {
return data[key];
} else {
const doc = await Data.findOne({ key }).exec();
return doc ? doc.value : undefined;
return get(key);
}
}
// All Copyrights By </SmSm>#8700
async function reset() {
if (storageType === 'json') {
data = {};
dataChanged = true;
dataChanged = true;
} else {
await Data.deleteMany({});
await Data.deleteMany({});
}
}
}
// All Copyrights By </SmSm>#8700
function save() {
if (dataChanged) {
if (dataChanged && storageType === 'json') {
writeData();

@@ -166,10 +134,6 @@ dataChanged = false;

setInterval(save, 1000);
readData();
// All Copyrights By </SmSm>#8700
module.exports = {
connect,
useJSON,
useMongoDB,
add,

@@ -179,7 +143,7 @@ subtract,

get,
trash,
delete: deleteKey,
has,
all,
fetch,
reset
};
reset,
};
{
"name": "multiple.db",
"version": "0.0.3",
"version": "0.0.5",
"description": "multiple database mongodb and json",

@@ -18,3 +18,5 @@ "main": "index.js",

"discord.js",
"plus.db"
"mongo",
"database",
"data"
],

@@ -24,5 +26,9 @@ "author": "SmSm",

"dependencies": {
"colors": "^1.4.0",
"fs": "^0.0.1-security",
"mongoose": "^6.8.1"
"mongoose": "^8.1.1"
},
"engines": {
"node": ">=20.11.0"
}
}

@@ -16,7 +16,3 @@ # multiple.db

// Connect to the database
await db.connect('mongodb://localhost/test').catch((err) => {
console.log(err)
})
// This if Using Mongoose
db.useMongoDB();
await db.connect('mongodb://localhost/test')

@@ -33,3 +29,3 @@ // Add a value

// Delete a value
await db.trash('key');
await db.delete('key');

@@ -59,5 +55,2 @@ // Get a value

// This if You Want Storage with **JSON**
db.useJSON();
// Add a value

@@ -73,3 +66,3 @@ await db.add('key', 1);

// Delete a value
await db.trash('key');
await db.delete('key');

@@ -97,3 +90,5 @@ // Get a value

Contact With Me Discord : ```</SmSm>#8700```
Contact With Me on Discord : ```devsmsm```
Contact With Me on Instrgram : ```u9fxc```