Options
All
  • Public
  • Public/Protected
  • All
Menu

Class JSDODataAccess

The JSDO implementation of the data access interface.

Hierarchy

Implements

Index

Constructors

constructor

  • Parameters

    • jsdoHandler: JSDOHandler

      The JDSO data access handler.

    • Default value asDataset: boolean = true

      Flag to use the dataset data structure format.

    • Default value sqlSafe: boolean = true

      Flag to 'translate' table/field names to SQL safe names.

    Returns JSDODataAccess

Properties

Protected _dataHandler

_dataHandler: IDataHandler

Methods

doDelete

  • doDelete(broker: string, req: express.Request, res: express.Response): Promise<void>
  • Delete a single record from the database table, primary key and fields values available through query params in request.

    Parameters

    • broker: string

      The broker alias to connect to.

    • req: express.Request

      The Express request object, the way route/query params are used depends on the implementation.

    • res: express.Response

      The Express response object, the function should not throw any error but send the error message in response.

    Returns Promise<void>

doDeleteByRowid

  • doDeleteByRowid(broker: string, req: express.Request, res: express.Response): Promise<void>
  • Delete a single record from the database table, record identifier (rowid) and fields values available through query params in request.

    Parameters

    • broker: string

      The broker alias to connect to.

    • req: express.Request

      The Express request object, the way route/query params are used depends on the implementation.

    • res: express.Response

      The Express response object, the function should not throw any error but send the error message in response.

    Returns Promise<void>

doInsert

  • doInsert(broker: string, req: express.Request, res: express.Response): Promise<void>
  • Insert a single record into the database table, fields values (including the primary key) available through query params in request.

    Parameters

    • broker: string

      The broker alias to connect to.

    • req: express.Request

      The Express request object, the way route/query params are used depends on the implementation.

    • res: express.Response

      The Express response object, the function should not throw any error but send the error message in response.

    Returns Promise<void>

doSelect

  • doSelect(broker: string, req: express.Request, res: express.Response): Promise<void>
  • Select multiple records from one database table, filter, sort and fields selection available through query params in request.

    Parameters

    • broker: string

      The broker alias to connect to.

    • req: express.Request

      The Express request object, the way route/query params are used depends on the implementation.

    • res: express.Response

      The Express response object, the function should not throw any error but send the error message in response.

    Returns Promise<void>

doSelectCount

  • doSelectCount(broker: string, req: express.Request, res: express.Response): Promise<void>
  • Select the total number of records from one database table, filter selection available through query params in request.

    Parameters

    • broker: string

      The broker alias to connect to.

    • req: express.Request

      The Express request object, the way route/query params are used depends on the implementation.

    • res: express.Response

      The Express response object, the function should not throw any error but send the error message in response.

    Returns Promise<void>

doSelectRecord

  • doSelectRecord(broker: string, req: express.Request, res: express.Response): Promise<void>
  • Select a single record from the database table, primary key and fields selection available through query params in request.

    Parameters

    • broker: string

      The broker alias to connect to.

    • req: express.Request

      The Express request object, the way route/query params are used depends on the implementation.

    • res: express.Response

      The Express response object, the function should not throw any error but send the error message in response.

    Returns Promise<void>

doUpdate

  • doUpdate(broker: string, req: express.Request, res: express.Response): Promise<void>
  • Override of abstract implementation method. If 'rest' path parameters are present then a single record update is done using the primary key values sent through the path parameter.

    Otherwise a 'save changes' operation is performed so not only updates but also new or deleted records are processed using the information from 'before-image'.

    Parameters

    • broker: string

      The broker name.

    • req: express.Request

      The express Request object.

    • res: express.Response

      The express Response object.

    Returns Promise<void>

doUpdateByRowid

  • doUpdateByRowid(broker: string, req: express.Request, res: express.Response): Promise<void>
  • Update a single record from the database table, record identifier (rowid) and fields values available through query params in request.

    Parameters

    • broker: string

      The broker alias to connect to.

    • req: express.Request

      The Express request object, the way route/query params are used depends on the implementation.

    • res: express.Response

      The Express response object, the function should not throw any error but send the error message in response.

    Returns Promise<void>

Protected endConnection

  • endConnection(connection: IConnection, broker: string): Promise<void>
  • Signal the @akera/web instance that a connection is not needed.

    Parameters

    • connection: IConnection

      The connection that is not needed anymore.

    • broker: string

      The broker on which the connection is established.

    Returns Promise<void>

Protected getConnection

  • getConnection(broker: string): Promise<IConnection>
  • Establish a connection to one application server.

    Parameters

    • broker: string

      The broker alias to connect to, the connection is managed by the @akera/web instance.

    Returns Promise<IConnection>

Protected getDeleteRecords

  • getDeleteRecords(table: ITable, data: Object): Record[]
  • Returns the records to be deleted from a given table.

    If dataset structure is used records from before image with state [JSDOState.DELETED] are considered.

    Parameters

    • table: ITable

      The table name (used for dataset structure).

    • data: Object

      The data structure (array for table, object for dataset).

    Returns Record[]

Protected getInsertRecords

  • getInsertRecords(table: ITable, data: Object): Record[]
  • Returns the records to be inserted into a given table.

    If dataset structure is used records from current image with state [JSDOState.CREATED] are considered.

    Parameters

    • table: ITable

      The table name (used for dataset structure).

    • data: Object

      The data structure (array for table, object for dataset).

    Returns Record[]

