JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 21
  • Score
    100M100P100Q43805F
  • License ISC

Local database with json.

Package Exports

  • jsonbases
  • jsonbases/jsonbase.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jsonbases) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

JsonBases

jsonbases

Jsonbases - simple utility for managing JSON-based databases in Node.js. It provides functions to create, read, update, and delete records in a JSON file, following a specified data format.

Installation

npm install jsonbases

Get started

import jsonbases from 'jsonbases';

// Define user data format giving types, optionally specify required and unique values.
const format = {
    types: {
        name: 'string',
        age: 'number',
    },
    requireds: ['name', 'age'],
    uniques: ['name'],
};

// Create user table named "users", optionally specify the path, by default it's './jsonbases'.
const users = jsonbases('users', format, './path/to/your/database');

// Create a new item with default values
const newItem = db.createItem(); // returns object. ex: { name: null, age: null, _id: 'ad5sad132' }

// Add a new item to the database
newItem.name = 'John'
newItem.age = 25
const added = db.add(newItem); // returns boolean

// Find an item by unique values
const foundItem = db.find({ name: 'John' }); // returns object

// Find all items matching certain criteria
const allItems = db.findAll({ age: 25 }); // returns list

// Update an existing item
newItem.age = 26
const updated = db.update(newItem); // returns boolean

// Remove an item by unique values
const removed = db.remove({ name: 'John' }); // returns boolean

// Remove all items matching certain criteria
const removedAll = db.removeAll({ age: 26 }); // returns boolean

// Get all items in the database
const allData = db.getAll(); // returns list

// Reset the database (remove all items)
db.reset();

Functions

  • createItem() Creates a new item with properties initialized to null based on the defined data format.

  • add(item) Adds a new item to the database if it conforms to the specified data format.

  • find(item) Finds and returns an item in the database based on the provided ID.

  • findAll(item) Finds and returns an array of items in the database based on the provided criteria.

  • update(item) Updates an existing item in the database with the provided data and original ID.

  • remove(item) Removes an item from the database based on the provided criteria.

  • removeAll(item) Removes all items from the database that match the provided criteria.

  • getAll() Returns an array containing all items in the database.

  • resetTable() Resets the entire table, removing all items.

Features

  • Saves your time - no need to learn, install, create connections, sign up for other databases.

  • Easy to use - simple intuitive functions to manage with your tables.

  • Fast to work - simplicity of this tool makes your work more faster.


Developed with ❤️ in Budapest