package
0.0.0-20240519111142-3e416e18f32e
Repository: https://github.com/snail007/gmc.git
Documentation: pkg.go.dev

# README

GMC DATABASE

  1. Support of MYSQL , SQLITE3.
  2. Support of Multiple database source.
  3. Support of encrypt sqlite3 databse.

Configuration

database configuration section in app.toml

########################################################
# database configuration
########################################################
# mysql,sqlite3 are both supported
# support of mutiple mysql server 
# support of mutiple sqlite3 database
# notic: each config section must have an unique id 
########################################################
[database]
default="mysql"
[[database.mysql]]
enable=true
id="default"
host="127.0.0.1"
port="3306"
username="root"
password="admin"
database="test"
prefix=""
prefix_sql_holder="__PREFIX__"
charset="utf8"
collate="utf8_general_ci"
maxidle=30
maxconns=200
timeout=3000
readtimeout=5000
writetimeout=5000
maxlifetimeseconds=1800

[[database.mysql]]
enable=false
id="news"
host="127.0.0.1"
port="3306"
username="root"
password="admin"
database="test"
prefix=""
prefix_sql_holder="__PREFIX__"
charset="utf8"
collate="utf8_general_ci"
maxidle=30
maxconns=200
timeout=3000
readtimeout=5000
writetimeout=5000
maxlifetimeseconds=1800

[[database.sqlite3]]
enable=false
id="default"
database="test.db"
# if password is not empty , database will be encrypted.
password=""
prefix=""
prefix_sql_holder="__PREFIX__"
# syncmode 0:OFF, 1:NORMAL, 2:FULL, 3:EXTRA
syncmode=0
# openmode ro,rw,rwc,memory
openmode="rw"
# shared,private
cachemode="shared"

Example

package main

import (
	"github.com/snail007/gmc"
)

func main() {
	cfg := gmc.New.Config()
	cfg.SetConfigFile("../../app.toml")
	err := cfg.ReadInConfig()
	if err != nil {
		panic(err)
	}
	// Init only using [database] section in app.toml
	gmc.DB.Init(cfg)

	// database default is mysql in app.toml
	// so gmc.DB.DB() equal to  gmc.DB.MySQL()
	// we can connect to multiple cache drivers at same time, id is the unique name of driver
	// gmc.DB.DB(id) to load `id` named default driver.
	db := gmc.DB.DB().(*gdb.MySQLDB)
	//do something with db
}

# Packages

No description provided by the author

# Functions

No description provided by the author
DBMySQL acquires a mysql db object associated the id, id default is : `default`.
DBSQLite3 acquires a sqlite3 db object associated the id, id default is : `default`.
Init parse app.toml database configuration, `cfg` is Config object of app.toml.
InitFromFile parse foo.toml database configuration, `cfg` is Config object of foo.toml.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author