question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding alias option on column definition

See original GitHub issue

Issue 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:open
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
Kononnablecommented, May 25, 2019

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.

3reactions
kyle-mccarthycommented, Jan 20, 2020

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 selects school_district.id AS school_district_id

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL: ALIASES - TechOnTheNet
SQL ALIASES can be used to create a temporary name for columns or tables. COLUMN ALIASES are used to make column headings in...
Read more >
Creating Column Aliases with AS | SQL Visual QuickStart Guide
You can use the AS clause to create a column alias. A column alias is an alternative name (identifier) that you specify to...
Read more >
Using field properties, aliases, and table display options
Define an alias for a field name so the field appears in the table with a name that is easy to ... Set...
Read more >
SQL Aliases - W3Schools
SQL aliases are used to give a table, or a column in a table, a temporary name. Aliases are often used to make...
Read more >
Using Column Aliases - SAS Help Center
Aliases are often used to name a column that is the result of an arithmetic expression or summary function. An alias is one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found