alexedwards / scs

HTTP Session Management for Go
MIT License
2.12k stars 165 forks source link

pgxstore expects a *pgxpool.Pool instead of a *sql.DB #184

Open tiagonbotelho opened 11 months ago

tiagonbotelho commented 11 months ago

Hello,

I'm following along the Let's Go book (amazing book btw 🎉 ) and trying to adapt the code to use Postgres rather than MySQL.

However, one of the challenges I've encountered is that the session store that scs uses for Postgres (pgxstore) doesn't support the usage of the database/sql package (unlike the MySQL counterpart), since it expects a *pgxpool.Pool to be passed rather than a *sql.DB.

Since it seems to be a best practice to use the higher-level wrapper such as database/sql rather than a driver-specific library, I was wondering if there'd be any appetite in adding support for passing *sql.DB to pgxstore.New()

Thanks again for all the amazing contributions to the Go language 👏

tiagonbotelho commented 11 months ago

To add to the issue description, one could definitely switch to using pq instead alongside the postgresstore. But pq does seem to point to pgx as the most up-to-date driver for Postgres.

tiagonbotelho commented 11 months ago

I guess another alternative would be to just use the postgresstore but instead of using pq like recommended in the README just use pgx 👍

I'll give it a try and report back. Maybe this is something that can be clarified in the README as well 😊

jum commented 10 months ago

I am using the pgx driver via the jackc/pgx/v5/stdlib interface to make it compatible to sqlx at. al., this works fine with postgresstore for scs. You can always get the pgx handle from the DB interface if you are so inclined to use the pgx interface.

tiagonbotelho commented 10 months ago

👍 Same, I can confirm that I've been running the pgx driver using postgresstore for scs without any issues thus far. A small suggestion would be to clarify in the readme of that adapter that is supports pgx as well as pq.

I'd be happy to open a quick PR to make that clarification if we agree 😊

alexedwards commented 10 months ago

@tiagonbotelho Thanks, that sounds good to me :+1: It would be great if you could update the README for postgresstore to include examples of both using it with pq and also jackc/pgx/v5/stdlib. If we're making that change, we should probably update the table in the main SCS README at https://github.com/alexedwards/scs/tree/master#configuring-the-session-store too.