Closed realbucksavage closed 4 months ago
Would CAST
work in this case?
statement := table.SomeTable.SELECT(table.SomeTable.AllColumns).
WHERE(table.SomeTable.ID.EQ(CAST(String(id)).AS_BINARY())
@houten11 the query produced by using CAST
doesn't work:
SELECT *
FROM testdb.some_table
WHERE some_table.id = CAST('00000000-0000-0000-0000-000000000000' AS BINARY);
Assume working with a table that has UUIDs stored in a
varbinary
field. Here's an example:Querying data by
id
in this table would look like this:The type of the
id
column would be ofmysql.ColumnString
in the generated code.Generating a query using the
.EQ
method onSomeTable.ID
would result in a query that looks like:select .... where
id= '0000-0000-.....';
mysql.UUID
also appears to be just a wrapper that takes afmt.Stringer
and generates the same output as the.EQ
method.To get the desired output, we can use something like this:
Would it make sense for the library to add a couple of utility functions to shorten this? For example,
functions.go
could have these:With this, the user code can be shortened as: