-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support define options
queryKeyWhiteList.where
and `queryKeyW…
…hiteList.findBy`
- Loading branch information
1 parent
92aa08e
commit 1041058
Showing
19 changed files
with
1,403 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const orm = require('@fxjs/orm'); | ||
const util = require('util') | ||
|
||
const assert = require('assert') | ||
|
||
module.exports = db => { | ||
db.define('person_query', { | ||
name: String, | ||
sex: ["male", "female"], | ||
age: Number | ||
}, { | ||
validations: { | ||
age: orm.enforce.ranges.number(10, 18, "teenage") | ||
}, | ||
functions: { | ||
test: (req, data) => { | ||
return { | ||
success: { | ||
message: "test", | ||
data: data | ||
} | ||
} | ||
}, | ||
|
||
getPersonByName: (req, data) => { | ||
const app = db.app | ||
const findRep = app.api.find({ | ||
...req, | ||
query: { | ||
...req.query, | ||
where: {name: { eq: data.name }} | ||
} | ||
}, db, db.models['person_query']) | ||
|
||
if (findRep.error) { | ||
throw findRep.error | ||
} | ||
|
||
return { | ||
success: { | ||
message: 'ok', | ||
data: findRep.success.map(x => util.pick(x, 'name')) | ||
} | ||
}; | ||
} | ||
}, | ||
webx: { | ||
queryKeyWhiteList: { | ||
where: ['id'], | ||
} | ||
}, | ||
}); | ||
|
||
var PetQuery = db.define('pet_query', { | ||
name: String | ||
}, { | ||
webx: { | ||
queryKeyWhiteList: { | ||
findby: ['createdBy'], | ||
} | ||
}, | ||
}); | ||
|
||
PetQuery.hasOne('createdBy', db.models.person_query); | ||
PetQuery.hasOne('createdBy2', db.models.person_query); | ||
}; |
Oops, something went wrong.