Skip to content

EkoEdyPurwanto/simple-bank

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create Database Schema

Simple Bank Schema

Setup Database & Perform Database Migration on Docker (manually)

  1. Pull the database from Docker Hub:
docker pull postgres:15.3-alpine3.18
  1. Run the database container:
sudo docker run --name postgres15.3 -p 9876:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=1903 -d postgres:15.3-alpine3.18
  1. Login to the database:
sudo docker exec -it postgres15.3 psql -U root
  1. Create the simple_bank database:
CREATE DATABASE simple_bank OWNER root;
  1. Import the .sql file into the simple_bank database.

Setup Database & Perform Database Migration on Docker (automatically)

You can also perform database migration automatically without doing it manually using Go Database migrations. First, make sure you have pulled the appropriate database image:

docker pull postgres:15.3-alpine3.18

Then, install the required library for Go Database migrations:

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

Use the provided Makefile to simplify execution.

Install SQLC and Go Postgres Driver

  1. Install SQLC.

  2. Install Go Postgres driver for database/sql.

Implement SQLC:

  1. Change directory to your project path:
cd /to/your/path/project
  1. Initialize SQLC:
sqlc init
  1. Set the configuration in sqlc.yaml.

Implement .sql

Implement queries account.sql, entry.sql, transfer.sql .

Implement Unit Tests

  1. Install testify for testing.

  2. Implement main_test.go to connect to the database.

  3. Implement account_test.go, entry_test.go, transfer_test to test the functions.

  4. Additionally, you can use random_generate.go to generate random data for testing purposes.

About

build a simple bank service in Go

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published