Closed gevera closed 10 months ago
@gevera Thank you for using my library. I'm always happy to see people finding it useful :smile:.
Now, regarding the UUIDs, you can always do the casting in the database itself e.g. for the statement you've posted, I would just write the following:
-- name: create_a_customer
-- docs: Creates a new customer
INSERT INTO customers(id, name, age, telephone, inserted_at, updated_at)
VALUES (:id::TEXT::UUID, :name, :age, :telephone, now(), now());
When reading values from the database, you can do the same trick, but backwards e.g:
SELECT id::UUID::TEXT FROM customers;
I hope this helps :smile:
Worked like a charm. Thanks
Hey Alexander!
I have a question regarding UUIDs. More specifically, how to deal with them in more elegant way. As of right now, if I generate a migration with the a binary_id like this one:
And having a sql query like so:
There is a need to generate an UUID and cast it with something like this:
And ultimately, for creating a customer the code will look like so:
So the issue here, is when I retrieve the results with AyeSQL , I will need to convert the binary_id back and forth
As an example, if I run the following command
Ill get a response that looks like so:
That's understandable, since Postgres keeps UUID as 16 bit binaries. Now for me in order to display IDs as strings, again, we will need a helper
And then use it in the Customers service
I hope it makes sense. So my question will be, if there is a more streamlined way of handling the UUIDs ?
Btw, wonderful library. I feel more comfortable using it then Ecto queries. Maybe I am just old school ?