From 59145a8db03a43bf960861c037bbeb29967624cc Mon Sep 17 00:00:00 2001 From: chenos Date: Fri, 3 Dec 2021 10:13:38 +0800 Subject: [PATCH] docs: update doc --- docs/reference/database.md | 80 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/docs/reference/database.md b/docs/reference/database.md index 167805661..dbe7bfd78 100644 --- a/docs/reference/database.md +++ b/docs/reference/database.md @@ -482,6 +482,86 @@ repository.find({ }); ``` +更多例子: + +```ts +db.collection({ + name: 'users', + fields: [ + { type: 'date', name: 'birthday' }, + ], +}); + +db.collection({ + name: 'posts', + fields: [ + { type: 'belongsTo', name: 'user' }, + ], +}); + +repository.find({ + filter: { + 'birthday.$dateOn': '1999-01-02', + }, +}); + +db.registerOperators({ + dateOn: (value, ctx) => { + console.log(value) // 1999-01-02 + console.log(ctx.path) // birthday + } +}); + +repository.find({ + filter: { + $and: [ + { 'birthday.$dateOn': '1999-01-02' }, + ] + }, +}); + +db.registerOperators({ + dateOn: (value, ctx) => { + console.log(value) // 1999-01-02 + console.log(ctx.path) // birthday + }, +}); + +repository.find({ + filter: { + $and: [ + { 'user.birthday.$dateOn': '1999-01-02' }, + ] + }, +}); + +db.registerOperators({ + dateOn: (value, ctx) => { + console.log(value) // 1999-01-02 + console.log(ctx.path) // user.birthday + }, +}); + +repository.find({ + filter: { + $or: [ + { + $and: [ + {'user.birthday.$dateOn': '1999-01-02'} + ], + }, + ], + }, +}); + +db.registerOperators({ + dateOn: (value, ctx) => { + console.log(value) // 1999-01-02 + console.log(ctx.path) // user.birthday + } +}); +``` + ## `db.registerRepositories()` 待完善 自定义 Repository