storage

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initialize

func Initialize(db *sql.DB, schema string) error

Initialize executes the schema generated by GenerateSchema. It's a convenience helper for development and testing. For production, it's recommended to use a proper migration tool.

Types

type Option

type Option func(*SQLiteStorage)

Option is a function that configures a SQLiteStorage.

func WithCustomFields

func WithCustomFields(fields map[string]string) Option

WithCustomFields defines the schema for additional application-specific data to be stored. The map key is the key used in the workflow's context map. The map value is the full SQL column definition (e.g., "title TEXT", "amount INTEGER NOT NULL").

func WithIDColumn

func WithIDColumn(name string) Option

WithIDColumn sets the name of the column used to store the workflow ID. Default: "id".

func WithStateColumn

func WithStateColumn(name string) Option

WithStateColumn sets the name of the column used to store the workflow's current places (state). Default: "state".

func WithTable

func WithTable(name string) Option

WithTable sets the name of the table used to store workflow state. Default: "workflow_states".

type SQLiteStorage

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

SQLiteStorage provides a persistent storage implementation using SQLite. It is highly configurable to allow for custom table and column names, as well as storing arbitrary application-specific data alongside the workflow state.

func NewSQLiteStorage

func NewSQLiteStorage(db *sql.DB, opts ...Option) (*SQLiteStorage, error)

NewSQLiteStorage creates a new SQLiteStorage with the given options.

func (*SQLiteStorage) DeleteState

func (s *SQLiteStorage) DeleteState(id string) error

DeleteState removes a workflow's state from the database.

func (*SQLiteStorage) GenerateSchema

func (s *SQLiteStorage) GenerateSchema() string

GenerateSchema returns the `CREATE TABLE` SQL statement based on the storage configuration. This allows the user to see, modify, or use the schema with a separate migration tool.

func (*SQLiteStorage) LoadState

func (s *SQLiteStorage) LoadState(id string) ([]workflow.Place, map[string]interface{}, error)

LoadState loads the workflow's places and all configured custom fields into the context map.

func (*SQLiteStorage) SaveState

func (s *SQLiteStorage) SaveState(id string, places []workflow.Place, context map[string]interface{}) error

SaveState saves the workflow's current places and any configured custom fields from its context.

Jump to

Keyboard shortcuts

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