Comparing version 1.2.6 to 1.2.7
27
index.js
@@ -503,6 +503,5 @@ /*! | ||
async saveData(dataName, newData) { | ||
const existingData = await this.readData(dataName); | ||
if (existingData !== null) { | ||
try { | ||
const existingData = await this.readData(dataName) || []; | ||
const newId = await this.randomID(); | ||
const newDataWithId = { | ||
@@ -512,12 +511,18 @@ id: newId, | ||
}; | ||
existingData.push(newDataWithId); // Append the new data to the existing array | ||
await this.writeDataByFileName(dataName, existingData).then(() => { | ||
this.logSuccess(`New Data added to DB: ${dataName}`); | ||
}); | ||
} else { | ||
this.handleError(`Data failed to be added to the DB: ${dataName}`); | ||
// Remove any existing data with the same ID | ||
const updatedData = existingData.filter((item) => item.id !== newId); | ||
// Add the new data with the same ID | ||
updatedData.push(newDataWithId); | ||
// Write the updated data to the file | ||
await this.writeDataByFileName(dataName, updatedData); | ||
this.logSuccess(`Data updated in DB: ${dataName}`); | ||
} catch (error) { | ||
this.handleError(`Failed to update data in DB: ${dataName}\nError: ${error}`); | ||
} | ||
} | ||
@@ -524,0 +529,0 @@ async delByID(id) { |
{ | ||
"name": "jsonverse", | ||
"version": "1.2.6", | ||
"version": "1.2.7", | ||
"description": "jsonVerse is a lightweight JSON-based database package for Node.js. It provides a simple interface to store, retrieve, and manage data using JSON files.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29089
573