I wish to create view that collectively shows data from multiple tables in my mysql database. Project is nodeJS based.
npm versions using "bookshelf": "^0.14.2" & "knex": "^0.17.6". migration failed with error: knex.schema.createView is not a function.
migration file content are as follows:
exports.up = function(knex, Promise) {
return knex.schema.createView('sp_form_view', function(view) {
view.columns(['first_name']);
view.as(knex('sp_form').select('first_name').where('id','>', 20));
});
};
exports.down = function(knex, Promise) {
return knex.schema.dropView('sp_form_view');
};
I tried creation of view using migration command as knex migrate:latest. I got error as createView is not a function.
View support wasn't added to Knex until version 0.95.12 (https://github.com/knex/knex/blob/master/CHANGELOG.md#09512---28-october-2021)
If you are not able to update your knex version you'll need to use
knex.raw