docs: update doc

This commit is contained in:
chenos 2021-12-03 11:01:50 +08:00
parent 7b7902a0dc
commit 17b34980a8
2 changed files with 42 additions and 0 deletions

View File

@ -509,6 +509,7 @@ db.registerOperators({
dateOn: (value, ctx) => {
console.log(value) // 1999-01-02
console.log(ctx.path) // birthday
console.log(ctx.field) // ctx.field instanceof DateField
}
});
@ -524,6 +525,7 @@ db.registerOperators({
dateOn: (value, ctx) => {
console.log(value) // 1999-01-02
console.log(ctx.path) // birthday
console.log(ctx.field) // ctx.field instanceof DateField
},
});
@ -539,6 +541,7 @@ db.registerOperators({
dateOn: (value, ctx) => {
console.log(value) // 1999-01-02
console.log(ctx.path) // user.birthday
console.log(ctx.field) // ctx.field instanceof DateField
},
});
@ -558,6 +561,7 @@ db.registerOperators({
dateOn: (value, ctx) => {
console.log(value) // 1999-01-02
console.log(ctx.path) // user.birthday
console.log(ctx.field) // ctx.field instanceof DateField
}
});
```

View File

@ -61,6 +61,8 @@ await repository.find({
'nested.someAttribute': {
// 同上
},
// scope 的情况
scopeName: 'val1',
},
// 字段白名单
fields: [],
@ -162,6 +164,42 @@ await Post.repository.find({
});
```
也支持 [scopes](https://sequelize.org/master/manual/scopes.html)
```ts
Post.model.addScope('published', () => {
return {
where: {
status: 'published',
},
}
});
await Post.repository.find({
filter: {
published: true,
},
});
```
如果 scope name 和 field name 冲突时scope 优先级更高
```ts
Post.model.addScope('level', (value) => {
return {
where: {
level: { [Op.gte]: value }
},
}
});
await Post.repository.find({
filter: {
level: 1,
},
});
```
###### sort 参数示例说明
指定一组数据的排序,倒序时在字段前加上减号 `-`