Make view.columns() functionality optional when creating a view
See original GitHub issueEnvironment
Knex version: 0.95.14 Database + version: PostgreSQL 13.4 OS: Windows10
Feature discussion / request
As a PostgreSQL user, I would like to be able to create such queries for views:
create view "users_view" as select "users".*, "user_roles"."role_code" from "users" inner join "user_roles" on "users"."user_id" = "user_roles"."user_id"
I could achieve it this with this code:
knex.schema.createView('users_view', (view) => {
view.as(knex('users').join('user_roles', 'users.user_id', 'user_roles.user_id').select('users.*', 'user_roles.role_code'))
})
But currently this doesn’t work because I didn’t use view.columns()
functionality, so knex throws columns is not iterable
error.
I edited the knex\lib\schema\viewcompiler.js file
, changed part of createQuery
code like this and everything worked as I wanted:
const formatColumnsArr = [];
for (const c of columns || []) {
formatColumnsArr.push(
columnize_(c, this.viewBuilder, this.client, this.bindingsHolder)
);
}
const formatColumns = formatColumnsArr.length ? ' (' + formatColumnsArr.join(', ') + ')' : ''
let sql = createStatement + this.viewName() + formatColumns;
I would be happy to provide a PR if this is something you would like.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Documentation: 15: CREATE VIEW
CREATE VIEW defines a view of a query. The view is not physically materialized. Instead, the query is run every time the view...
Read more >CREATE VIEW (Transact-SQL) - SQL Server
Creates a virtual table whose contents (columns and rows) are defined by a query. Use this statement to create a view of the...
Read more >CREATE VIEW
By default, view columns are VISIBLE regardless of their visibility in the base tables, unless you specify INVISIBLE . This applies to conventional...
Read more >CREATE VIEW
Creates a new view in the current/specified schema, based on a query of one or more existing tables ... You can specify an...
Read more >sql server - SQL View Select Optional
Each group can only have 2 code and always have a default code vs not a default code. · IF default code is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Released in 1.0.1.
I’ll publish 1.0.0-next1 tonight then.