- Generate the SQL binding code using SQLC using docker/podman (use docker on windows):
- Pull the SQLC Docker Image:
docker pull kjconrow/sqlc
podman pull docker.io/kjconroy/sqlc
- Execute the following in the
database
directory:- For bash:
docker run --rm -v $(pwd):/src -w /src kjconroy/sqlc generate
- For Windows CMD
docker run --rm -v "%cd%:/src" -w /src kjconroy/sqlc generate
- For bash:
- Pull the SQLC Docker Image:
- Build the docker image
- Run
docker build --tag=schedder-api:latest --network=host --file Dockerfile .
- Run the dockerfile directly
./Dockerfile
on a Linux box whereenv
fromcoreutils
has support for-S/--split-string
- Run
- Running the container image
- Run
docker compose up
-
If you are seeing an error like:
schedder-schedder-api-1 | panic: failed to connect to `host=database user=postgres database=postgres`: dial error (dial tcp 172.22.0.2:5432: connect: connection refused)
Just run
docker compose up
again. This might happen on the first run as the backend tries to connect to the database while it is still initializing.
-
- Run
- Test the connection
-
Database Setup
- Install Postgres (detailed instructions outside the scope of this document, consult your distribution's documentation).
- Create a database (i.e.
echo "CREATE DATABASE schedder_test;" | psql
). - Read section "Connection Strings" from PostgreSQL Documentation: Database Connection Control Functions.
- Create a connection string, write it down.
-
Generate the SQL binding code using SQLC directly:
- Install SQLC
- Using
pacman
on Arch Linux:sudo pacman -S sqlc
- Using go 1.17+:
go install github.com/kyleconroy/sqlc/cmd/sqlc@latest
- Using
- Run in the
database
directory:sqlc generate
- if sqlc is in your
$PATH
you can also dogo generate
- Done
- Install SQLC
-
For testing:
- Copy
testing.env.example
totesting.env
. - Set
SCHEDDER_TEST_POSTGRES
to a the connection string from step 1.4. - Source the env you made using
source ./setenv.sh testing
- Run the tests using
go test
- Copy
-
For running:
- Copy
testinv.env.example
todevelop.env
- Do step 3.2
- Rename
SCHEDDER_TEST_POSTGRES
toSCHEDDER_POSTGRES
- Run using
go run ./cmd/schedder-api
- Copy
Try it with curl localhost:2023/accounts/self/sessions
, you should get a 401 response similar to:
{"error":"invalid token"}