Closed dclipca closed 2 years ago
To add to this.. does it support struct tags in any way?
@georgysavva Excellent. I tried that out and it works great. Very cool. Question.. though it may not apply to this project.. is there any chance you'll add (or make another project) that allows the storage of a struct similar to how this is done? Seems like going both ways would be ideal when working with structs.
You mean when we have a struct filled with data and we want to save this data to the database?
I thought about implementing this actually. The only thing that stopped me is that different databases have a different symbol for query arguments:$
for postgres, ?
for mysql and etc.
It will require the user to configure this somehow and it will complicate the library, so I decided to not add it.
BTW I added the list of all features to the readme file.
Yah.. and that's a good point. Oddly I thought this was a library for pgx which was postgresql. I came to it from pgx.. but I see you support others as well. Until we have generics you would be stuck implementing db specific implementations. I am good with that :D. The name though.. scany.. may contradict the opposite direction, pushy or story... :D
I don't like the idea of db specific implementations. I have some plans for adding configuration ability for the user, maybe after this is implemented I can start thinking about this feature.
Alternatively, we could use this approach: For Postgres:
"INSERT INTO users (id, name, age) ($id, $name, $age)" -> "INSERT INTO users (id, name, age) ($1, $2, $3)"
For MySQL:
"INSERT INTO users (id, name, age) (?id, ?name, ?age)" -> "INSERT INTO users (id, name, age) (?, ?, ?)"
For SQL server:
"INSERT INTO users (id, name, age) (@id, @name, @age)" -> "INSERT INTO users (id, name, age) (@p1, @p2, @p3)"
So the query will contain named argument with the special symbol specific for the database of the user and scany library will detect this symbol and resolve it to the proper query, valid for this database.
This way scany doesn't need any configuration from the user, because it gets the special symbol in every query. But I have some doubts about this solution as well. Tell me what you think
Hello. Greetings and thanks for a great piece of code.
Do you have any kind of answer how scany
is similar/different to sqlx
?
Some of my projects are build with sqlx
, but I want to switch to pgx
and that's where scany
arrives. :)
Thanks in advance!
@pashagolub Thanks for reaching out!
database/sql
and pgx
native interface (when you use pgx
as a standalone library, without database/sql
layer). Also it can be extended to work with any db library. On the other hand, sqlx
only works with database/sql
.sqlx
.sqlx
, so I believe it should be easier to use.sqlx
has this feature. Those are the main points.
UPD: added section to readme with the comparison with sqlx
I don't like the idea of db specific implementations. I have some plans for adding configuration ability for the user, maybe after this is implemented I can start thinking about this feature.
Alternatively, we could use this approach: For Postgres:
"INSERT INTO users (id, name, age) ($id, $name, $age)" -> "INSERT INTO users (id, name, age) ($1, $2, $3)"
For MySQL:
"INSERT INTO users (id, name, age) (?id, ?name, ?age)" -> "INSERT INTO users (id, name, age) (?, ?, ?)"
For SQL server:
"INSERT INTO users (id, name, age) (@id, @name, @age)" -> "INSERT INTO users (id, name, age) (@p1, @p2, @p3)"
So the query will contain named argument with the special symbol specific for the database of the user and scany library will detect this symbol and resolve it to the proper query, valid for this database.
This way scany doesn't need any configuration from the user, because it gets the special symbol in every query. But I have some doubts about this solution as well. Tell me what you think
@georgysavva are these named query parameters already implemented into scany? i could perhaps integrate that feature set from my library (https://github.com/anton7r/pgxe) into scany.
Hey @anton7r. No, I actually haven't started working on this yet. So feel free to shoot a PR with your integration!
@georgysavva yeah, opened it #71
Thank you so much for building this library, it saved me a lot of time. You rock!
Does it support omitting certain properties from a struct?