primaryreplica

package module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2023 License: MIT Imports: 3 Imported by: 0

README

primaryreplica

GoDoc Test Go Report Card codecov Gitter chat

Read Write separation for primary-replica topologies

Example

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(primary rel.Adapter, replicas ...rel.Adapter) rel.Adapter

Types

type PrimaryReplica

type PrimaryReplica struct {
	// contains filtered or unexported fields
}

func (*PrimaryReplica) Aggregate

func (pr *PrimaryReplica) Aggregate(ctx context.Context, query rel.Query, mode string, field string) (int, error)

func (*PrimaryReplica) Apply

func (pr *PrimaryReplica) Apply(ctx context.Context, migration rel.Migration) error

func (*PrimaryReplica) Begin

func (pr *PrimaryReplica) Begin(ctx context.Context) (rel.Adapter, error)

func (*PrimaryReplica) Close

func (pr *PrimaryReplica) Close() error

func (*PrimaryReplica) Commit

func (pr *PrimaryReplica) Commit(ctx context.Context) error

func (*PrimaryReplica) Delete

func (pr *PrimaryReplica) Delete(ctx context.Context, query rel.Query) (int, error)

func (*PrimaryReplica) Exec

func (pr *PrimaryReplica) Exec(ctx context.Context, stmt string, args []interface{}) (int64, int64, error)

func (*PrimaryReplica) Insert

func (pr *PrimaryReplica) Insert(ctx context.Context, query rel.Query, primaryField string, mutates map[string]rel.Mutate, onConflict rel.OnConflict) (interface{}, error)

func (*PrimaryReplica) InsertAll

func (pr *PrimaryReplica) InsertAll(ctx context.Context, query rel.Query, primaryField string, fields []string, bulkMutates []map[string]rel.Mutate, onConflict rel.OnConflict) ([]interface{}, error)

func (*PrimaryReplica) Instrumentation

func (pr *PrimaryReplica) Instrumentation(instrumenter rel.Instrumenter)

func (*PrimaryReplica) Name added in v0.6.0

func (pr *PrimaryReplica) Name() string

func (*PrimaryReplica) Ping

func (pr *PrimaryReplica) Ping(ctx context.Context) error

func (*PrimaryReplica) Query

func (pr *PrimaryReplica) Query(ctx context.Context, query rel.Query) (rel.Cursor, error)

func (*PrimaryReplica) Rollback

func (pr *PrimaryReplica) Rollback(ctx context.Context) error

func (*PrimaryReplica) Update

func (pr *PrimaryReplica) Update(ctx context.Context, query rel.Query, primaryField string, mutates map[string]rel.Mutate) (int, error)

func (*PrimaryReplica) WriteAdapter added in v0.5.0

func (pr *PrimaryReplica) WriteAdapter() rel.Adapter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL