From 17b34980a85203f564ab7e4457acd63084ef5ff0 Mon Sep 17 00:00:00 2001 From: chenos Date: Fri, 3 Dec 2021 11:01:50 +0800 Subject: [PATCH] docs: update doc --- docs/reference/database.md | 4 ++++ docs/reference/repository.md | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/docs/reference/database.md b/docs/reference/database.md index dbe7bfd78..a64ee67ea 100644 --- a/docs/reference/database.md +++ b/docs/reference/database.md @@ -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 } }); ``` diff --git a/docs/reference/repository.md b/docs/reference/repository.md index 46a28ae97..fbace998b 100644 --- a/docs/reference/repository.md +++ b/docs/reference/repository.md @@ -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 参数示例说明 指定一组数据的排序,倒序时在字段前加上减号 `-`