sqlx

command module
v0.0.0-...-0736bb3 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: MIT Imports: 17 Imported by: 0

README

Percobaan SQLX untuk Koneksi Database Menggunakan Bahasa Golang

Technology Stacks

  • Gin - for easy to configure web server framework
  • Gin-Swagger - Swagger Docs integration for Gin web framework
  • Yaml v2 - Go package for processing yaml files
  • Sqlx - a package which provides a set of extensions on Go's builtin database/sql package

Application Structure

app
├── config              // config
│   └── config.go       // logics to load the setting.yaml
├── controller          // routing, might change it to 'service', karena
│   └── controller.go   // package tidak menampung logic, hanya definisi routing & memanggil service lain
├── datasource          // koneksi ke datasource (database)
│   ├── datasource.go   // logics stored here
│   └── entity.go       // models generic untuk datasource, currently empty
├── entity              // generic models yang bisa digunakan dimana saja
│   └── entity.go
├── middlewares         // middlewares
│   └── middlewares.go  // untuk sementara hanya CORS supaya swagger jalan
└── user                // user management logic
    ├── entity.go       // models, isinya user model dan req & resp yg berhubungan dgn user
    └── user.go         // logics stored here

How to try this project

  1. Clone repository:
git clone https://github.com/yeyee2901/sqlx.git
  1. Run go mod download & verify untuk melengkapi semua dependency
go mod download && go verify
  1. Sesuaikan file setting.yaml terutama bagian mysql profile nya
mysql:
  username: your_username
  password: your_password
  db: local_development
  host: 127.0.0.1
  port: 30000
  minpool: 1
  maxpool: 10
  parse_time: "true" # wajib true apabila ingin banding ke objek time.Time
  1. Migrate database (script migrate ada di ./db/migration.sql)
CREATE TABLE `users` (
    id INT auto_increment,
    name VARCHAR(255) NOT NULL,
    created_at DATETIME NOT NULL DEFAULT NOW(),

    PRIMARY KEY (`id`)
);
  1. Jalankan bisa di compile dulu / langsung di go run
go run .    # Jalan langsung

go build -o compiled # di compile dulu
./compiled
  1. Buka browser dan akses ke IP yang ada di setting.yaml untuk mengakses swagger supaya bisa coba-coba API nya
http://localhost:8767/swagger/index.html
  1. Have fun trying!

You can see the source code, I put comments almost everywhere that might need explanation. Welcome to the world of Go, sir.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
app
Package docs GENERATED BY SWAG; DO NOT EDIT This file was generated by swaggo/swag
Package docs GENERATED BY SWAG; DO NOT EDIT This file was generated by swaggo/swag

Jump to

Keyboard shortcuts

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