diff --git a/Makefile b/Makefile index 420b249..b5eee34 100644 --- a/Makefile +++ b/Makefile @@ -62,6 +62,17 @@ docker-tools: @$(call print, "Building tools docker image.") docker build -q -t aperture-tools $(TOOLS_DIR) +# ======= +# CODEGEN +# ======= +sqlc: + @$(call print, "Generating sql models and queries in Go") + ./scripts/gen_sqlc_docker.sh + +sqlc-check: sqlc + @$(call print, "Verifying sql code generation.") + if test -n "$$(git status --porcelain '*.go')"; then echo "SQL models not properly generated!"; git status --porcelain '*.go'; exit 1; fi + # ======= # TESTING # ======= diff --git a/scripts/gen_sqlc_docker.sh b/scripts/gen_sqlc_docker.sh new file mode 100755 index 0000000..e3c98cf --- /dev/null +++ b/scripts/gen_sqlc_docker.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e + +# Directory of the script file, independent of where it's called from. +DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)" +# Use the user's cache directories +GOCACHE=`go env GOCACHE` +GOMODCACHE=`go env GOMODCACHE` + +echo "Generating sql models and queries in go..." + +docker run \ + --rm \ + --user "$UID:$(id -g)" \ + -e UID=$UID \ + -v "$DIR/../:/build" \ + -w /build \ + kjconroy/sqlc:1.18.0 generate + diff --git a/sqlc.yaml b/sqlc.yaml new file mode 100644 index 0000000..ea56883 --- /dev/null +++ b/sqlc.yaml @@ -0,0 +1,10 @@ +version: "2" +sql: + - engine: "postgresql" + schema: "aperturedb/sqlc/migrations" + queries: "aperturedb/sqlc/queries" + gen: + go: + out: aperturedb/sqlc + package: sqlc + emit_interface: true