-
Notifications
You must be signed in to change notification settings - Fork 923
Type-hinting for MySQL? #686
-
Is there a way to get the "type hinting" in https://github.com/kyleconroy/sqlc/blob/master/docs/named_parameters.md (e.g., sqlc.arg(set_name)::bool
) to work for MySQL?
I'm trying to get types for a query like:
SELECT * FROM things WHERE x = sqlc.arg(x) AND y = sqlc.arg(y) AND ABS(DATEDIFF(created_at, sqlc.arg(created_at))) < 15;
but CreatedAt
in the result struct is an interface{}
(and sqlc outputs " unknown MySQL type: any")
Trying to do a MySQL-style CAST(sqlc.arg(created_at) AS DATETIME)
results in sqlc getting confused and just omitting the CreatedAt
arg altogether.
Is this supposed to work right now, or is it a known issue that more work needs to be done to support this?
Beta Was this translation helpful? Give feedback.
All reactions
Is this supposed to work right now
Nope!
or is it a known issue that more work needs to be done to support this?
Most certainly a known issue. The sqlc.arg(set_name)::bool
syntax is PostgreSQL syntactic sugar for CAST ... AS
. I've opened #687 to track implementation.
I'd also like to point out #655, which would also fix your issue. Since the DATEDIFF function takes two arguments of known types, sqlc will pick the correct type automatically. The issue is that I haven't generated the functions definitions yet. Soon!
Replies: 1 comment
-
Is this supposed to work right now
Nope!
or is it a known issue that more work needs to be done to support this?
Most certainly a known issue. The sqlc.arg(set_name)::bool
syntax is PostgreSQL syntactic sugar for CAST ... AS
. I've opened #687 to track implementation.
I'd also like to point out #655, which would also fix your issue. Since the DATEDIFF function takes two arguments of known types, sqlc will pick the correct type automatically. The issue is that I haven't generated the functions definitions yet. Soon!
Beta Was this translation helpful? Give feedback.