flash

package module
v0.0.0-...-e455efd Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: MIT Imports: 12 Imported by: 4

README

Flash

Documentation License

Flash is a lightweight Go library for managing real-time PostgreSQL changes using event management.

Notes

This library is currently under active development.

Features and APIs may change.

Contributions and feedback are welcome!

Features

  • ✅ Start/Stop listening during runtime.
  • ✅ Supports common PostgreSQL events: Insert, Update, Delete, Truncate.
  • ✅ Driver interfaces for creating new drivers.
  • ✅ Parallel Callback execution using goroutine
  • ✅ Listen for changes in specific columns, not the entire row.
  • ✅ Listen changes using WAL replication

🌐 Visit Our Website

For more information, updates, and resources, check out the official website:

📚 Documentation

Our detailed documentation is available to help you get started, learn how to configure and use Flash, and explore advanced features:

Contributing

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Commit your changes.
  4. Push your branch.
  5. Create a pull request.

Credits

License

MIT. See the License File for more information.

Documentation

Index

Constants

Variables

View Source
var DefaultDriverTestConfig = &DriverTestConfig{
	ImagesVersions: []string{

		"docker.io/postgres:14-alpine",
		"docker.io/postgres:15-alpine",
		"docker.io/postgres:16-alpine",
	},

	Database: "testdb",
	Username: "testuser",
	Password: "testpasword",

	PropagationTimeout:  time.Second,
	RegistrationTimeout: time.Second,

	Parallel: false,
}

Functions

func RunFlashDriverTestCase

func RunFlashDriverTestCase[T Driver](t *testing.T, config *DriverTestConfig, getDriverCb func() T)

Types

type Client

type Client struct {
	Config *ClientConfig
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config *ClientConfig) (*Client, error)

func (*Client) Attach

func (c *Client) Attach(listeners ...*Listener)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Init

func (c *Client) Init() error

func (*Client) Start

func (c *Client) Start() error

type ClientConfig

type ClientConfig struct {
	DatabaseCnx string
	Driver      Driver
	Logger      *zerolog.Logger

	ShutdownTimeout time.Duration
}

type CreateEventCallback

type CreateEventCallback func(event Operation) error

type DatabaseEvent

type DatabaseEvent struct {
	ListenerUid string
	Event       Event
}

type DatabaseEventsChan

type DatabaseEventsChan chan *DatabaseEvent

type DeleteEvent

type DeleteEvent struct {
	Old *EventData
}

func (*DeleteEvent) GetOperation

func (e *DeleteEvent) GetOperation() Operation

type DeleteEventCallback

type DeleteEventCallback func(event Operation) error

type Driver

type Driver interface {
	Init(clientConfig *ClientConfig) error
	Close() error

	HandleOperationListenStart(listenerUid string, listenerConfig *ListenerConfig, operation Operation) error
	HandleOperationListenStop(listenerUid string, listenerConfig *ListenerConfig, operation Operation) error
	Listen(eventsChan *DatabaseEventsChan) error
}

type DriverTestConfig

type DriverTestConfig struct {
	ImagesVersions []string `default:"postgres,flash"`

	Database string
	Username string
	Password string

	ContainerCustomizers []testcontainers.ContainerCustomizer

	PropagationTimeout  time.Duration // Delay for event propagated from the DB to the eventsChan
	RegistrationTimeout time.Duration // Delay for OperationListenStart / HandleOperationListenStop

	Parallel bool
}

type Event

type Event interface {
	GetOperation() Operation
}

type EventCallback

type EventCallback func(event Event)

type EventData

type EventData map[string]any

type ExecSqlFunc

type ExecSqlFunc func(t *testing.T, sql string) string

type InsertEvent

type InsertEvent struct {
	New *EventData
}

func (*InsertEvent) GetOperation

func (e *InsertEvent) GetOperation() Operation

type Listener

type Listener struct {
	Config *ListenerConfig

	// Internals
	sync.Mutex
	// contains filtered or unexported fields
}

func NewListener

func NewListener(config *ListenerConfig) (*Listener, error)

func (*Listener) Close

func (l *Listener) Close() error

func (*Listener) Dispatch

func (l *Listener) Dispatch(event *Event)

func (*Listener) Init

func (l *Listener) Init(_createCallback CreateEventCallback, _deleteCallback DeleteEventCallback) error

Init emit all event for first boot */

func (*Listener) On

func (l *Listener) On(operation Operation, callback EventCallback) (func() error, error)

type ListenerCondition

type ListenerCondition struct {
	Column string
	//Operator string //TODO actually only equals are implemented
	Value any
}

TODO SORTIR VERIFICATION AU NIVEAU LISTENER, PBM oblige à envoyer les columns dans l'event

type ListenerConfig

type ListenerConfig struct {
	Table              string   // Can be prefixed by schema - e.g: public.posts
	Fields             []string // Empty fields means all ( SELECT * )
	MaxParallelProcess int      // Default to 1 (not parallel) -> use -1 for Infinity

	Conditions []*ListenerCondition
}

type Operation

type Operation uint8
const (
	OperationInsert Operation = 1 << iota
	OperationUpdate
	OperationDelete
	OperationTruncate
)

func OperationFromName

func OperationFromName(name string) (Operation, error)

func (Operation) GetAtomics

func (o Operation) GetAtomics() []Operation

func (Operation) IncludeAll

func (o Operation) IncludeAll(targetOperation Operation) bool

IncludeAll checks if the current operation includes all specified atomic operations.

func (Operation) IncludeOne

func (o Operation) IncludeOne(targetOperation Operation) bool

IncludeOne checks if the current operation includes at least one of the specified atomic operations.

func (Operation) IsAtomic

func (o Operation) IsAtomic() bool

func (Operation) StrictName

func (o Operation) StrictName() (string, error)

StrictName returns the name of the operation, or throws an error if it doesn't exist

func (Operation) String

func (o Operation) String() string

Use with caution, because no errors are returned when invalid

type TestFn

type TestFn func(t *testing.T, name string, f func(t *testing.T), restore bool)

type TruncateEvent

type TruncateEvent struct{}

func (*TruncateEvent) GetOperation

func (e *TruncateEvent) GetOperation() Operation

type UpdateEvent

type UpdateEvent struct {
	Old *EventData
	New *EventData
}

func (*UpdateEvent) GetOperation

func (e *UpdateEvent) GetOperation() Operation

Directories

Path Synopsis
_examples
debug_trace command
development command
specific_fields command
trigger_all command
trigger_insert command
drivers
trigger module
wal_logical module

Jump to

Keyboard shortcuts

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