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