Database

A simple JSON database for PXE.js.

Installation

Install @pxe/database.

# NPM npm i @pxe/database vlds # Yarn yarn add @pxe/database vlds

Declarations

These are all @pxe/database module methods, events and declarations.

Constructor: Database

  • path?: string: The database path.

Create a database instance.

Method: db.remove

  • collectionName: string: The name of the collection to be removed.

Remove a collection from the database.

Method: db.clear

Clear the database.

Method: db.collect

  • T: The collection type.
  • name: string: The collection name.
  • validator: valids.Validator: A type validator from package vlds.

Create a new database collection.

Collection

The class returns by db.collect.

Constructor: Collection
  • data: T: The data.

Create an object with the specified value if validate successfully.

Method: item.save

Save or resave the collection to the database.

Method: item.del

Delete the collection from the database.

Method: item.setValue
  • value: T: Value to be set to the collection.

Set the value to the collection and save to the database.

Static Method: Collection.remove
  • id: string: ID of object to be removed.

Delete object from collection by ID.

Static Method: Collection.removeAll
  • o: any: Key that will be matched to objects.
  • count?: number: Number of objects to be removed.

Delete all objects the match o in the collection. Delete count objects if specified.

Static Method: Collection.select
  • id: string: ID of object to be selected.

Select a collection by ID.

Static Method: Collection.find
  • o: any: Key that will be matched to objects.
  • count?: number: Number of objects to be removed.

Find a collection that matches o. Find count number of collections if specified.

Static Method: Collection.findOne
  • o: any: Key that will be matched to objects.

Find a single colelction that matches o.

Static Method: Collection.update
  • o: any: Key that will be matched to objects.
  • value: T: Value to update the collection with.
  • rewrite?: boolean: Overwrites the object when true.

Update the first collection that matches o with the new value.

Static Method: Collection.updateID
  • id: string: ID of object to be updated.
  • value: T: Value to update the collection with.
  • rewrite?: boolean: Overwrites the object when true.

Update an item by its ID.

Update a collection by ID with the new value.

Property: db.path

  • Type: string

The specified database path. Can be undefined.