Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/asqiriba/golang-banking-system
Create and manage bank accounts and money transactions.
https://github.com/asqiriba/golang-banking-system
crud golang postgres
Last synced: 11 days ago
JSON representation
Create and manage bank accounts and money transactions.
- Host: GitHub
- URL: https://github.com/asqiriba/golang-banking-system
- Owner: asqiriba
- Created: 2022-08-01T20:03:13.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-09-05T18:33:46.000Z (over 2 years ago)
- Last Synced: 2024-06-21T04:59:07.699Z (7 months ago)
- Topics: crud, golang, postgres
- Language: Go
- Homepage:
- Size: 141 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Banking System
Create and manage bank accounts and money transactions.
## Installation
We launch an image of Postgres locally.
```bash
make postgres
```Then, we run the migration script (Install from [here](https://github.com/golang-migrate/migrate/tree/master/cmd/migrate)).
```bash
make createdb
make migrateup
```## DB Schema
![](db/provision/db-schema.png)
```sql
Table users as U {
username varchar [pk]
hashed_password varchar [not null]
full_name varchar [not null]
email varchar [unique, not null]
password_changed_at timestamptz [not null, default: '0001-01-01 00:00:00Z']
created_at timestamptz [not null, default: `now()`]
}Table accounts as A {
id bigserial [pk]
owner varchar [ref: > U.username, not null]
balance bigint [not null]
currency varchar [not null]
created_at timestamptz [not null, default: `now()`]Indexes{
owner
(owner, currency) [unique]
}
}Table entries {
id bigserial [pk]
account_id bigint [ref: > A.id, not null]
amount bigint [not null]
created_at timestamptz [not null, default: `now()`]Indexes{
account_id
}
}Table transfers {
id bigserial [pk]
from_account_id bigint [ref: > A.id, not null]
to_account_id bigint [ref: > A.id, not null]
amount bigint [not null, note: 'can only be positive']
created_at timestamptz [not null, default: `now()`]Indexes{
from_account_id
to_account_id
(from_account_id, to_account_id)
}
}
```Create the migration scripts for the database schema.
```bash
migrate create -ext sql -dir db/migration -seq init_schema
```## CRUD using [SQLC](https://docs.sqlc.dev/en/latest/overview/install.html)
```bash
sqlc init
```After populating your `sqlc.yaml` file and putting some queries under ./db/query.
```bash
make sqlc
```To get rid of the red error lines, create a module for the project.
```bash
go mod init github.com/asqiriba/golang-banking-system
go mod tidy
```## Run Unit Tests
```bash
make test
```