knex/lib/dialects/sqlite3/schema/sqlite-viewcompiler.js

41 lines
935 B
JavaScript
Raw Permalink Normal View History

2021-10-20 22:23:29 +02:00
/* eslint max-len: 0 */
const ViewCompiler = require('../../../schema/viewcompiler.js');
const {
columnize: columnize_,
} = require('../../../formatter/wrappingFormatter');
2021-10-20 22:23:29 +02:00
class ViewCompiler_SQLite3 extends ViewCompiler {
2021-10-20 22:23:29 +02:00
constructor(client, viewCompiler) {
super(client, viewCompiler);
}
createOrReplace() {
const columns = this.columns;
const selectQuery = this.selectQuery.toString();
const viewName = this.viewName();
const columnList = columns
? ' (' +
columnize_(
columns,
this.viewBuilder,
this.client,
this.bindingsHolder
) +
')'
: '';
const dropSql = `drop view if exists ${viewName}`;
const createSql = `create view ${viewName}${columnList} as ${selectQuery}`;
this.pushQuery({
sql: dropSql,
});
this.pushQuery({
sql: createSql,
});
}
2021-10-20 22:23:29 +02:00
}
module.exports = ViewCompiler_SQLite3;