Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AkeraHandler

akera.io data access handler implementation.

Hierarchy

Implements

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

Properties

Protected _name

_name: string = ""

Protected _router

_router: express.Router

Protected _webApp

_webApp: AkeraWeb

Accessors

Protected dataHandler

webApp

  • get webApp(): AkeraWeb
  • Returns the @akera/web instance used by the data access handler.

    Returns AkeraWeb

Methods

Protected _error

  • _error(err: Error | string, res?: express.Response, code?: number): void
  • Log an error message and optionally pipe it into the Response.

    Parameters

    • err: Error | string

      The error object or message string.

    • Optional res: express.Response

      The Response instance to pipe the error message.

    • Optional code: number

      The HTTP status code to use.

    Returns void

Protected _log

  • _log(msg: string, level?: LogLevel): void
  • Log a message back to the parrent @akera/web instance.

    Parameters

    • msg: string

      The log message

    • Default value level: LogLevel = LogLevel.info

      The log level

    Returns void

Protected _mount

  • _mount(broker?: string): express.Router
  • Returns a data access middleware that is either set to work with a specific broker or expect the broker alias to be sent as route parameter.

    This will mount the following routes:

    GET /$meta Return the catalog for all connected databases. GET /$meta/:db Return the catalog for just one database. GET /$meta/:db/:table Return the catalog for just one database table.

    GET /:db/:table/count Return the select count for one table (optional filter). GET /:db/:table Return the select records for one table (optional filter, fields, sort, paging). GET /:db/:table/ Return the one record select using primary key values (rest path parameter). POST /:db/:table Receives the records to be inserted in body and returns the new record(s). PUT /:db/:table/ Receives the record(s) to be updated in body and primary key values in route path and returns the updated record. DELETE /:db/:table/* Receives the record(s) to be deleted in body and primary key values in route path and returns the number of deleted records.

    Parameters

    • Optional broker: string

      The broker name.

    Returns express.Router

getCatalog

  • getCatalog(broker: string, fullLoad: boolean, dbName?: string, tableName?: string): Promise<ICatalog>
  • Return the catalog - the meta data information for connected databases of any application server (broker).

    Parameters

    • broker: string

      The broker name.

    • fullLoad: boolean

      Flag to completelly load all table information (fields, indexes).

    • Optional dbName: string

      The database name to load the catalog for, if not set all databases information are returned.

    • Optional tableName: string

      The table name if only one table information is needed, if not set all tables info are returned.

    Returns Promise<ICatalog>

init

  • init(): express.Router
  • Returns the middleware that can be mounted on an express route. If there is a single application server configured all requests on the route's root will be dispatched to that broker. When multiple application servers (different alias) are present in configuration then for each alias entry a separate 'sub-route' will be created and all requests on those routes will be dispatched to the respective application server. Requests made on route's root will be rejected with a 405 Method Not Allowed, those for a sub-route that doesn't match the name of any application server alias will be rejected with 404 Broker not found.

    Returns express.Router