Comparing version 1.1.0 to 1.2.0
@@ -5,2 +5,4 @@ export declare namespace collection { | ||
function insert(collection: string, newData: any): Promise<string | null>; | ||
function remove(collection: string, identifier: string): Promise<string | null>; | ||
function destroy(collection: string): Promise<string>; | ||
} |
@@ -54,4 +54,2 @@ "use strict"; | ||
const data = JSON.parse(jsonData); | ||
console.log(newData); | ||
console.log(data); | ||
// Generate a unique ID for the new data | ||
@@ -75,3 +73,54 @@ newData._id = await generateUniqueID(); | ||
collection_1.insert = insert; | ||
async function remove(collection, identifier) { | ||
try { | ||
const dbname = process.env.DB_NAME; | ||
const fileName = `${dbname}/${collection}.json`; | ||
if (fs_1.default.existsSync(fileName)) { | ||
// Read the file synchronously | ||
const jsonData = fs_1.default.readFileSync(fileName, 'utf-8'); | ||
// Parse the JSON data | ||
let data = JSON.parse(jsonData); | ||
// Find the index of the item with the given identifier | ||
const index = data.findIndex((item) => item._id === identifier); | ||
if (index !== -1) { | ||
// Remove the item from the array | ||
data.splice(index, 1); | ||
// Write the updated data back to the file | ||
fs_1.default.writeFileSync(fileName, JSON.stringify(data)); | ||
return 'Data removed successfully.'; | ||
} | ||
else { | ||
return `Item with identifier '${identifier}' not found in collection '${collection}'.`; | ||
} | ||
} | ||
else { | ||
return `Collection '${collection}' does not exist.`; | ||
} | ||
} | ||
catch (error) { | ||
console.error('Error removing data:', error); | ||
return null; | ||
} | ||
} | ||
collection_1.remove = remove; | ||
async function destroy(collection) { | ||
try { | ||
let dbname = process.env.DB_NAME; | ||
const fileName = `${dbname}/${collection}.json`; | ||
// Check if the file exists | ||
if (fs_1.default.existsSync(fileName)) { | ||
// Delete the file | ||
fs_1.default.unlinkSync(fileName); | ||
return `File '${fileName}' deleted successfully.`; | ||
} | ||
else { | ||
return `File '${fileName}' does not exist.`; | ||
} | ||
} | ||
catch (error) { | ||
return `Error deleting collection: ${error}`; | ||
} | ||
} | ||
collection_1.destroy = destroy; | ||
})(collection || (exports.collection = collection = {})); | ||
//# sourceMappingURL=collection.js.map |
{ | ||
"name": "sreya", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Sreya is a versatile in-memory database for Node.js applications.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -70,2 +70,54 @@ import fs from 'fs'; | ||
} | ||
export async function remove(collection: string, identifier: string) { | ||
try { | ||
const dbname = process.env.DB_NAME; | ||
const fileName = `${dbname}/${collection}.json`; | ||
if (fs.existsSync(fileName)) { | ||
// Read the file synchronously | ||
const jsonData = fs.readFileSync(fileName, 'utf-8'); | ||
// Parse the JSON data | ||
let data = JSON.parse(jsonData); | ||
// Find the index of the item with the given identifier | ||
const index = data.findIndex((item: any) => item._id === identifier); | ||
if (index !== -1) { | ||
// Remove the item from the array | ||
data.splice(index, 1); | ||
// Write the updated data back to the file | ||
fs.writeFileSync(fileName, JSON.stringify(data)); | ||
return 'Data removed successfully.'; | ||
} else { | ||
return `Item with identifier '${identifier}' not found in collection '${collection}'.`; | ||
} | ||
} else { | ||
return `Collection '${collection}' does not exist.`; | ||
} | ||
} catch (error) { | ||
console.error('Error removing data:', error); | ||
return null; | ||
} | ||
} | ||
export async function destroy(collection: string) { | ||
try { | ||
let dbname = process.env.DB_NAME; | ||
const fileName = `${dbname}/${collection}.json`; | ||
// Check if the file exists | ||
if (fs.existsSync(fileName)) { | ||
// Delete the file | ||
fs.unlinkSync(fileName); | ||
return `File '${fileName}' deleted successfully.`; | ||
} else { | ||
return `File '${fileName}' does not exist.`; | ||
} | ||
} catch (error) { | ||
return `Error deleting collection: ${error}`; | ||
} | ||
} | ||
} |
@@ -9,9 +9,13 @@ const { connect, collection } = require('../dist/index'); | ||
let col = await collection.find('user'); | ||
console.log(col); | ||
// console.log(col); | ||
collection.insert('user', { | ||
name: 'hi' | ||
}) | ||
// collection.insert('user', { | ||
// name: 'hi' | ||
// }) | ||
collection.destroy('user') | ||
// collection.remove('user', 'lvnqqt1h6m6z1') | ||
} | ||
clal() |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
25536
439
0
13
8