Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds a PostgreSQL module. To achieve this, first some new bindings for Go APIs have been added:
tc_container_with_envtc_container_with_wait_for_exectc_exec_with_exit_code_matcher(not sure about the naming of this one)tc_container_get_mapped_porttc_container_get_hostnameThe first one is required as the PostgreSQL container will not start up without a password being configured, and the easiest way to set this is the
POSTGRES_PASSWORDenv var. The exec-related functions are required to ensure a proper wait-for strategy that checks the exit code of runningpg_isreadyinside the container. And lastly, the port and hostname functions are used to assemble the connection string.Why is it important?
PostgreSQL is a widely used RDBMS and in my experience tends to be commonly deployed alongside native apps, perhaps because the client libraries libpq and libpqxx are quite mature and nice to use.
Related issues
Closes #41
How to test this PR
To test: build the repo and run
build/demo/postgresql/demo_postgresql_module.out. Requireslibpqto be installed to build. This demo application tests starting a PostgreSQL container and then opening a connection to it. You could also try extending it with some more of the code from https://www.postgresql.org/docs/current/libpq-example.html to run an actual query, but I think if the connection can be established then everything should work fine.Follow-ups
I have left some TODOs about:
Additionally, while I was able to test the Nix changes and validate that the new environment can build the example using
libpq, I found the dev container doesn't really work for multiple unrelated reasons and wasn't able to do a successful build on it, but the package does get installed 🤷