Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sreya

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sreya - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

2

dist/collection.d.ts

@@ -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

2

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc