sql

package
v1.46.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

see marker below

Package ptr provides utilities for pointer operations using storage layer paths.

Index

Constants

View Source
const (
	ColumnTypeJSON    = "json"
	ColumnTypeString  = "string"
	ColumnTypeBool    = "bool"
	ColumnTypeFloat64 = "float64"
	ColumnTypeInt64   = "int64"
)
View Source
const ArrayIndexTypeMsg = "array index must be integer"
View Source
const DoesNotExistMsg = "document does not exist"
View Source
const OutOfRangeMsg = "array index out of range"

Variables

View Source
var (
	ErrInvalidTableName   = errors.New("invalid table name")
	ErrInvalidTablePath   = errors.New("invalid storage path")
	ErrInvalidTableColumn = errors.New("invalid table column")
)

Functions

func New

func New(ctx context.Context, _ logging.Logger, prom prometheus.Registerer, options interface{}) (storage.Store, error)

New returns a new SQL-based store based on the provided options. It does not validate the table configuration with the existing tables in the database.

func NewNotFoundError

func NewNotFoundError(path storage.Path) *storage.Error

func NewNotFoundErrorWithHint

func NewNotFoundErrorWithHint(path storage.Path, hint string) *storage.Error

func NewNotFoundErrorf

func NewNotFoundErrorf(f string, a ...interface{}) *storage.Error

func NewWriteConflictError

func NewWriteConflictError(p storage.Path) *storage.Error

func Ptr

func Ptr(data interface{}, path storage.Path) (interface{}, error)

func ValidateArrayIndex

func ValidateArrayIndex(arr []interface{}, s string, path storage.Path) (int, error)

func ValidateArrayIndexForWrite

func ValidateArrayIndexForWrite(arr []interface{}, s string, i int, path storage.Path) (int, error)

ValidateArrayIndexForWrite also checks that `s` is a valid way to address an array element like `ValidateArrayIndex`, but returns a `resource_conflict` error if it is not.

Types

type Discovery

type Discovery struct {
	Schema string `json:"schema"`
	Path   string `json:"path"`
}

type Options

type Options struct {
	Driver         string // SQL driver name
	DataSourceName string // SQL data source name
	Tables         []TableOpt
}

Options contains parameters that configure the SQL-based store.

func OptionsFromConfig

func OptionsFromConfig(ctx context.Context, raw []byte, id string) (*Options, error)

OptionsFromConfig parses the passed config, extracts the disk storage settings, validates it, and returns a *Options struct pointer on success.

func (Options) WithTables

func (o Options) WithTables(tables []TableOpt) Options

type Store

type Store struct {
	storage.PolicyNotSupported
	storage.TriggersNotSupported
	// contains filtered or unexported fields
}

Store provides an SQL-based implementation of the storage.Store interface.

func (*Store) Abort

func (db *Store) Abort(ctx context.Context, txn storage.Transaction)

Abort implements the storage.Store interface.

func (*Store) Close

func (db *Store) Close(context.Context) error

Close finishes the DB connection(s).

func (*Store) Commit

func (db *Store) Commit(ctx context.Context, txn storage.Transaction) error

Commit implements the storage.Store interface.

func (*Store) MakeDir

func (db *Store) MakeDir(_ context.Context, txn storage.Transaction, _ storage.Path) error

MakeDir makes Store a storage.MakeDirer, to avoid the superfluous MakeDir steps -- MakeDir is implicit in the disk storage's data layout.

Here, we only check if it's a write transaction, for consistency with other implementations, and do nothing.

func (*Store) NewTransaction

func (db *Store) NewTransaction(ctx context.Context, params ...storage.TransactionParams) (storage.Transaction, error)

NewTransaction implements the storage.Store interface.

func (*Store) Read

func (db *Store) Read(ctx context.Context, txn storage.Transaction, path storage.Path) (interface{}, error)

Read implements the storage.Store interface.

func (*Store) ReadBJSON

func (db *Store) ReadBJSON(ctx context.Context, txn storage.Transaction, path storage.Path) (bjson.Json, error)

ReadBJSON implements the storage.Store interface.

func (*Store) Truncate

Truncate implements the storage.Store interface. This method must be called within a transaction.

func (*Store) Write

func (db *Store) Write(ctx context.Context, txn storage.Transaction, op storage.PatchOp, path storage.Path, value interface{}) error

Write implements the storage.Store interface.

type Table

type Table struct {
	Path       string        `json:"path"`        // Tables path in the namespace.
	Table      string        `json:"table"`       // Table name
	PrimaryKey []string      `json:"primary_key"` // Column names
	Values     []ValueColumn `json:"values"`      // Value columns
}

type TableOpt

type TableOpt struct {
	Path         storage.Path // Base path for the table (wild carded primary key included).
	Table        string
	KeyColumns   []string
	ValueColumns []ValueColumnOpt
	// contains filtered or unexported fields
}

func (*TableOpt) AbsolutePath

func (t *TableOpt) AbsolutePath(path storage.Path) storage.Path

AbsolutePath converts a table relative path to an absolute path.

func (*TableOpt) DeleteArgs

func (t *TableOpt) DeleteArgs(path storage.Path) []interface{}

func (*TableOpt) DeleteQuery

func (t *TableOpt) DeleteQuery() string

func (*TableOpt) DocPath

func (t *TableOpt) DocPath(path storage.Path) storage.Path

func (*TableOpt) InsertArgs

func (t *TableOpt) InsertArgs(path storage.Path, value interface{}) ([]interface{}, error)

func (*TableOpt) InsertQuery

func (t *TableOpt) InsertQuery() string

func (*TableOpt) RelativePath

func (t *TableOpt) RelativePath(path storage.Path) storage.Path

RelativePath converts an absolute path to a table relative path.

func (*TableOpt) Scan

func (t *TableOpt) Scan(rows *sql.Rows) (storage.Path, interface{}, error)

func (*TableOpt) Schema

func (t *TableOpt) Schema() string

func (*TableOpt) SelectArgs

func (t *TableOpt) SelectArgs(path storage.Path) []interface{}

func (*TableOpt) SelectQuery

func (t *TableOpt) SelectQuery(path storage.Path) string

type ValueColumn

type ValueColumn struct {
	Column string `json:"column"`
	Path   string `json:"path"`
	Type   string `json:"type"`
}

type ValueColumnOpt

type ValueColumnOpt struct {
	Column string
	Type   string
	Path   string
}

Jump to

Keyboard shortcuts

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