Protected getPrimaryKeyFilter

  • getPrimaryKeyFilter(table: ITable, keyPath: string): Promise<Filter>
  • Returns the primary key filter for a table using the primary key values passed as rest parameter in request. If the table does not have a primary key or not all values for the fields part of the primary key index are not specified this will be rejected with an error.

    Parameters

    • table: ITable

      The table name.

    • keyPath: string

      The primary key values as string (path format, backslash separator).

    Returns Promise<Filter>

Protected getRecordFilter

  • getRecordFilter(table: ITable, row: Record): Promise<Filter>
  • Return a primary key filter using values from the table record. If the table does not have a primary key or not all fields of the primary key have values set in the table record this will be rejected with an error.

    Parameters

    • table: ITable

      The table buffer.

    • row: Record

      The table record.

    Returns Promise<Filter>

Protected getRequestBody

  • getRequestBody(req: express.Request): Object
  • Make sure we have the request body parsed so we can use in case of requests that expects JSON body, a body parser is needed for this to work.

    Parameters

    • req: express.Request

      The express Request to read body information from.

    Returns Object

Protected getRequestTable

  • getRequestTable(conn: IConnection, req: express.Request): Promise<ITable>
  • Returns a table buffer instance from given connection or is rejected with an error if table is not found.

    Parameters

    • conn: IConnection

      The API connection to use.

    • req: express.Request

      The express Request holding database and table information (path parameters).

    Returns Promise<ITable>

Protected getRestRequestParam

  • getRestRequestParam(req: express.Request): string
  • Return the 'rest' path parameter from an express Request, if any.

    Parameters

    • req: express.Request

      The express Request.

    Returns string

Protected getSelectQuery

  • getSelectQuery(req: express.Request, connection: IConnection, table: ITable, pkFilter?: Filter, useFields?: boolean, usePage?: boolean, useSort?: boolean): Promise<QuerySelect>
  • Override of abstract implementation method to parse filter information according to the JSDO protocol (abl filter).

    Parameters

    • req: express.Request

      The express Request object used to parse filter information.

    • connection: IConnection

      The API connection to run the select query on.

    • table: ITable

      The table name to select records from.

    • Optional pkFilter: Filter

      The primary key filter from Request path/query string.

    • Default value useFields: boolean = false

      The JSDO does not support filter selection.

    • Default value usePage: boolean = false

      If the query should use pagination information from Request.

    • Default value useSort: boolean = false

      If the query should use sort information from Request.

    Returns Promise<QuerySelect>

Protected getUpdateRecords

  • getUpdateRecords(table: ITable, data: Object, clean?: boolean): Record[]
  • Returns the records to be updated for a given table.

    If dataset structure is used records from current image with state [JSDOState.UPDATED] are considered.

    Parameters

    • table: ITable

      The table name (used for dataset structure).

    • data: Object

      The data structure (array for table, object for dataset).

    • Default value clean: boolean = true

      Flag to remove any prodataset internal properties (state, id).

    Returns Record[]

Protected writeDeletes

  • writeDeletes(table: ITable, affected: number, res: express.Response): void
  • Writes the deleted records result response back. Default implementation sends a JSON object with the deleted property set.

    If no record was found to be delete a 404 Record not found error will be returned.

    Parameters

    • table: ITable

      The table buffer.

    • affected: number

      The number of records deleted.

    • res: express.Response

      The express Response to write to.

    Returns void

Protected writeInserts

  • writeInserts(table: ITable, records: Record[], res: express.Response): void
  • Writes the inserted records result response back.

    The inserted records are sent back in the same way as for select, the format depends on whether the dataset format is used or not.

    Parameters

    • table: ITable

      The table buffer.

    • records: Record[]

      The table records array of the insert query.

    • res: express.Response

      The express Response to write to.

    Returns void

Protected writeSelect

  • writeSelect(table: ITable, records: Record[], res: express.Response): void
  • Writes the select records result response back either using a dataset format or the default implementation.

    Parameters

    • table: ITable

      The table buffer.

    • records: Record[]

      The table records array of the select query.

    • res: express.Response

      The express Response to write to.

    Returns void

Protected writeSelectCount

  • writeSelectCount(table: ITable, count: number, res: express.Response): void
  • Writes the select count response back. JSDO implementation sends a JSON object with an response object having the numRecs property set.

    Parameters

    • table: ITable

      The table buffer.

    • count: number

      The total number of records for the select query executed.

    • res: express.Response

      The express Response to write to.

    Returns void

Protected writeSelectRecord

  • writeSelectRecord(table: ITable, records: Record[], res: express.Response): void
  • Writes the selected record response back.

    JSDO expects an array even if only one record is selected.

    Parameters

    • table: ITable

      The table buffer.

    • records: Record[]

      The table records array of the select query, it should have at most one item.

    • res: express.Response

      The express Response to write to.

    Returns void

Protected writeUpdates

  • writeUpdates(table: ITable, records: Record[], res: express.Response): void
  • Writes the updated records result response back.

    The updated records are sent back in the same way as for select, the format depends on whether the dataset format is used or not.

    Parameters

    • table: ITable

      The table buffer.

    • records: Record[]

      The table records array of the update query.

    • res: express.Response

      The express Response to write to.

    Returns void