go-jet / jet

Type safe SQL builder with code generation and automatic query result data mapping
Apache License 2.0
2.52k stars 118 forks source link

AS alias and ORDER_BY #308

Closed ferllings closed 8 months ago

ferllings commented 8 months ago

Hello,

Using mysql, I'm trying to get list of users first letter:

    stmt := SELECT(
        LEFT(User.name, Int(1)).AS("letter"),
    ).DISTINCT().FROM(
        User,
    ).ORDER_BY(
        String("letter").ASC(),
    )

It produce:

SELECT DISTINCT LEFT(user.name, 1) AS "letter"
FROM user
ORDER BY 'letter' ASC;

It gets the list, but not sorted. Any idea?

houten11 commented 8 months ago

Replace String("letter") with StringColumn("letter"). Ordering by a string constant doesn't make sense.

ferllings commented 8 months ago

Sorry for the confusion, I'm only starting with this lib. Great job so far !