IAdminForthDataSourceConnector
Extended by
Properties
client
client:
any
supportsCompositePrimaryKey?
optionalsupportsCompositePrimaryKey?:boolean
Set to true if connector is able to work with resources which have several columns marked as
AdminForthResourceColumn.primaryKey (composite primary key).
Such connector must build WHERE clause from pkValues argument of
IAdminForthDataSourceConnector.updateRecordOriginalValues and
IAdminForthDataSourceConnector.deleteRecord instead of using getPrimaryKey().
Methods
createRecordOriginalValues()
createRecordOriginalValues(
__namedParameters):Promise<string>
Used to create record in database. Should return value of primary key column of created record.
Parameters
| Parameter | Type |
|---|---|
__namedParameters | { record: any; resource: AdminForthResource; } |
__namedParameters.record | any |
__namedParameters.resource | AdminForthResource |
Returns
Promise<string>
deleteRecord()
deleteRecord(
__namedParameters):Promise<boolean>
Used to delete record in database. pkValues is map of primary key column name to its value, use it to build WHERE clause (it supports both single and composite primary keys).
Parameters
| Parameter | Type |
|---|---|
__namedParameters | { pkValues?: Record<string, any>; recordId: any; resource: AdminForthResource; } |
__namedParameters.pkValues? | Record<string, any> |
__namedParameters.recordId | any |
__namedParameters.resource | AdminForthResource |
Returns
Promise<boolean>
discoverFields()
discoverFields(
resource,config):Promise<{[key:string]:AdminForthResourceColumn; }>
Function should go over all columns of table defined in resource.table and try to guess data and constraints for each columns. Type should be saved to:
- AdminForthResourceColumn.type Constraints:
- AdminForthResourceColumn.required
- AdminForthResourceColumn.primaryKey For string fields:
- AdminForthResourceColumn.maxLength For numbers: // min/max are used inside getMinMaxForColumns from base connector
- AdminForthResourceColumn.min
- AdminForthResourceColumn.max
- AdminForthResourceColumn.minValue,
- AdminForthResourceColumn.maxValue,
- AdminForthResourceColumn.enum,
- AdminForthResourceColumn.foreignResource,
- AdminForthResourceColumn.sortable,
- AdminForthResourceColumn.backendOnly,
- AdminForthResourceColumn.masked,
- AdminForthResourceColumn.virtual,
- AdminForthResourceColumn.components,
- AdminForthResourceColumn.allowMinMaxQuery,
- AdminForthResourceColumn.editingNote,
- AdminForthResourceColumn.showIn,
- AdminForthResourceColumn.isUnique,
- AdminForthResourceColumn.validation) Also you can additionally save original column type to AdminForthResourceColumn._underlineType. This might be later used in IAdminForthDataSourceConnector.getFieldValue and IAdminForthDataSourceConnector.setFieldValue methods.
Parameters
| Parameter | Type | Description |
|---|---|---|
resource | AdminForthResource | - |
config | AdminForthConfig | - |
Returns
Promise<{[key: string]: AdminForthResourceColumn; }>
getAggregateWithOriginalTypes()?
optionalgetAggregateWithOriginalTypes(__namedParameters):Promise<object[]>
Optional. Used to perform aggregation queries on a resource table. Returns rows with aliased aggregate values and optional group key.
Parameters
| Parameter | Type |
|---|---|
__namedParameters | { aggregations: {[alias: string]: IAggregationRule; }; filters: IAdminForthAndOrFilter; groupBy?: IGroupByRule | IGroupByRule[]; resource: AdminForthResource; } |
__namedParameters.aggregations | {[alias: string]: IAggregationRule; } |
__namedParameters.filters | IAdminForthAndOrFilter |
__namedParameters.groupBy? | IGroupByRule | IGroupByRule[] |
__namedParameters.resource | AdminForthResource |
Returns
Promise<object[]>
getAllColumnsInTable()
getAllColumnsInTable(
tableName):Promise<object[]>
Function to get all columns in table.
Parameters
| Parameter | Type |
|---|---|
tableName | string |
Returns
Promise<object[]>
getAllTables()
getAllTables():
Promise<string[]>
Function to get all tables from database.
Returns
Promise<string[]>
getCount()
getCount(
__namedParameters):Promise<number>
Used to get count of records in database.
Parameters
| Parameter | Type |
|---|---|
__namedParameters | { filters: IAdminForthAndOrFilter; resource: AdminForthResource; } |
__namedParameters.filters | IAdminForthAndOrFilter |
__namedParameters.resource | AdminForthResource |
Returns
Promise<number>
getDataWithOriginalTypes()
getDataWithOriginalTypes(
__namedParameters):Promise<any[]>
Used to fetch data from database. This method is reused both to list records and show one record (by passing limit 1 and offset 0) .
Fields are returned from db "as is" then AdminForthBaseConnector.getData will transform each field using IAdminForthDataSourceConnector.getFieldValue
Parameters
| Parameter | Type |
|---|---|
__namedParameters | { columns?: AdminForthResourceColumn[]; filters: IAdminForthAndOrFilter; limit: number; offset: number; resource: AdminForthResource; sort: IAdminForthSort[]; } |
__namedParameters.columns? | AdminForthResourceColumn[] |
__namedParameters.filters | IAdminForthAndOrFilter |
__namedParameters.limit | number |
__namedParameters.offset | number |
__namedParameters.resource | AdminForthResource |
__namedParameters.sort | IAdminForthSort[] |
Returns
Promise<any[]>
getFieldValue()
getFieldValue(
field,value):any
Used to transform record after fetching from database. According to AdminForth convention, if AdminForthResourceColumn.type is set to AdminForthDataTypes.DATETIME then it should be transformed to ISO string.
Parameters
| Parameter | Type | Description |
|---|---|---|
field | AdminForthResourceColumn | - |
value | any | - |
Returns
any
getMinMaxForColumnsWithOriginalTypes()
getMinMaxForColumnsWithOriginalTypes(
__namedParameters):Promise<ColumnMinMaxValue>
Optional method which used to get min and max values for columns in resource. Called only for columns which have AdminForthResourceColumn.allowMinMaxQuery set to true.
Internally should call IAdminForthDataSourceConnector.getFieldValue for both min and max values.
Parameters
| Parameter | Type |
|---|---|
__namedParameters | { columns: AdminForthResourceColumn[]; resource: AdminForthResource; } |
__namedParameters.columns | AdminForthResourceColumn[] |
__namedParameters.resource | AdminForthResource |
Returns
Promise<ColumnMinMaxValue>
getRecordByPrimaryKeyWithOriginalTypes()
getRecordByPrimaryKeyWithOriginalTypes(
resource,recordId):Promise<any>
Optional. You an redefine this function to define how one record should be fetched from database. You you will not redefine it, AdminForth will use IAdminForthDataSourceConnector.getData with limit 1 and offset 0 and filter by primary key.
Parameters
| Parameter | Type |
|---|---|
resource | AdminForthResource |
recordId | string |
Returns
Promise<any>
isDatabaseEmpty()?
optionalisDatabaseEmpty():Promise<boolean>
Function to check whether database has no user data.
Returns
Promise<boolean>
setFieldValue()
setFieldValue(
field,value):any
Used to transform record before saving to database. Should perform operation inverse to IAdminForthDataSourceConnector.getFieldValue
Parameters
| Parameter | Type | Description |
|---|---|---|
field | AdminForthResourceColumn | - |
value | any | - |
Returns
any
setupClient()
setupClient(
url,options?):Promise<void>
Function to setup client connection to database.
Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | URL to database. Examples: clickhouse://demo:demo@localhost:8125/demo |
options? | { recovery?: boolean; } | Optional connection options. recovery mirrors the dataSource connectionRecovery flag (defaults to true when omitted). |
options.recovery? | boolean | - |
Returns
Promise<void>
updateRecordOriginalValues()
updateRecordOriginalValues(
__namedParameters):Promise<void>
Update record in database. newValues might have not all fields in record, but only changed ones. recordId is value of field which is marked as AdminForthResourceColumn.primaryKey, or, for resources with composite primary key, encoded value of all such columns. pkValues is map of primary key column name to its value, use it to build WHERE clause (it supports both single and composite primary keys).
Parameters
| Parameter | Type |
|---|---|
__namedParameters | { newValues: any; pkValues?: Record<string, any>; recordId: string; resource: AdminForthResource; } |
__namedParameters.newValues | any |
__namedParameters.pkValues? | Record<string, any> |
__namedParameters.recordId | string |
__namedParameters.resource | AdminForthResource |
Returns
Promise<void>