Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Removes pgx dependency #15

Closed
wants to merge 1 commit into from
Closed

Conversation

aravindc26
Copy link
Contributor

Since go 1.9's database/sql interface allows you grab an individual connection, I have removed pgx dependency.

Copy link

@cbandy cbandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. If I understand correctly, sql.Conn is part of Go 1.9, yes?

// truncate to the microsecond as postgres driver does
want = want.Truncate(time.Microsecond)
// truncate to the Second as postgres driver does
want = want.Truncate(time.Second)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Time: j.RunAt,
Valid: !j.RunAt.IsZero(),
runAt := sql.NullString{
String: j.RunAt.Format(time.RFC3339),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use time.RFC3339Nano to include microseconds here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbandy yes I'll change it. If time.RFC3339Nano is used here, I guess there is no need of truncating it to second in the tests.

conn := newConn()
i := 0
for {
var waiting bool
err := conn.QueryRow(`SELECT pg_stat_get_backend_waiting($1)`, backendID).Scan(&waiting)
err := conn.QueryRowContext(context.Background(), `SELECT waiting from pg_stat_activity where pid=$1`, backendID).Scan(&waiting)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using postgresql 9.6 and pg_stat_get_backend_waiting doesn't seem to exist in 9.6.


mu sync.Mutex
deleted bool
pool *pgx.ConnPool
conn *pgx.Conn
db *sql.DB
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I don't mind this still being named pool. Newcomers to the database/sql package often do not recognize that *sql.DB is a connection pool. (Keeping it as pool would also reduce the size of this diff.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -121,14 +121,14 @@ func (j *Job) Error(msg string) error {
// Client is a Que client that can add jobs to the queue and remove jobs from
// the queue.
type Client struct {
pool *pgx.ConnPool
db *sql.DB
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with pool here as well.

@@ -121,14 +121,14 @@ func (j *Job) Error(msg string) error {
// Client is a Que client that can add jobs to the queue and remove jobs from
// the queue.
type Client struct {
pool *pgx.ConnPool
db *sql.DB

// TODO: add a way to specify default queueing options
}

// NewClient creates a new Client that uses the pgx pool.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove "pgx" here.

... that uses the connection pool.

pool *pgx.ConnPool
conn *pgx.Conn
db *sql.DB
conn *sql.Conn
}

// Conn returns the pgx connection that this job is locked to. You may initiate
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove "pgx" here.

Conn returns the connection that this job ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bgentry
Copy link
Owner

bgentry commented Jul 28, 2017

@aravindc26 thanks for submitting this! I have a few questions before I review it.

  • Does this have any semantic differences that pre-existing users will need to adjust for when they migrate over? It looks like pgx/stdlib has a DriverConfig struct that's basically the same as the current pgx.ConnPoolConfig but used to configure the database/sql driver. Is there any reason that direct pgx support might need to be preserved? (If others can chime in here that would be 🙏)
  • Can you update the readme both to reflect the new usage?
  • Can you also add a readme note that explains how existing users should migrate from older versions?

I realized I hadn't yet tagged any releases on this repo, so I just tagged v0.5.0 on master. I think after this PR I'll want to bump it version to 1.0 since this is a breaking change.

@aravindc26
Copy link
Contributor Author

Does this have any semantic differences that pre-existing users will need to adjust for when they migrate over? It looks like pgx/stdlib has a DriverConfig struct that's basically the same as the current pgx.ConnPoolConfig but used to configure the database/sql driver. Is there any reason that direct pgx support might need to be preserved? (If others can chime in here that would be 🙏)

@bgentry There are some differences in API between database/sql and pgx's native driver. One such difference is that database/sql doesn't seem to support named prepared statements (https://tip.golang.org/pkg/database/sql/#Conn.PrepareContext), while there is support for named prepared statements in pgx native lib (https://godoc.org/github.com/jackc/pgx#Conn.Prepare); as a result I had to remove the PrepareQuery API from que-go and use the queries without preparation and I am not sure about the performance impact.

Completely removing pgx support would mean that one cannot use ConnPool's AfterConnect feature. In a project that I work, I use AfterConnect to set search_path, this is useful when the que_jobs table is not created in public schema. May be we could come up with a solution to overcome the reliance on AfterConnect ?

Can you update the readme both to reflect the new usage?
Can you also add a readme note that explains how existing users should migrate from older versions?

Sure I can work on them 👍

@bgentry
Copy link
Owner

bgentry commented Jul 31, 2017

@bgentry There are some differences in API between database/sql and pgx's native driver. One such difference is that database/sql doesn't seem to support named prepared statements (https://tip.golang.org/pkg/database/sql/#Conn.PrepareContext), while there is support for named prepared statements in pgx native lib (https://godoc.org/github.com/jackc/pgx#Conn.Prepare); as a result I had to remove the PrepareQuery API from que-go and use the queries without preparation and I am not sure about the performance impact.

If you're saying that you've entirely removed the use of prepared statements in this PR (which is what it appears like at a glance), that's probably a no-go. When I was writing this lib, there was a dramatic difference in perf once prepared statements were added (likely bc the Que SQL statements are fairly complex).

@aravindc26
Copy link
Contributor Author

@bgentry if there is dramatic difference in performance, it does not make sense to move to database/sql; Closing the PR.

@aravindc26 aravindc26 closed this Aug 1, 2017
@aravindc26
Copy link
Contributor Author

Would you accept a PR if I were to upgrade the pgx dependency to v3 ?

@bgentry
Copy link
Owner

bgentry commented Aug 1, 2017 via email

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

Successfully merging this pull request may close these issues.

None yet

3 participants