v3.1.0 push 2

This commit is contained in:
DJj123dj
2022-12-27 17:35:01 +01:00
parent 86a5a1a2ca
commit ae002e168b
14 changed files with 239 additions and 24 deletions
@@ -0,0 +1,66 @@
const fs = require("fs")
const location = "./storage/database.json"
/**@returns {[{category:String, key:String, value:String}]}*/
function getData(){
return JSON.parse(fs.readFileSync(location).toString())
}
/**@param {[{category:String, key:String, value:String}]} data*/
function setData(data){
fs.writeFileSync(location,JSON.stringify(data,null,"\t"))
}
exports.set = (category,key,value) => {
const currentData = getData()
const exists = currentData.find((d) => (d.category == category) && (d.key == key)) ? true : false
var newData = []
if (exists){
currentData.forEach((d,i) => {
if (d.category == category && d.key == key){
newData.push({category,key,value})
}else{
newData.push(d)
}
})
}else{
currentData.push({category,key,value})
newData = currentData
}
setData(newData)
return exists
}
/**
* @param {String} category
* @param {String} key
* @returns {String|false}
*/
exports.get = (category,key) => {
const currentData = getData()
const tempresult = currentData.find((d) => (d.category == category) && (d.key == key))
const result = tempresult ? tempresult.value : false
return result
}
/**
* @param {String} category
* @param {String} key
* @param {String} value
*/
exports.delete = (category,key) => {
const currentData = getData()
const exists = currentData.find((d) => (d.category == category) && (d.key == key)) ? true : false
var newData = []
if (exists){
currentData.forEach((d,i) => {
if (!(d.category == category && d.key == key)){
newData.push(d)
}
})
}else{
newData = currentData
}
setData(newData)
return exists
}
+5 -1
View File
@@ -36,4 +36,8 @@ exports.get = (category,id) => {
exports.delete = (category,id) => {
ls.removeItem(category+"--"+id)
return true
}
}
this.set("category","key","value")
this.get("category","key",)
this.delete("category","key")
+3 -7
View File
@@ -1,11 +1,7 @@
//Do not change this without knowing what you are doing!!
const databaseFile = "local"
//Do not change this without knowing what you are doing!!
try {
var db = require("./dynamicfiles/local")
}catch{
var db = require("./dynamicfiles/database")
}catch(err){
console.log(err)
console.log("I couldn't find the database file! (location: ./core/dynamicdatabase/storage.js:2)")
process.exit(1)
}