Closed phenpessoa closed 1 year ago
Hey @phenpessoa sorry for the delay I missed the email notification. Yes, it does. But what do you mean by custom types?
Hey @VinGarcia no worries!
For example, with pgx we can use decimal for Numeric
values on PostgreSQL. This is thanks to database/sql.Scanner
and database/sql/driver.Valuer
.
But I can create any custom type I want and serialize/deserialize them to/from the database as long as they implement those interfaces.
Check this PR for an example.
Hey @phenpessoa, yeah this is actually defined by the sql package and its a standard.
About KSQL in particular it doesn't do much with the arguments you pass to it, except if you decide to use a modifier.
So if you just send us an attribute that implements sql.Scanner
or sql.Valuer
it will just be forwarded to the underlying driver, in your case pgx.
But this issue makes me think of two things:
sql.Scanner
and sql.Valuer
even when the attribute is using a modifier, it might be possible 🤔 Again sorry for taking so long to answer you xP. I have finished a couple tasks I was working on these last weeks so I will try to improve on this issue this next few weeks.
Thanks for asking.
Also just so you understand what I mean about a modifier:
https://github.com/VinGarcia/ksql/wiki/Modifiers
It is an extra annotation on the ksql
tag. e.g.: ksql:"address,json"
The modifier can specify a scanner and/or valuer function so if it does we will use that instead of the .Scan or .Value functions of your type, at least that is how it is right now. I may be able to check if the original type implements Scan and/or Value and call this function myself inside the modifier functions.
Hey @phenpessoa, I finally improved the docs on this, on the README I am now mentioning it as an outstanding feature:
https://github.com/VinGarcia/ksql#outstanding-features
And I also updated the "Modifiers" Wiki page to explain that KSQL supports the Scanner and Valuer interfaces and also explain the differences between these interfaces and the Modifiers:
https://github.com/VinGarcia/ksql/wiki/sql.Scan,-sql.Value-and-Modifiers
I will leave this Issue open for a few days, if you want me to add anything to these docs just say so. After that, I will close the issue but feel free to create a new one at any time.
Kind Regards.
I think the docs now make it crystal clear. Thank you!
Nice, I will close this issue then, feel free to open others whenever you need =]
Does this lib offers support for
database/sql.Scanner
anddatabase/sql/driver.Valuer
interfaces for custom types?Custom use case is for null fields where you don't want to (or can't) add pointers, for example.
database/sql.NullTime
is one of the most famous use cases.