Introduction
Examples of using various popular database libraries and ORM in Go.
The aim is to demonstrate and compare usage for several operations
- Simple CRUD operation
- 1-1 queries
- 1-to-Many queries
- Many-to-many queries
- Dynamic list filter from query parameter
- Transaction
The schema contains optional fields, for example middle name, and a field that must not be returned, for example, a password.
Usage
Setup
Setup postgres database by either running from docker-compose or manually.
docker-compose up
This creates both postgres
database (which this repo uses) and ent
database which is used by ent ORM.
Default database credentials are defined in config/config.go
. These can be overwritten by setting environment variables. For example:
export DB_NAME=test_db
Run
Run with
go run main.go
Run examples from examples
folder.