Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thank you for this library #12

Closed
dclipca opened this issue Aug 19, 2020 · 12 comments
Closed

Thank you for this library #12

dclipca opened this issue Aug 19, 2020 · 12 comments

Comments

@dclipca
Copy link

dclipca commented Aug 19, 2020

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?

@navirick
Copy link

To add to this.. does it support struct tags in any way?

@georgysavva
Copy link
Owner

@virtumonde Thanks for your warm words!
Yes it does. you can do it via db:"-" struct tag, please see this docs section for details and example.

@navirick Yep, apart from omitting struct fields, you can set a custom column name via db struct tag, see this docs section for details and example

@navirick
Copy link

@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.

@georgysavva
Copy link
Owner

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.

@georgysavva
Copy link
Owner

BTW I added the list of all features to the readme file.

@navirick
Copy link

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

@georgysavva
Copy link
Owner

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

@pashagolub
Copy link

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!

@georgysavva
Copy link
Owner

georgysavva commented Sep 4, 2020

@pashagolub Thanks for reaching out!

  1. scany supports both 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.
  2. In terms of scanning and mapping abilities, scany provides all features of sqlx.
  3. Scany has a much simpler API/interface and much fewer concepts compared to sqlx, so I believe it should be easier to use.
  4. Scany doesn't support the opposite direction of mapping when you insert data from your struct into the query, at least for now. We had a discussion about implementing this: Thank you for this library #12 (comment). sqlxhas this feature.

Those are the main points.

UPD: added section to readme with the comparison with sqlx

@anton7r
Copy link

anton7r commented Dec 3, 2021

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.

@georgysavva
Copy link
Owner

Hey @anton7r. No, I actually haven't started working on this yet. So feel free to shoot a PR with your integration!

@anton7r
Copy link

anton7r commented Dec 3, 2021

@georgysavva yeah, opened it #71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants