Skip to main content

IAdminForthDataSourceConnectorBase

Interface that exposes methods to interact with AdminForth in standard way

Extends

Methods

createRecord()

createRecord(__namedParameters): Promise<object>

Parameters

ParameterType
__namedParametersobject
__namedParameters.adminUserAdminUser
__namedParameters.recordany
__namedParameters.resourceAdminForthResource

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

ParameterType
__namedParametersobject
__namedParameters.recordany
__namedParameters.resourceAdminForthResource

Returns

Promise<void>

Inherited from

IAdminForthDataSourceConnector . createRecordOriginalValues


deleteRecord()

deleteRecord(__namedParameters): Promise<boolean>

Used to delete record in database.

Parameters

ParameterType
__namedParametersobject
__namedParameters.recordIdany
__namedParameters.resourceAdminForthResource

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

ParameterTypeDescription
resourceAdminForthResource

Returns

Promise<object>

Inherited from

IAdminForthDataSourceConnector . discoverFields


getCount()

getCount(__namedParameters): Promise<number>

Used to get count of records in database.

Parameters

ParameterType
__namedParametersobject
__namedParameters.filtersIAdminForthFilter[]
__namedParameters.resourceAdminForthResource

Returns

Promise<number>

Inherited from

IAdminForthDataSourceConnector . getCount


getData()

getData(__namedParameters): Promise<object>

Parameters

ParameterType
__namedParametersobject
__namedParameters.filtersIAdminForthFilter[]
__namedParameters.getTotals?boolean
__namedParameters.limitnumber
__namedParameters.offsetnumber
__namedParameters.resourceAdminForthResource
__namedParameters.sortIAdminForthSort[]

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

ParameterType
__namedParametersobject
__namedParameters.filtersIAdminForthFilter[]
__namedParameters.limitnumber
__namedParameters.offsetnumber
__namedParameters.resourceAdminForthResource
__namedParameters.sortIAdminForthSort[]

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

ParameterTypeDescription
fieldAdminForthResourceColumn
valueany

Returns

any

Inherited from

IAdminForthDataSourceConnector . getFieldValue


getMinMaxForColumns()

getMinMaxForColumns(__namedParameters): Promise<object>

Parameters

ParameterType
__namedParametersobject
__namedParameters.columnsAdminForthResourceColumn[]
__namedParameters.resourceAdminForthResource

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

ParameterType
__namedParametersobject
__namedParameters.columnsAdminForthResourceColumn[]
__namedParameters.resourceAdminForthResource

Returns

Promise<object>

Inherited from

IAdminForthDataSourceConnector . getMinMaxForColumnsWithOriginalTypes


getPrimaryKey()

getPrimaryKey(resource): string

Parameters

ParameterType
resourceAdminForthResource

Returns

string


getRecordByPrimaryKey()

getRecordByPrimaryKey(resource, recordId): Promise<any>

Parameters

ParameterType
resourceAdminForthResource
recordIdstring

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

ParameterType
resourceAdminForthResource
recordIdstring

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

ParameterTypeDescription
fieldAdminForthResourceColumn
valueany

Returns

any

Inherited from

IAdminForthDataSourceConnector . setFieldValue


updateRecord()

updateRecord(__namedParameters): Promise<void>

Used to update record in database. recordId is value of field which is marked as AdminForthResourceColumn.primaryKey newValues is array of fields which should be updated (might be not all fields in record, but only changed fields).

Parameters

ParameterType
__namedParametersobject
__namedParameters.newValuesany
__namedParameters.recordIdstring
__namedParameters.resourceAdminForthResource

Returns

Promise<void>

Inherited from

IAdminForthDataSourceConnector . updateRecord