I'm using Knex.js (along with Bookshelf.js) with a PostreSQL DB and I'm trying to "extract" the SQL schema in order to use it with something like Joi or Checkit.
Here just a simple example:
The schema written with knex:
return knex.schema.createTable('users', table => {
table.string('username').notNullable()
table.string('password')
})
And what I would like to automatically get:
const schema = Joi.object().keys({
username: Joi.string().required(),
password: Joi.string()
})
The point is simply to avoid writting the schema twice and having a programmatically way to validated the objects, before passing it to bookshelf/knex. Are there any built-ins ways to do it? Or any best practice?
via Cohars
No comments:
Post a Comment