[Solved] Aliasing a column
Is there any way to alias a column on a select?
I mean an actual alias on the final query..
In starting to test out the new views support (amazing btw), I noticed a "problem"..
Normally if we have colliding colum names, like for instance: users.name and posts.name, we would alias them as user_name and post_name, for example, but currently drizzle queries them as "users"."name" and "posts"."name" In the view, which, at least in SQLite, creates a view with two "name" columns (returned as name and name:1)
That creates issues when filtering and joining data..
Maybe supporting the .as() function on columns for selects in general could be useful? Instead of only supporting it on sql``?
4 Replies
I wrote a little generic function that does exactly what i want, for anyone interested:
May be used as such in views!
It generates views with aliased columns:
And keeps the results properly typed based on the source column: