Adding alias option on column definition
See original GitHub issueIssue type:
[ ] question [ ] bug report [X ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ X] mongodb
[ X] mssql
[ X] mysql
/ mariadb
[ X] oracle
[ X] postgres
[ X] cockroachdb
[ X] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ X] latest
[X ] @next
[ ] 0.x.x
(or put your version here)
It would be amazing if we could add an “alias” option on the column. For example an Entity like this :
` @Entity() export class User {
@PrimaryGeneratedColumn() id: number;
@Column({ type: “text”}) department: string;
@Column(“text”) localization: string;
} `
getConnection().getRespoitory(User).find()
Generates the following statement :
SELECT "User"."id" AS "User_id", "User"."department" AS "User_department", "User"."localization" AS "User_localization" FROM "user" "User"
What about adding an option to columns like for example :
@Column({ type: "text", alias: "dep" }) department: string;
So the statement will be like this :
SELECT "User"."id" AS "User_id", "User"."department" AS "dep", "User"."localization" AS "User_localization" FROM "user" "User"
The only workaround I found is to change the class name of the entity or to use the query builder
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
I don’t really see what will we gain by that. At the end of the day you still use javascript objects and shouldn’t care much of generated sql as long as it gives you results you want and is performant. Readable sql is good in case of debbuging - but adding column aliases just for that is just a bit overkill.
I am running into an issue with the query builder generating ambiguously named columns columns too. I am actually trying to join two entities School and SchoolDistrict. The school has a district_id column and then SchoolDistrict has an id column. When joined the query builder selects
school.district_id AS school_district_id
and selectsschool_district.id AS school_district_id
…