IAdminForthDataSourceConnectorBase
Interface that exposes methods to interact with AdminForth in standard way
Extends
Methods
createRecord()
createRecord(
__namedParameters
):Promise
<object
>
Parameters
Parameter | Type |
---|---|
__namedParameters | object |
__namedParameters.adminUser | AdminUser |
__namedParameters.record | any |
__namedParameters.resource | AdminForthResource |
Returns
Promise
<object
>
createdRecord?
optional
createdRecord:any
error?
optional
error:string
ok
ok:
boolean
createRecordOriginalValues()
createRecordOriginalValues(
__namedParameters
):Promise
<void
>
Used to create record in database.
Parameters
Parameter | Type |
---|---|
__namedParameters | object |
__namedParameters.record | any |
__namedParameters.resource | AdminForthResource |
Returns
Promise
<void
>
Inherited from
IAdminForthDataSourceConnector
. createRecordOriginalValues
deleteRecord()
deleteRecord(
__namedParameters
):Promise
<boolean
>
Used to delete record in database.
Parameters
Parameter | Type |
---|---|
__namedParameters | object |
__namedParameters.recordId | any |
__namedParameters.resource | AdminForthResource |
Returns
Promise
<boolean
>
Inherited from
IAdminForthDataSourceConnector
. deleteRecord
discoverFields()
discoverFields(
resource
):Promise
<object
>
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:
- 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 |
Returns
Promise
<object
>
Inherited from
IAdminForthDataSourceConnector
. discoverFields
getCount()
getCount(
__namedParameters
):Promise
<number
>
Used to get count of records in database.
Parameters
Parameter | Type |
---|---|
__namedParameters | object |
__namedParameters.filters | IAdminForthFilter [] |
__namedParameters.resource | AdminForthResource |
Returns
Promise
<number
>
Inherited from
IAdminForthDataSourceConnector
. getCount
getData()
getData(
__namedParameters
):Promise
<object
>
Parameters
Parameter | Type |
---|---|
__namedParameters | object |
__namedParameters.filters | IAdminForthFilter [] |
__namedParameters.getTotals ? | boolean |
__namedParameters.limit | number |
__namedParameters.offset | number |
__namedParameters.resource | AdminForthResource |
__namedParameters.sort | IAdminForthSort [] |
Returns
Promise
<object
>
data
data:
any
[]
total
total:
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 | object |
__namedParameters.filters | IAdminForthFilter [] |
__namedParameters.limit | number |
__namedParameters.offset | number |
__namedParameters.resource | AdminForthResource |
__namedParameters.sort | IAdminForthSort [] |
Returns
Promise
<any
[]>
Inherited from
IAdminForthDataSourceConnector
. getDataWithOriginalTypes
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
Inherited from
IAdminForthDataSourceConnector
. getFieldValue
getMinMaxForColumns()
getMinMaxForColumns(
__namedParameters
):Promise
<object
>
Parameters
Parameter | Type |
---|---|
__namedParameters | object |
__namedParameters.columns | AdminForthResourceColumn [] |
__namedParameters.resource | AdminForthResource |
Returns
Promise
<object
>
getMinMaxForColumnsWithOriginalTypes()
getMinMaxForColumnsWithOriginalTypes(
__namedParameters
):Promise
<object
>
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 | object |
__namedParameters.columns | AdminForthResourceColumn [] |
__namedParameters.resource | AdminForthResource |
Returns
Promise
<object
>
Inherited from
IAdminForthDataSourceConnector
. getMinMaxForColumnsWithOriginalTypes
getPrimaryKey()
getPrimaryKey(
resource
):string
Parameters
Parameter | Type |
---|---|
resource | AdminForthResource |
Returns
string
getRecordByPrimaryKey()
getRecordByPrimaryKey(
resource
,recordId
):Promise
<any
>
Parameters
Parameter | Type |
---|---|
resource | AdminForthResource |
recordId | string |
Returns
Promise
<any
>
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
>
Inherited from
IAdminForthDataSourceConnector
. getRecordByPrimaryKeyWithOriginalTypes
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
Inherited from
IAdminForthDataSourceConnector
. setFieldValue
updateRecord()
updateRecord(
__namedParameters
):Promise
<object
>
Parameters
Parameter | Type |
---|---|
__namedParameters | object |
__namedParameters.newValues | any |
__namedParameters.recordId | string |
__namedParameters.resource | AdminForthResource |
Returns
Promise
<object
>
error?
optional
error:string
ok
ok:
boolean
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
Parameters
Parameter | Type |
---|---|
__namedParameters | object |
__namedParameters.newValues | any |
__namedParameters.recordId | string |
__namedParameters.resource | AdminForthResource |
Returns
Promise
<void
>