https://github.com/partizaans/gormreplicated
This library is a complementary library for Gorm (v2) which resolves the first available pool passed to it.
https://github.com/partizaans/gormreplicated
go go-orm golang
Last synced: 5 months ago
JSON representation
This library is a complementary library for Gorm (v2) which resolves the first available pool passed to it.
- Host: GitHub
- URL: https://github.com/partizaans/gormreplicated
- Owner: partizaans
- Created: 2022-01-31T12:33:30.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-01T10:12:53.000Z (about 4 years ago)
- Last Synced: 2025-02-25T22:22:20.939Z (12 months ago)
- Topics: go, go-orm, golang
- Language: Go
- Homepage:
- Size: 1.95 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Gorm Replicated
This library is a complementary library for [Gorm (v2)](https://github.com/go-gorm/gorm)
which resolves the first available pool passed to it.
## Installation
```bash
go get github.com/partizaans/gormreplicated
```
## Example
Before reading the example it is better to check the gorm [official docs](https://gorm.io/docs/dbresolver.html).
```golang
package main
import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/plugin/dbresolver"
"github.com/partizaans/gormreplicated"
)
func main() {
db, err := gorm.Open(mysql.Open("db1_dsn"), &gorm.Config{})
db.Use(dbresolver.Register(dbresolver.Config{
// Use `db2`, `db1` as replica options
// It can be as many as replicas you want
// Note that the ordering is important
Replicas: []gorm.Dialector{mysql.Open("db2_dsn"), mysql.Open("db1_dsn")},
Policy: gormreplicated.ReplicaPolicy{},
}, "replicas"))
}
```