Skip to main content

Retrieving

Important Note
All the functions metioned below are returning Promise. 
So whenever you are using it make sure you use async/await

getOne

To get a single or first record.

Syntax
getOne(modelName, options)
Example

await getOne('Users', {
where: {
is_active: 1,
is_deleted: 0
},
contain: ['Media']
});

// It will return object

getMany

To get multiple records.

Syntax
getMany(modelName, options)
Example

await getMany('Users', {
where: {
is_active: 1,
is_deleted: 0
},
select: ['id', 'first_name', 'last_name', 'username', 'updated_at'],
contain: ['Media'],
order: {
updated_at: 'DESC'
},
limit: 50
});

// It will return array

getList

It is same as getMany but it does returns list of records.

Syntax
getList(modelName, options)

getPagination

It will return the records with pagination information. such as how many total pages are there with total number of records.

Syntax
getPagination(modelName, options = { where: {}, page: 1, limit: 20 })

getCount

It will return the number of records or you can say just count.

Syntax
getCount(modelName, options)

Arguments

NameTypeDescription
modelNamestringModel name of a Database Table.
optionsobjectWhich records you wanted to fetch, so you can specify where conditions in it.