crudr

package
v0.0.0-...-4221867 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionCreate = "create"
	ActionUpdate = "update"
	ActionDelete = "delete"
)
View Source
const (
	LocalStreamName  = "ops"
	GlobalStreamName = "global"
)

Variables

This section is empty.

Functions

func SetupTestDB

func SetupTestDB() *gorm.DB

func WithSkipBroadcast

func WithSkipBroadcast() withOption

func WithTransient

func WithTransient() withOption

Types

type Crudr

type Crudr struct {
	DB *gorm.DB
	// contains filtered or unexported fields
}

func New

func New(selfHost string, myPrivateKey *ecdsa.PrivateKey, peerHosts []string, db *gorm.DB) *Crudr

func (*Crudr) AddOpCallback

func (c *Crudr) AddOpCallback(cb func(op *Op, records interface{}))

func (*Crudr) ApplyOp

func (c *Crudr) ApplyOp(op *Op) error

func (*Crudr) Create

func (c *Crudr) Create(data interface{}, opts ...withOption) error

func (*Crudr) Delete

func (c *Crudr) Delete(data interface{}, opts ...withOption) error

func (*Crudr) ForceSweep

func (c *Crudr) ForceSweep()

used for testing

func (*Crudr) GetOutboxSizes

func (c *Crudr) GetOutboxSizes() map[string]int

func (*Crudr) GetPercentNodesSeeded

func (c *Crudr) GetPercentNodesSeeded() float64

func (*Crudr) KnownType

func (c *Crudr) KnownType(op *Op) bool

func (*Crudr) Patch

func (c *Crudr) Patch(data interface{}, opts ...withOption) error

func (*Crudr) RegisterModels

func (c *Crudr) RegisterModels(tables ...interface{}) *Crudr

RegisterModels accepts a instance of a GORM model and registers it to work with Op apply.

func (*Crudr) StartClients

func (c *Crudr) StartClients()

func (*Crudr) Update

func (c *Crudr) Update(data interface{}, opts ...withOption) error

type Cursor

type Cursor struct {
	Host     string `json:"host" gorm:"primaryKey"`
	LastULID string `json:"last_ulid" gorm:"column:last_ulid"`
}

type Op

type Op struct {
	ULID   string          `json:"ulid" gorm:"column:ulid"`
	Host   string          `json:"host"`
	Action string          `json:"action"` // create, update, delete
	Table  string          `json:"table"`
	Data   json.RawMessage `json:"data"`

	Transient     bool `json:"transient" gorm:"-"`
	SkipBroadcast bool `json:"-" gorm:"-"`
}

func (Op) String

func (op Op) String() string

type PeerClient

type PeerClient struct {
	Host   string
	Seeded bool
	// contains filtered or unexported fields
}

func NewPeerClient

func NewPeerClient(host string, crudr *Crudr, selfHost string) *PeerClient

func (*PeerClient) Send

func (p *PeerClient) Send(data []byte) bool

func (*PeerClient) Start

func (p *PeerClient) Start()

Jump to

Keyboard shortcuts

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