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
How to try this project
- Clone repository:
git clone https://github.com/yeyee2901/sqlx.git
- Run go mod download & verify untuk melengkapi semua dependency
go mod download && go verify
- Sesuaikan file
setting.yaml
terutama bagian mysql profile nya
mysql:
username: your_username
password: your_password
db: local_development
host: 192.168.100.16
port: 3306
minpool: 1
maxpool: 10
parse_time: "true" # wajib true apabila ingin banding ke objek time.Time
- 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`)
);
- Jalankan bisa di compile dulu / langsung di go run
go run . # Jalan langsung
go build -o compiled # di compile dulu
./compiled
You can see the source code, I put comments almost everywhere that needs explanation. Welcome to the world of Go, sir.