mysql

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package mysql is the implementation of the mysql data store.

Index

Examples

Constants

View Source
const (
	// DefaultEventStoreTable is the default table name
	DefaultEventStoreTable = "event_store"
)

Variables

View Source
var (
	// ErrLocked is used when we can't acquire an explicit lock
	ErrLocked = errors.New("can't acquire lock")

	// ErrNoDatabaseName is used when the database name is blank
	ErrNoDatabaseName = errors.New("no database name")
)

Functions

This section is empty.

Types

type MySQL

type MySQL struct {
	DatabaseName    string
	EventStoreTable string
	// contains filtered or unexported fields
}

MySQL is the implementation of the data store

Example
package main

import (
	"context"
	"database/sql"
	"fmt"
	"os"

	"github.com/italolelis/outboxer/mysql"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	db, err := sql.Open("mysql", os.Getenv("DS_DSN"))
	if err != nil {
		fmt.Printf("failed to connect to mysql: %s", err)
		return
	}

	ds, err := mysql.WithInstance(ctx, db)
	if err != nil {
		fmt.Printf("failed to setup the data store: %s", err)
		return
	}
	defer ds.Close()
}
Output:

func WithInstance

func WithInstance(ctx context.Context, db *sql.DB) (*MySQL, error)

WithInstance creates a mysql data store with an existing db connection

func (*MySQL) Add

func (p *MySQL) Add(ctx context.Context, evt *outboxer.OutboxMessage) error

Add adds the message to the data store

func (*MySQL) AddWithinTx

func (p *MySQL) AddWithinTx(ctx context.Context, evt *outboxer.OutboxMessage, fn func(outboxer.ExecerContext) error) error

AddWithinTx creates a transaction and then tries to execute anything within it

func (*MySQL) Close

func (p *MySQL) Close() error

Close closes the db connection

func (*MySQL) GetEvents

func (p *MySQL) GetEvents(ctx context.Context, batchSize int32) ([]*outboxer.OutboxMessage, error)

GetEvents retrieves all the relevant events

func (*MySQL) Remove

func (p *MySQL) Remove(ctx context.Context, dispatchedBefore time.Time, batchSize int32) error

Remove removes old messages from the data store

func (*MySQL) SetAsDispatched

func (p *MySQL) SetAsDispatched(ctx context.Context, id int64) error

SetAsDispatched sets one message as dispatched

Jump to

Keyboard shortcuts

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