database/

directory
v0.0.0-...-0aa8bca Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: MIT

README

Driver DB

Use MariaDB

Folder Structure

migration

List of DDL that have been happening so far.

codegen

Inside this folder, there are other folders which is a representation of repository. Inside those folder, there are 2 important files:

  1. query.sql; List of queries what used on the repository
  2. schema.sql; Partial DDL for tables, must be updated every time there is a schema change. Note: Since using soft delete method, the implication is all queries need adding clause
deleted_at IS NULL

For retrieving deleted data, will be use other function, e.g GetDeletedByID, etc.

Code Generator

codegen folder will be used for code generator from query to Go which is type-safe code. The generator is sqlc, using sqlc.yaml as sqlc configuration. Please check sqlc docs here for more details.

How to generate code

After install sqlc, just use CLI sqlc generate

Notes for codegen

There is limitation of current build sqlc for MySQL driver, such as

  • IN clause not working
  • LIKE clause not working workaround: just edit the codegen-ed code.
  • queries can not be exported

Directories

Path Synopsis
Package main, work as CLI for db migration.
Package main, work as CLI for db migration.

Jump to

Keyboard shortcuts

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