Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DB

Simple Virtual Database (VDB) application API.

This API abstracts and provides a standard way to connect to a server-side relational database (e.g. sqlite).

Each user when connected has their own database previously created. All VDB operations related to that user will be performed on this database.

The creation of user database need to be managed by the server-side API. The VDB API assumes that the database already exist. All operations is performed in tables level

export

Hierarchy

  • DB

Index

Constructors

Properties

Methods

Constructors

constructor

  • new DB(table: string): DB
  • Creates an instance of DB.

    memberof

    DB

    Parameters

    • table: string

      table name

    Returns DB

Properties

Private table

table: string

A table name on the user's database

memberof

DB

Methods

delete

  • delete record(s) from the current table by a conditional object

    memberof

    DB

    Parameters

    • c: GenericObject<any> | number | string

      conditional object, c can be:

      • a number: the operation will delete the record with id = c
      • a string: The SQL string condition that selects record to delete
      • a conditional object represents a SQL condition statement as an object, example: pid = 10 AND cid = 2 is represented by:
       {
           exp: {
               "and": {
                   pid: 10,
                   cid: 2
               }
       }
      

    Returns Promise<RequestResult>

find

  • Find records by a condition

    memberof

    DB

    Parameters

    • cond: GenericObject<any>

      conditional object

      a conditional object represents a SQL condition statement as an object, example: pid = 10 AND cid = 2 ORDER BY date DESC is represented by:

       {
           exp: {
               "and": {
                   pid: 10,
                   cid: 2
               }
           },
           order: {
               date: "DESC"
           }
       }
      

    Returns Promise<GenericObject<any>[]>

get

  • Get a record in the table by its primary key

    memberof

    DB

    Parameters

    • id: number

      the primary key value

    Returns Promise<GenericObject<any>>

    Promise on returned record data

save

  • Save data to the current table. The input data must conform to the table record format.

    On the server side, if the table doest not exist yet, it should be created automatically by inferring the data structure of the input object

    memberof

    DB

    Parameters

    • d: GenericObject<any>

      data object represents a current table record

    Returns Promise<RequestResult>