03-go-database-postgresql-part-1

command module
v0.0.0-...-f98ffab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 12 Imported by: 0

README

Using PostgreSQL - Part 1

Requirements

  1. Go 1.15
  2. direnv: for sanboxing the required tools used by this project.
  3. PostgreSQL: either a remote instance, local binary or docker container.
  4. Load testing data

Running

Download the required packages:

go mod download

Then you can run server.go with the PostgreSQL and memcached configuration:

DATABASE_URL=postgres://user:password@localhost:5432/dbname?sslmode=disable \
  go run .
PostgreSQL
Using Docker
docker run \
  -d \
  -e POSTGRES_HOST_AUTH_METHOD=trust \
  -e POSTGRES_USER=user \
  -e POSTGRES_PASSWORD=password \
  -e POSTGRES_DB=dbname \
  -p 5432:5432 \
  postgres:12.5-alpine
Migrations

Make sure the migrate tool is installed:

go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate

Then, assuming you used docker, you can run:

migrate -path db/migrations/ -database "postgres://user:password@localhost:5432/dbname?sslmode=disable" up
Load testing data

You can use the tool I build during my Implementing Complex Pipelines in Go series, install it using:

go install github.com/MarioCarrion/complex-pipelines/part5

Then run it using:

DATABASE_URL="postgres://user:password@localhost:5432/dbname?sslmode=disable" part5

Sadly, at the moment this tool does not provide any progress feedback; but it should finish after a couple of minutes.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL