Options
All
  • Public
  • Public/Protected
  • All
Menu

Class JSDOHandler

The JSDO implementation of the data access handler.

This will support basic CRUD operations as exposed in a JSDO catalog for business entities.

Hierarchy

Implements

Index

Constructors

constructor

  • new JSDOHandler(webApp: AkeraWeb, asDataset?: boolean, sqlSafe?: boolean): JSDOHandler
  • If before image information is not needed asDataset option can be set to false in which case the data will be serialized in a simple temp-table format.

    Parameters

    • webApp: AkeraWeb

      The @akera/web web handler instance.

    • Default value asDataset: boolean = true

      If set to true data will be serialized using a dataset format.

    • Default value sqlSafe: boolean = false

      If set to true the table/field names will be made SQL safe.

    Returns JSDOHandler

Properties

Protected _name

_name: string = ""

Protected _router

_router: express.Router

Protected _webApp

_webApp: AkeraWeb

Accessors

Protected dataHandler

  • Returns the actual data access handler instance that will handle basic CRUD operations.

    Returns JSDODataAccess

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 records. PUT /:db/:table Receives the record(s) to be updated in body and returns the updated records. DELETE /:db/:table* Receives the record(s) to be deleted in body and returns the number of deleted records.

    Parameters

    • Optional broker: string

      The broker name.

    Returns express.Router

getCatalog

  • getCatalog(broker: string, 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.

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

getSqlName

  • getSqlName(name: string): string
  • Return an SQL safe name, reserved characters are replaced.

    Parameters

    • name: string

      The table/field name to make SQL safe.

    Returns string

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