Closed BlueAccords closed 6 years ago
Yes, the Model
absolutely is compatible with koa! It doesn't do anything hapi-specific: it just provides joi validation on top of objection models and sets jsonAttributes
based upon your joi schema 👍
alright thanks! So I just have to setup my joi schema inside of static get joiSchema() {
for each model for the validation I want and I should be good to go?
Yep, the model class just needs tableName
and joiSchema
static properties, so this works equally well,
const User = module.exports = class User extends Schwifty.Model {};
User.tableName = 'Users';
User.joiSchema = Joi.object({
id: Joi.number(),
name: Joi.string()
});
Mmmk, Also in the joi docs the syntax uses
const schema = Joi.object().keys({
...
})
Is there a difference between Joi.object().keys({ ... })
vs Joi.object({ ... })
?
There's a good section about this in the joi docs (https://github.com/hapijs/joi/blob/master/API.md#objectkeysschema). Some decent places to ask questions about joi usage are hapijs/discuss, the hapi slack, or hapijs/hapi on gitter.
Alright i'll look through it, thanks for the help!
Just wondering but is this compatible with koa.js as well https://github.com/koajs?
If so, does it require any specific changes or can I just extend like in the given example for my objection.js models?