Exclude column from Query
See original GitHub issueHi. First of all, congratulations for this awesome tool. English is not my first language, so I apologize for eventual mistakes.
It’s relatively common for ORMs to read the tables before execution to know exactly all the columns and its specifications. For example: in Mysql/MariaDb: DESCRIBE products; could return something like this:
Field Type Null Key Default Extra
id int(11) unsigned NO PRI NULL auto_increment
uuid char(36) NO NULL
name varchar(255) NO NULL
created_at datetime NO NULL
updated_at datetime YES NULL
By doing this, the QueryBuilder could start all SELECT queries with all fields by default, instead of *. And this is great for several reasons.
I’d like to know if there is a way to enable this? At this moment all my queries are using “select table.* […]”
My second question is: how to exclude columns from my query? I already saw how to omit columns after fetched, but i think this is a really poor solution, since my query:
static findByUUID( uuid ) {
return this.query().where( 'uuid', uuid ).first().omit( [ 'id' ] );
}
… Is being written like this anyway:
select `products`.* from `products` where `uuid` = ?
Summing up: I’m just trying to do this:
select
`products`.`uuid`,
`products`.`name`,
`products`.`created_at`,
`products`.`updated_at`
from `products` where `uuid` = ?
I really appreciate any contributions, since I’m really new to Knex and/or Objection.js.
Issue Analytics
- State:
- Created 6 years ago
- Comments:14
Top Related StackOverflow Question
After more consideration, this is too much of a hack for objection.
Here’s an example plugin that implements the feature using only public interface:
You would use it like this: