Model API
- Model API (
ModelRepository
methods) is actually implemented by using Query Builder. - But it provides a simpler way to carry out
create
,update
anddelete
operations on a Model.
.createOne()
- Creates one record of Model Example:
const createdRecord = await context.ModelRepo1.createOne(data)
1
.createEach()
- Creates many record of Model
- The records are created one by one in multiple sql statements
Example:
const createdRecords = await context.ModelRepo1.createEach(arrayOfData)
1
.update()
delete()
deleteOne()
find()
findOne()
findOneOrNull()
findOptions
select
selectProps
where
- Model API is implemented by using Query Builder.
- The
where
option is passed to the Builder. For more options, please see where - But the target Model (table) is assigned a table alias with 'root'. About table alias, please see Datasource.
Example:
const records = await context.ModelRepo1.find({
where: ({root}) => root.id.equals(1)
})
1
2
3
2
3
It equals to dataset
const records = await context.dataset()
.from(ModelRepo1.datasource('root'))
.where({
'root.id': 1
}).execute()
1
2
3
4
5
2
3
4
5