chore(dev): setup sqlc and atlas

This commit is contained in:
Bastien Riviere 2024-01-29 18:45:50 +01:00
parent 1ebb4936ea
commit 2efa42651f
Signed by: babariviere
GPG key ID: 4E5F0839249F162E
6 changed files with 58 additions and 1 deletions

View file

@ -1,2 +1,3 @@
# short # short
URL Shortener written in Go URL Shortener written in Go

7
atlas.hcl Normal file
View file

@ -0,0 +1,7 @@
env "local" {
src = "file://sql/schema.sql"
url = "postgres://short:short@localhost:5432/short?sslmode=disable"
migration {
dir = "file://sql/migrations"
}
}

View file

@ -1,4 +1,4 @@
version: '3.1' version: "3.1"
services: services:
db: db:

View file

@ -21,6 +21,7 @@
alejandra.enable = true; alejandra.enable = true;
deadnix.enable = true; deadnix.enable = true;
gofumpt.enable = true; gofumpt.enable = true;
prettier.enable = true;
}; };
}; };
@ -29,6 +30,17 @@
# Go tools # Go tools
go go
gopls gopls
# Database
atlas
sqlc
postgresql_16
# Lint
golangci-lint
# Tools
just
]; ];
}; };
}; };

23
justfile Normal file
View file

@ -0,0 +1,23 @@
alias b := build
alias r := run
alias l := lint
build:
go build .
run:
go run .
lint:
golangci-lint run
sqlc:
sqlc generate
sqlc vet
gen-migration NAME:
atlas migrate diff {{NAME}} --env local
atlas migrate apply --env local
migrate:
atlas migrate apply --env local

14
sqlc.yaml Normal file
View file

@ -0,0 +1,14 @@
version: "2"
sql:
- engine: "postgresql"
queries: "sql/query.sql"
schema: "sql/schema.sql"
database:
uri: postgres://short:short@localhost:5432/short
gen:
go:
package: "db"
out: "internal/db"
sql_package: "pgx/v5"
rules:
- sqlc/db-prepare