Skip to content

Reducing database/sql boilerplate using Go generics without the need for added dependencies

Notifications You must be signed in to change notification settings

Jimeux/go-generic-dao

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-generic-dao

Reducing database/sql boilerplate using Go generics without the need for added dependencies.

Medium Article

For a full explanation of the code, please see the accompanying blog post.

Setup

Environment variables

Use direnv as below, or manually set contents of .env in your terminal or editor.

direnv allow

Database

docker-compose up -d
make db-init

Run tests

make test

Code Overview

config package

  • Initializes environment variables and stores them in a singleton
  • Initialize with config.Init()
  • Access with config.Instance()

db package

  • Initializes a database instance and stores it in a singleton
  • Initialize with db.Init()
  • Access with db.Instance()

test package

  • Provides helpers for testing
  • Call test.InitConfig() instead of config.Init() from TestMain functions

like and user packages

  • Contain entities, DAOs and tests

About

Reducing database/sql boilerplate using Go generics without the need for added dependencies

Topics

Resources

Stars

Watchers

Forks