I'm new to nodejs Development and I currently practicing CRUD operations on my postgresql. I used Objection.js for the ORM and Model making. I follow some codes from the docs and edit necessary lines but I don't actually get it to success instead it returns this error:
builder.knex(...).queryBuilder is not a function
I am following MVC pattern so I seperate the files according to it.
My controller:
'use strict';
const Todo = require('./../models/Todo');
class TodoController {
createTodo() {
Todo
.query()
.insert({
'title': 'asdasdasda',
'description': 'sdasdasdasdasdsad',
'date': '2017-12-12',
'isActive': true,
})
.then(name => {
console.log(name.description);
})
.catch(err => {
console.log(err);
});
}
}
module.exports = TodoController;
Knex Schema:
knex.schema.createTableIfNotExists('todo', (table) => {
table.increments();
table.string('title', 255).notNullable();
table.text('description').notNullable();
table.boolean('isActive').defaultTo('false');
table.datetime('date').notNullable();
table.timestamp('createdAt').defaultTo(knex.fn.now());
})
Model:
'use strict';
const { Model } = require('objection');
class Todo extends Model {
static get tableName() {
return 'Todo';
}
}
module.exports = Todo;
server.js:
...
const KnexConfig = require('./knexfile');
const { Model } = require('objection');
...
...
Model.knex(KnexConfig.development);
Hopefully someone could guide me, I'm still newbie on nodejs