sqlstorage

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 38 Imported by: 0

Documentation

Overview

File is part of the build only if cgo is enabled. Otherwise, the compilation will complains about missing type sqlite3,Error It is due to the fact than sqlite lib use import "C" statement. The presence of these statement during the build exclude the file if CGO is disabled.

Index

Constants

View Source
const (
	SQLCustomFuncMetaCompare = "meta_compare"
)
View Source
const SystemSchema = "_system"

Variables

View Source
var (
	SQLite     = Flavor(sqlbuilder.SQLite)
	PostgreSQL = Flavor(sqlbuilder.PostgreSQL)
)
View Source
var MigrationsFS embed.FS

Functions

func DriverModule

func DriverModule(cfg ModuleConfig) fx.Option

func InstrumentalizeSQLDrivers added in v1.9.0

func InstrumentalizeSQLDrivers()

func Migrate added in v1.7.0

func Migrate(ctx context.Context, schema Schema, migrations ...Migration) (bool, error)

func NewDefaultStorageDriverFromRawDriver added in v1.8.0

func NewDefaultStorageDriverFromRawDriver(driver *Driver) storage.Driver[storage.LedgerStore]

func NewIdempotencyStorageDriverFromRawDriver added in v1.8.0

func NewIdempotencyStorageDriverFromRawDriver(driver *Driver) storage.Driver[idempotency.Store]

func NewLedgerStorageDriverFromRawDriver added in v1.8.0

func NewLedgerStorageDriverFromRawDriver(driver *Driver) storage.Driver[ledger.Store]

func NewPostgresDB added in v1.3.2

func NewPostgresDB(db *sql.DB) *postgresDB

func NewSQLiteDB added in v1.3.2

func NewSQLiteDB(directory, dbName string) *sqliteDB

func OpenSQLDB added in v1.3.2

func OpenSQLDB(flavor Flavor, dataSourceName string) (*sql.DB, error)

func RegisterGoMigration added in v1.7.0

func RegisterGoMigration(fn MigrationFunc)

func RegisterGoMigrationFromFilename added in v1.7.0

func RegisterGoMigrationFromFilename(filename string, fn MigrationFunc)

func UpdateSQLDriverMapping

func UpdateSQLDriverMapping(flavor Flavor, name string)

Types

type AccPaginationToken added in v1.3.2

type AccPaginationToken struct {
	PageSize              uint                   `json:"pageSize"`
	Offset                uint                   `json:"offset"`
	AfterAddress          string                 `json:"after,omitempty"`
	AddressRegexpFilter   string                 `json:"address,omitempty"`
	MetadataFilter        map[string]string      `json:"metadata,omitempty"`
	BalanceFilter         string                 `json:"balance,omitempty"`
	BalanceOperatorFilter ledger.BalanceOperator `json:"balanceOperator,omitempty"`
}

type BalancesPaginationToken added in v1.6.0

type BalancesPaginationToken struct {
	PageSize            uint     `json:"pageSize"`
	Offset              uint     `json:"offset"`
	AfterAddress        string   `json:"after,omitempty"`
	AddressRegexpFilter []string `json:"address,omitempty"`
}

type DB added in v1.3.2

type DB interface {
	Initialize(ctx context.Context) error
	Schema(ctx context.Context, name string) (Schema, error)
	Close(ctx context.Context) error
}

type DefaultStorageDriver added in v1.8.0

type DefaultStorageDriver struct {
	*Driver
}

func (*DefaultStorageDriver) GetLedgerStore added in v1.8.0

func (d *DefaultStorageDriver) GetLedgerStore(ctx context.Context, name string, create bool) (storage.LedgerStore, bool, error)

type Driver added in v1.3.2

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

func NewDriver added in v1.3.2

func NewDriver(name string, db DB, redisLockStrategy bool) *Driver

func (*Driver) Close added in v1.3.2

func (d *Driver) Close(ctx context.Context) error

func (*Driver) GetLedgerStore added in v1.8.0

func (d *Driver) GetLedgerStore(ctx context.Context, name string, create bool) (*Store, bool, error)

func (*Driver) GetSystemStore added in v1.8.0

func (d *Driver) GetSystemStore() storage.SystemStore

func (*Driver) Initialize added in v1.3.2

func (d *Driver) Initialize(ctx context.Context) (err error)

func (*Driver) Name added in v1.3.2

func (d *Driver) Name() string

type Flavor

type Flavor sqlbuilder.Flavor

func FlavorFromString

func FlavorFromString(v string) Flavor

func (Flavor) String

func (f Flavor) String() string

type HandlersByEngine added in v1.7.0

type HandlersByEngine map[string][]MigrationFunc

type IdempotencyStorageDriver added in v1.8.0

type IdempotencyStorageDriver struct {
	*Driver
}

func (*IdempotencyStorageDriver) GetLedgerStore added in v1.8.0

func (d *IdempotencyStorageDriver) GetLedgerStore(ctx context.Context, name string, create bool) (idempotency.Store, bool, error)

type LedgerStorageDriver added in v1.8.0

type LedgerStorageDriver struct {
	*Driver
}

func (*LedgerStorageDriver) GetLedgerStore added in v1.8.0

func (d *LedgerStorageDriver) GetLedgerStore(ctx context.Context, name string, create bool) (ledger.Store, bool, error)

type LogsPaginationToken added in v1.9.0

type LogsPaginationToken struct {
	AfterID   uint64    `json:"after"`
	PageSize  uint      `json:"pageSize,omitempty"`
	StartTime time.Time `json:"startTime,omitempty"`
	EndTime   time.Time `json:"endTime,omitempty"`
}

type Migration added in v1.7.0

type Migration struct {
	core.MigrationInfo `json:"inline"`
	Handlers           HandlersByEngine `json:"-"`
}

func CollectMigrationFiles added in v1.7.0

func CollectMigrationFiles(migrationsFS fs.FS) ([]Migration, error)

type MigrationFunc added in v1.7.0

type MigrationFunc func(ctx context.Context, schema Schema, tx *sql.Tx) error

func SQLMigrationFunc added in v1.7.0

func SQLMigrationFunc(content string) MigrationFunc

type Migrations added in v1.7.0

type Migrations []Migration

func (Migrations) Len added in v1.7.0

func (m Migrations) Len() int

func (Migrations) Less added in v1.7.0

func (m Migrations) Less(i, j int) bool

func (Migrations) Swap added in v1.7.0

func (m Migrations) Swap(i, j int)

type ModuleConfig

type ModuleConfig struct {
	StorageDriver     string
	SQLiteConfig      *SQLiteConfig
	PostgresConfig    *PostgresConfig
	RedisLockStrategy bool
}

type PGSchema added in v1.3.2

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

func (*PGSchema) Close added in v1.3.2

func (s *PGSchema) Close(ctx context.Context) error

func (*PGSchema) Delete added in v1.3.2

func (s *PGSchema) Delete(ctx context.Context) error

func (*PGSchema) ExecContext added in v1.3.2

func (s *PGSchema) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*PGSchema) Flavor added in v1.3.2

func (s *PGSchema) Flavor() sqlbuilder.Flavor

func (*PGSchema) Initialize added in v1.3.2

func (s *PGSchema) Initialize(ctx context.Context) error

func (*PGSchema) Name added in v1.3.2

func (s *PGSchema) Name() string

func (*PGSchema) QueryContext added in v1.3.2

func (s *PGSchema) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

func (*PGSchema) QueryRowContext added in v1.3.2

func (s *PGSchema) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

func (*PGSchema) Table added in v1.3.2

func (s *PGSchema) Table(name string) string

type PostgresConfig

type PostgresConfig struct {
	ConnString string
}

type SQLiteConfig

type SQLiteConfig struct {
	Dir    string
	DBName string
}

type SQLiteSchema added in v1.3.2

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

func (*SQLiteSchema) Close added in v1.3.2

func (s *SQLiteSchema) Close(ctx context.Context) error

func (SQLiteSchema) Delete added in v1.3.2

func (s SQLiteSchema) Delete(ctx context.Context) error

func (*SQLiteSchema) ExecContext added in v1.3.2

func (s *SQLiteSchema) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (SQLiteSchema) Flavor added in v1.3.2

func (s SQLiteSchema) Flavor() sqlbuilder.Flavor

func (*SQLiteSchema) Initialize added in v1.3.2

func (s *SQLiteSchema) Initialize(ctx context.Context) error

func (*SQLiteSchema) Name added in v1.3.2

func (s *SQLiteSchema) Name() string

func (*SQLiteSchema) QueryContext added in v1.3.2

func (s *SQLiteSchema) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

func (*SQLiteSchema) QueryRowContext added in v1.3.2

func (s *SQLiteSchema) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

func (*SQLiteSchema) Table added in v1.3.2

func (s *SQLiteSchema) Table(name string) string

type Schema added in v1.3.2

type Schema interface {
	Initialize(ctx context.Context) error
	Table(name string) string
	Close(ctx context.Context) error
	BeginTx(ctx context.Context, s *sql.TxOptions) (*sql.Tx, error)
	Flavor() sqlbuilder.Flavor
	Name() string
	Delete(ctx context.Context) error
	// contains filtered or unexported methods
}

type Store

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

func NewStore

func NewStore(schema Schema, multipleInstance bool, executorProvider func(ctx context.Context) (executor, error),
	onClose, onDelete func(ctx context.Context) error) *Store

func (*Store) Close

func (s *Store) Close(ctx context.Context) error

func (*Store) Commit added in v1.8.0

func (s *Store) Commit(ctx context.Context, txs ...core.ExpandedTransaction) (err error)

func (*Store) CountAccounts

