Skip to content

Adapters

Rel uses adapter in order to generate and execute query to a database, below is the list of available adapters currently supported.

Adapter Package Godoc
MySQL github.com/go-rel/mysql GoDoc
PostgreSQL github.com/go-rel/postgres GoDoc
MSSQL github.com/go-rel/mssql GoDoc
SQLite3 github.com/go-rel/sqlite3 GoDoc

Using Primary Replica Connections

REL Read Write separation for primary replica connections by using intermediary adapters.

package main

import (
    "context"

    _ "github.com/go-sql-driver/mysql"
    "github.com/go-rel/primaryreplica"
    "github.com/go-rel/mysql"
    "github.com/go-rel/rel"
)
func main() {
    // open mysql connections.
    // note: `clientFoundRows=true` is required for update and delete to works correctly.
    adapter := primaryreplica.New(
        mysql.MustOpen("root@(source:3306)/rel_test?charset=utf8&parseTime=True&loc=Local"),
        mysql.MustOpen("root@(replica1:3306)/rel_test?charset=utf8&parseTime=True&loc=Local"),
        mysql.MustOpen("root@(replica2:3306)/rel_test?charset=utf8&parseTime=True&loc=Local"),
    )
    defer adapter.Close()

    // initialize REL's repo.
    repo := rel.New(adapter)
    repo.Ping(context.TODO())
}

Load Balancing of Replicas

REL only implements a very primitive load balancing for multiple replicas. For large scale application we recommend you to use external load balancing solution.


Last update: 2022-07-08