Skip to content

This library is a complementary library for Gorm (v2) which resolves the first available pool passed to it.

Notifications You must be signed in to change notification settings

partizaans/gormreplicated

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Gorm Replicated

This library is a complementary library for Gorm (v2) which resolves the first available pool passed to it.

Installation

go get github.com/partizaans/gormreplicated

Example

Before reading the example it is better to check the gorm official docs.

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"))
}

About

This library is a complementary library for Gorm (v2) which resolves the first available pool passed to it.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages