watermill-sql icon indicating copy to clipboard operation
watermill-sql copied to clipboard

streamline the database interfaces and add pgx adapter

Open julesjcraske opened this issue 1 year ago • 2 comments

I am opening this draft PR to see if you are interested in this direction for the library (trimming down the interfaces to only what is used). If so I can put the effort in to get it up to your required standards and resolve the final issues. If not I can close it and keep my fork.

Thanks for all the great work you have done on the lib so far!

I want to use watermill to fulfil the outbox pattern (persisting events that will be asynchronously broadcast as part of the main persistence transaction) but my company mainly uses the pgx library.

This change makes this library more flexible to allow for the use of the pgx library. I can keep the pgx adapter itself elsewhere, outside of this repo if you would like.

  • Strips out all of the unused methods declared in the database Beginner and Executor (totally unused) and ContextExecutor interfaces.
  • Adds interfaces for the Exec Result type and the Query Rows type.
  • Adds small plumbing adapters for the StdSQL and Pgx types

Still to do:

  • Make it so that it is backwards compatible initialising a Publisher or Subscriber with a raw StdSQL connection or transaction.
  • Add to documentation.
  • Add tests against a pgx adapter.

julesjcraske avatar Feb 08 '24 16:02 julesjcraske

Thanks for contributing @julesjcraske and I'm sorry it took us so long to reply!

This looks great, and I since we're getting more people asking about using specific database frameworks with the outbox pattern, I'm happy to go ahead with it. Since you changed the public interfaces anyway, I think we can't keep backward compatibility and will need to bump major version, unless you see some way?

m110 avatar Aug 23 '24 16:08 m110

I think we can't keep backward compatibility and will need to bump major version, unless you see some way?

Thanks for taking a look, its great to here you are interested in the concept. I will try and find time to explore the options backwards compat and finishing touches on the PR over the next few weeks.

julesjcraske avatar Sep 03 '24 22:09 julesjcraske

Update: I have created a pull request on the pgxtype repository to add the xid8 type that is currently used in the postgres schema. https://github.com/jackc/pgtype/pull/220

There are still some more fixes required and issues to resolve after that, but that gets the majority of the tests passing with the new adapters.

julesjcraske avatar Oct 07 '24 09:10 julesjcraske