An example of connecting to a postgres database using the sqlx and squirrel packages
- Docker
- Docker Compose
We will be using Docker to spin up a Postgres instance.
-
Launch a new shell session and start Postgres:
$ docker-compose up
-
You can connect to Postgres from the shell:
$ docker exec -it postgres psql postgres://pguser:password@localhost/db psql (12.11) Type "help" for help. db=# SELECT * FROM users; id | created_at | updated_at | email | username | first_name | last_name -----+----------------------------+----------------------------+-----------------+----------+------------+----------- 123 | 2023-07-25 00:04:13.652829 | 2023-07-25 00:04:13.652829 | jon@example.com | jonny | Jon | Murphy
-
Run the program
$ go run . -
When all is done, teardown Postgres.
$ docker-compose down