Skip to content

Conversation

@SapiensAnatis
Copy link

@SapiensAnatis SapiensAnatis commented Jan 4, 2026

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_env
  • tc_container_with_wait_for_exec
  • tc_exec_with_exit_code_matcher (not sure about the naming of this one)
  • tc_container_get_mapped_port
  • tc_container_get_hostname

The 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_PASSWORD env var. The exec-related functions are required to ensure a proper wait-for strategy that checks the exit code of running pg_isready inside 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. Requires libpq to 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:

  • being able to customise username, password, and other PostgreSQL properties; I didn't think this was necessary for a basic implementation
  • being able to pass command flags to the container, which will optimize the performance of the database considering that long-term data persistency and reliability is not required

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 🤷

@SapiensAnatis SapiensAnatis force-pushed the feature/postgres-module branch from 63cfbba to 2863b80 Compare January 4, 2026 06:15
Copy link
Author

Choose a reason for hiding this comment

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

I don't really know what this does, but I copied it from the WireMock folder ... it seems agnostic of what folder it lives in. Something to do with packaging?

Copy link
Author

Choose a reason for hiding this comment

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

This is my first time ever writing Go, and C interop code isn't exactly beginner-friendly, so I wouldn't be surprised if I've done some weird things here 😅

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

Successfully merging this pull request may close these issues.

New PostgreSQL Module for native apps

1 participant