Closed SchaichAlonso closed 1 year ago
SELECT "name", "email as user_email" FROM "users"
If this is happening then is a bug of course, it should look like this:
select "name", "email" as "user_email" from "users"
Currently, the as
keyword must be lowercase to be correctly detected, if it is the AS
then this bug you are describing can happen, I will make it case-insensitive, and I will further investigate it, it was only a fast 5 min lookup what's up.
Should be fixed in v0.36.4
Thx for reporting it
For non-trivial queries, it is often advantageous - if not required - to be able to assign aliases.
While TinyORM does not explicitly mention supporting alias assignments, the first example in the Select Statement Documentation, namely
hints the
email
column is to be assigned theuser_email
alias, as the statement could be imagined to become something likeHowever, TinyORM escapes the column specifiers that were passed through the initializer list, resulting in
being generated, which selects the
name
along with echo-ing the escaped string constant provided in the second argument.This Test executes the line that is provided in the Select Statement Documentation , then iterates the returned query result to emit this diagnostic indicating SQLite is echo-ing the SELECT parameter rather then assigning a column alias.
While cosmetic in trivial select statements like the one in the example, the ability to assign aliases in
JOIN
queries is crucial. For example, auser
might "follow" otherusers
, which could be implemented using a transitioning table storingfollows
andfollowers
in twitter-speak, identifying a user's followers with a statement likewhere the alias assignments are non-optional, as the follow and the followers are both
users
and need to be distinguished by using their aliases. However, as TinyORM escapes the string, it will cause an invalid SQL query if an "alias assignment" is used in a select query to ajoin
expression.I don't think "pasting" sql code into a column or table specifier is a scalable solution in case it was intentional. Instead, TinyORM should provide an API to specify aliases in a safe and backend independent way.