func (s *Store) CountAccounts(ctx context.Context, q ledger.AccountsQuery) (uint64, error)

func (*Store) CountTransactions

func (s *Store) CountTransactions(ctx context.Context, q ledger.TransactionsQuery) (uint64, error)

func (*Store) CreateIK added in v1.8.0

func (s *Store) CreateIK(ctx context.Context, key string, response idempotency.Response) error

func (*Store) Delete added in v1.8.0

func (s *Store) Delete(ctx context.Context) error

func (*Store) GetAccount added in v1.3.2

func (s *Store) GetAccount(ctx context.Context, addr string) (*core.Account, error)

func (*Store) GetAccountWithVolumes added in v1.9.0

func (s *Store) GetAccountWithVolumes(ctx context.Context, address string) (*core.AccountWithVolumes, error)

func (*Store) GetAccounts added in v1.3.2

func (s *Store) GetAccounts(ctx context.Context, q ledger.AccountsQuery) (api.Cursor[core.Account], error)

func (*Store) GetAssetsVolumes added in v1.6.0

func (s *Store) GetAssetsVolumes(ctx context.Context, accountAddress string) (core.AssetsVolumes, error)

func (*Store) GetBalances added in v1.6.0

func (*Store) GetBalancesAggregated added in v1.6.0

func (s *Store) GetBalancesAggregated(ctx context.Context, q ledger.AggregatedBalancesQuery) (core.AssetsBalances, error)

func (*Store) GetLastLog added in v1.9.0

func (s *Store) GetLastLog(ctx context.Context) (*core.Log, error)

func (*Store) GetLastTransaction added in v1.3.2

func (s *Store) GetLastTransaction(ctx context.Context) (*core.ExpandedTransaction, error)

func (*Store) GetLogs added in v1.9.0

func (s *Store) GetLogs(ctx context.Context, q *ledger.LogsQuery) (api.Cursor[core.Log], error)

func (*Store) GetMigrationsAvailable added in v1.9.0

func (s *Store) GetMigrationsAvailable() ([]core.MigrationInfo, error)

func (*Store) GetMigrationsDone added in v1.9.0

func (s *Store) GetMigrationsDone(ctx context.Context) ([]core.MigrationInfo, error)

func (*Store) GetTransaction

func (s *Store) GetTransaction(ctx context.Context, txId uint64) (*core.ExpandedTransaction, error)

func (*Store) GetTransactions added in v1.3.2

func (*Store) Initialize

func (s *Store) Initialize(ctx context.Context) (bool, error)

func (*Store) LoadMapping

func (s *Store) LoadMapping(ctx context.Context) (*core.Mapping, error)

func (*Store) Name

func (s *Store) Name() string

func (*Store) ReadIK added in v1.8.0

func (s *Store) ReadIK(ctx context.Context, key string) (*idempotency.Response, error)

func (*Store) SaveMapping

func (s *Store) SaveMapping(ctx context.Context, mapping core.Mapping) error

func (*Store) Schema added in v1.3.2

func (s *Store) Schema() Schema

func (*Store) UpdateAccountMetadata added in v1.8.0

func (s *Store) UpdateAccountMetadata(ctx context.Context, address string, metadata core.Metadata, at time.Time) error

func (*Store) UpdateTransactionMetadata added in v1.8.0

func (s *Store) UpdateTransactionMetadata(ctx context.Context, id uint64, metadata core.Metadata, at time.Time) error

type SystemStore added in v1.8.0

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

func (SystemStore) DeleteLedger added in v1.8.0

func (s SystemStore) DeleteLedger(ctx context.Context, name string) error

func (*SystemStore) GetConfiguration added in v1.8.0

func (s *SystemStore) GetConfiguration(ctx context.Context, key string) (string, error)

func (SystemStore) InsertConfiguration added in v1.8.0

func (s SystemStore) InsertConfiguration(ctx context.Context, key, value string) error

func (SystemStore) ListLedgers added in v1.8.0

func (s SystemStore) ListLedgers(ctx context.Context) ([]string, error)

func (*SystemStore) Register added in v1.8.0

func (s *SystemStore) Register(ctx context.Context, ledger string) (bool, error)

type TxsPaginationToken added in v1.3.2

type TxsPaginationToken struct {
	AfterTxID         uint64            `json:"after"`
	ReferenceFilter   string            `json:"reference,omitempty"`
	AccountFilter     string            `json:"account,omitempty"`
	SourceFilter      string            `json:"source,omitempty"`
	DestinationFilter string            `json:"destination,omitempty"`
	StartTime         time.Time         `json:"startTime,omitempty"`
	EndTime           time.Time         `json:"endTime,omitempty"`
	MetadataFilter    map[string]string `json:"metadata,omitempty"`
	PageSize          uint              `json:"pageSize,omitempty"`
}

Directories

Path Synopsis
migrates

Jump to

Keyboard shortcuts

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