driver

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2025 License: MIT Imports: 10 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyRegistered = errors.New("driver already registered")
	ErrNotRegistered     = errors.New("driver not registered")
)
View Source
var (
	ErrKeyMissing   = errors.New("key is missing")
	ErrKeyDuplicate = errors.New("key already exists")
	ErrKeyNotFound  = errors.New("key not found")

	ErrUnsupportedOperation = errors.New("unsupported operation")
	ErrUnsupportedType      = errors.New("unsupported type")
)

Functions

This section is empty.

Types

type Conn

type Conn interface {
	Load(name string) (Store, error)
	Close() error
}

Conn provides access to named Store instances.

type ConnAlias

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

ConnAlias represents a connection with alias support for table names.

func NewConnAlias

func NewConnAlias(conn Conn) *ConnAlias

NewConnAlias creates a new ConnAlias instance with the given connection.

func (*ConnAlias) Alias

func (c *ConnAlias) Alias(name, alias string)

Alias assigns an alias to a table name.

func (*ConnAlias) Close

func (c *ConnAlias) Close() error

Close closes the underlying connection.

func (*ConnAlias) Load

func (c *ConnAlias) Load(name string) (Store, error)

Load retrieves a table by its name.

type ConnProxy

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

ConnProxy wraps a Conn and allows dynamic replacement with concurrency safety.

func NewConnProxy

func NewConnProxy(conn Conn) *ConnProxy

NewConnProxy returns a new ConnProxy that wraps the given Conn.

func (*ConnProxy) Close

func (p *ConnProxy) Close() error

Close delegates to the underlying conn's Close method.

func (*ConnProxy) Load

func (p *ConnProxy) Load(name string) (Store, error)

Load delegates to the underlying conn's Load method.

func (*ConnProxy) Unwrap

func (p *ConnProxy) Unwrap() Conn

Unwrap returns the currently wrapped Conn.

func (*ConnProxy) Wrap

func (p *ConnProxy) Wrap(conn Conn)

Wrap sets the underlying Conn.

type Cursor

type Cursor interface {
	All(ctx context.Context, val any) error
	Next(ctx context.Context) bool
	Decode(val any) error
	Close(ctx context.Context) error
}

Cursor defines the interface for iterating over a collection of documents.

type DeleteOptions

type DeleteOptions struct {
}

DeleteOptions represents options when deleting documents.

type Driver

type Driver interface {
	Open(name string) (Conn, error)
	Close() error
}

Driver manages the opening and closing of connections.

func New

func New() Driver

New creates a new driver instance with an empty connections map.

type Event

type Event struct {
	ID uuid.UUID `json:"id" yaml:"id" validate:"required"`
	OP string    `json:"op" yaml:"op" validate:"required"`
}

Event represents a change event within the store.

type FindOptions

type FindOptions struct {
	Limit int
	Skip  int
	Sort  any
}

FindOptions represents options when finding documents.

type IndexOptions

type IndexOptions struct {
	Unique bool
	Filter any
}

IndexOptions represents options when creating an index.

type InsertOptions

type InsertOptions struct {
}

InsertOptions represents options when inserting documents.

type Proxy

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

Proxy wraps a Driver and allows dynamic replacement with concurrency safety.

func NewProxy

func NewProxy(driver Driver) *Proxy

NewProxy returns a new Proxy that wraps the given driver.

func (*Proxy) Close

func (p *Proxy) Close() error

Close delegates to the underlying driver's Close method if set.

func (*Proxy) Open

func (p *Proxy) Open(name string) (Conn, error)

Open delegates to the underlying driver's Open method.

func (*Proxy) Unwrap

func (p *Proxy) Unwrap() Driver

Unwrap returns the currently wrapped driver.

func (*Proxy) Wrap

func (p *Proxy) Wrap(driver Driver)

Wrap sets the underlying driver.

type Registry

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

Registry manages a collection of drivers.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates and returns a new Registry instance.

func (*Registry) Close

func (r *Registry) Close() error

Close shuts down all registered drivers and clears the registry.

func (*Registry) Lookup

func (r *Registry) Lookup(name string) (Driver, error)

Lookup retrieves a driver by its name. Returns an error if the driver is not found.

func (*Registry) Register

func (r *Registry) Register(name string, driver Driver) error

Register adds a driver to the registry. Returns an error if the driver already exists.

func (*Registry) Unregister

func (r *Registry) Unregister(name string) error

Unregister removes a driver from the registry. Returns an error if the driver is not found.

type Store

type Store interface {
	Watch(ctx context.Context, filter any) (Stream, error)

	Index(ctx context.Context, keys []string, opts ...IndexOptions) error
	Unindex(ctx context.Context, keys []string) error

	Insert(ctx context.Context, docs []any, opts ...InsertOptions) error
	Update(ctx context.Context, filter, update any, opts ...UpdateOptions) (int, error)
	Delete(ctx context.Context, filter any, opts ...DeleteOptions) (int, error)
	Find(ctx context.Context, filter any, opts ...FindOptions) (Cursor, error)
}

Store defines the interface for a basic document store.

func NewStore

func NewStore() Store

NewStore creates and returns a new in-memory store instance.

type Stream

type Stream interface {
	Next(ctx context.Context) bool
	Decode(val any) error
	Close(ctx context.Context) error
}

Stream defines an interface for consuming event streams.

type UpdateOptions

type UpdateOptions struct {
	Upsert bool
}

UpdateOptions represents options when updating documents.

Jump to

Keyboard shortcuts

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