driver

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package driver defines the interface for database service implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	CreateTable(ctx context.Context, config TableConfig) error
	DeleteTable(ctx context.Context, name string) error
	DescribeTable(ctx context.Context, name string) (*TableConfig, error)
	ListTables(ctx context.Context) ([]string, error)

	PutItem(ctx context.Context, table string, item map[string]any) error
	GetItem(ctx context.Context, table string, key map[string]any) (map[string]any, error)
	UpdateItem(ctx context.Context, input UpdateItemInput) (map[string]any, error)
	DeleteItem(ctx context.Context, table string, key map[string]any) error
	Query(ctx context.Context, input QueryInput) (*QueryResult, error)
	Scan(ctx context.Context, input ScanInput) (*QueryResult, error)

	BatchPutItems(ctx context.Context, table string, items []map[string]any) error
	BatchGetItems(ctx context.Context, table string, keys []map[string]any) ([]map[string]any, error)

	// TTL
	UpdateTTL(ctx context.Context, table string, config TTLConfig) error
	DescribeTTL(ctx context.Context, table string) (*TTLConfig, error)

	// Streams / Change Feed
	UpdateStreamConfig(ctx context.Context, table string, config StreamConfig) error
	GetStreamRecords(ctx context.Context, table string, limit int, token string) (*StreamIterator, error)

	// Transactional writes
	TransactWriteItems(ctx context.Context, table string, puts []map[string]any, deletes []map[string]any) error

	// Global Secondary Indexes
	CreateIndex(ctx context.Context, table string, config GSIConfig) (*IndexInfo, error)
	DeleteIndex(ctx context.Context, table, indexName string) error
	DescribeIndex(ctx context.Context, table, indexName string) (*IndexInfo, error)
	ListIndexes(ctx context.Context, table string) ([]IndexInfo, error)
}

Database is the interface that database provider implementations must satisfy.

type GSIConfig

type GSIConfig struct {
	Name         string
	PartitionKey string
	SortKey      string
}

GSIConfig describes a Global Secondary Index.

type IndexInfo added in v1.4.0

type IndexInfo struct {
	Name         string
	PartitionKey string
	SortKey      string
	Status       string // "ACTIVE", "CREATING", "DELETING"
}

IndexInfo describes a Global Secondary Index.

type KeyCondition

type KeyCondition struct {
	PartitionKey string
	PartitionVal any
	SortOp       string // "=", "<", ">", "<=", ">=", "BETWEEN", "BEGINS_WITH"
	SortVal      any
	SortValEnd   any // for BETWEEN
}

KeyCondition defines a key condition for queries.

type QueryInput

type QueryInput struct {
	Table        string
	IndexName    string
	KeyCondition KeyCondition
	Limit        int
	PageToken    string
	ScanForward  bool
}

QueryInput configures a query operation.

type QueryResult

type QueryResult struct {
	Items         []map[string]any
	Count         int
	NextPageToken string
}

QueryResult is the result of a query or scan.

type ScanFilter

type ScanFilter struct {
	Field string
	Op    string // "=", "!=", "<", ">", "<=", ">=", "CONTAINS", "BEGINS_WITH"
	Value any
}

ScanFilter defines a scan filter.

type ScanInput

type ScanInput struct {
	Table     string
	Filters   []ScanFilter
	Limit     int
	PageToken string
}

ScanInput configures a scan operation.

type StreamConfig added in v1.2.0

type StreamConfig struct {
	Enabled  bool
	ViewType string // "NEW_IMAGE", "OLD_IMAGE", "NEW_AND_OLD_IMAGES", "KEYS_ONLY"
}

StreamConfig configures streams for a table.

type StreamIterator added in v1.2.0

type StreamIterator struct {
	ShardID   string
	Records   []StreamRecord
	NextToken string
}

StreamIterator allows reading stream records.

type StreamRecord added in v1.2.0

type StreamRecord struct {
	EventID        string
	EventType      string // "INSERT", "MODIFY", "REMOVE"
	Table          string
	Keys           map[string]any
	NewImage       map[string]any
	OldImage       map[string]any
	Timestamp      time.Time
	SequenceNumber string
}

StreamRecord represents a change event in a stream.

type TTLConfig added in v1.2.0

type TTLConfig struct {
	Enabled       bool
	AttributeName string // the field containing the TTL timestamp
}

TTLConfig configures TTL for a table.

type TableConfig

type TableConfig struct {
	Name         string
	PartitionKey string
	SortKey      string
	GSIs         []GSIConfig
}

TableConfig describes a table to create.

type UpdateAction added in v1.3.1

type UpdateAction struct {
	Action string // "SET" or "REMOVE"
	Field  string
	Value  any // ignored for REMOVE
}

UpdateAction represents a single field-level update action.

type UpdateItemInput added in v1.3.1

type UpdateItemInput struct {
	Table   string
	Key     map[string]any
	Actions []UpdateAction
}

UpdateItemInput describes an update operation on an existing item.

Jump to

Keyboard shortcuts

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