Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove table name from columns alias #263

Open
dedalusj opened this issue Aug 16, 2023 · 3 comments
Open

Remove table name from columns alias #263

dedalusj opened this issue Aug 16, 2023 · 3 comments

Comments

@dedalusj
Copy link

I have an older project where I would like to use Jet as a query generator. The project already contains models with db tags and binding via sqlx.

Jet by default generate queries with column aliases including table names, e.g. for a table called jet the code

stmt := SELECT(Jet.ID).FROM(Jet)
query, _ := stmt.Sql()
fmt.Printf("Query: %s\n", query)

prints

SELECT jet.id AS "jet.id" FROM jet;

I would like to have a setting where the above stmt prints SELECT jet.id AS "id" FROM jet; by default.

I know I can manually add aliases to the columns in the query but for porting an older project to Jet it gets tedious quickly.

This answer suggests creating an alias for the table but even defining a table alias with an empty string aliasedTable := Jet.AS("") does not remove the table name from the column alias.

@houten11
Copy link

This #26 (comment) suggests creating an alias for the table but even defining a table alias with an empty string aliasedTable := Jet.AS("") does not remove the table name from the column alias.

Empty alias string means no alias.

I don't see other way then alias each column manually:

stmt := SELECT(Jet.ID.AS("id")).FROM(Jet)

Although, far easier would be to just ditch sqlx.

@dedalusj
Copy link
Author

Well the problem is not sqlx per se the problem is the hundreds of model structs that are already in the codebase that expect column name aliases without the table name, either due to existing db tag or because of default.

@go-jet
Copy link
Owner

go-jet commented Aug 18, 2023

You can use jet with custom model types as well. Also those db aliases will be ignored by jet QRM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants