Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AbstractDataAccess

Abstract partial implementation of the CRUD data access interface.

Hierarchy

Index

Constructors

constructor

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

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.

    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.

    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>
  • Returns the select query to be used to fetch table records.

    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

      If the query should use field selection information from Request.

    • 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): Record[]
  • Returns the records to be updated for a given table.

    Parameters

    • table: ITable

      The table name (used for dataset structure).

    • data: Object

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

    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. Default implementation sends a JSON array with the returned new records.

    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. Default implementation sends a JSON array with the returned records.

    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. Default implementation sends a JSON object with the count 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 a single record selected (by PK or ROWID) response back. Default implementation sends a JSON object with the returned record.

    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. Default implementation sends a JSON array with the returned updated records.

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

    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