How to using multiple database?

Hi
I have 2 databases and it’s using mysql driver
I want using 2 databases in 1 project of go-admin ?
how to using multiple database ?
Thanks <3

@duchanhstyle You can add multiple databases config in the global config.

"database": { 
    "default": {
        "host": "127.0.0.1",
        "port": "3306",
        "user": "root",
        "pwd": "root",
        "name": "godmin_1",
        "max_idle_con": 50,
        "max_open_con": 150,
        "driver": "mysql"
    },
    "my": {
        "host": "127.0.0.1",
        "port": "3306",
        "user": "root",
        "pwd": "root",
        "name": "godmin_2",
        "max_idle_con": 50,
        "max_open_con": 150,
        "driver": "mysql"
    }
},

And then specify the corresponding connection in your table model.

func GetXxxxTable(ctx *context.Context) (xxxxTable table.Table) {
	xxxxTable = table.NewDefaultTable(table.DefaultConfig().SetConnection("my"))
    return xxxxTable
}
1 Like