persistence

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PqForeignKeyViolationError = pq.ErrorCode("23503")
	PqUniqueViolationError     = pq.ErrorCode("23505")
)

Variables

This section is empty.

Functions

func CheckVector added in v0.7.0

func CheckVector(basis Basis, vector Vector) error

func NewMigration

func NewMigration(driverName, dataSourceName string) *migration

Types

type Basis added in v0.5.0

type Basis []Dimension

func NewBasis added in v0.5.0

func NewBasis(dims ...Dimension) (Basis, error)

func (*Basis) Scan added in v0.5.0

func (b *Basis) Scan(value any) error

func (Basis) Value added in v0.5.0

func (b Basis) Value() (value driver.Value, err error)

type Component added in v0.5.0

type Component any

func FromNumber added in v0.5.0

func FromNumber(f float64) Component

func FromString added in v0.5.0

func FromString(s string) Component

type Db

type Db interface {
	// NewModelTx creates new ModelTx object
	NewModelTx() ModelTx
	// NewTx creates Tx object
	NewTx() Tx
}

Db interface exposes

func NewDb

func NewDb(driverName, dataSourceName string) Db

NewDb creates new db object

type Dimension added in v0.5.0

type Dimension struct {
	Name string `json:"name"`
	Type Type   `json:"type"`
	Min  int64  `json:"min"`
	Max  int64  `json:"max"`
}

type Format added in v0.4.0

type Format struct {
	ID        string    `db:"id"`
	Name      string    `db:"name"`
	Basis     Basis     `db:"basis"`
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

type Index added in v0.0.2

type Index struct {
	ID        string    `db:"id"`
	Format    string    `db:"format"`
	Tags      Tags      `db:"tags"`
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

type IndexQuery added in v0.4.0

type IndexQuery struct {
	Format        string
	Tags          Tags
	CreatedAfter  time.Time
	CreatedBefore time.Time
	FromID        string
	Limit         int
}

type IndexRecord added in v0.0.2

type IndexRecord struct {
	ID        string    `db:"id"`
	IndexID   string    `db:"index_id"`
	Segment   string    `db:"segment"`
	Vector    Vector    `db:"vector"`
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

type IndexRecordQuery added in v0.4.0

type IndexRecordQuery struct {
	IndexIDs      []string
	CreatedAfter  time.Time
	CreatedBefore time.Time
	FromID        string
	Limit         int
}

type ModelTx

type ModelTx interface {
	Tx

	// CreateFormat creates format entry
	CreateFormat(format Format) (string, error)
	// GetFormat retrieves format entry by name
	GetFormat(name string) (Format, error)
	// DeleteFormat deletes format entry by name (only if not referenced)
	DeleteFormat(name string) error
	// ListFormats lists all the existing format entries
	ListFormats() ([]Format, error)

	// CreateIndex creates index entry based on source ID
	CreateIndex(index Index) (string, error)
	// GetIndex retrieves index info by ID
	GetIndex(ID string) (Index, error)
	// UpdateIndex updates index info
	UpdateIndex(index Index) error
	// DeleteIndex deletes index entry and all the related records
	DeleteIndex(ID string) error
	// QueryIndexes lists query matching index entries
	QueryIndexes(query IndexQuery) (QueryResult[Index, string], error)

	// CreateIndexRecord creates index record entry
	CreateIndexRecord(record IndexRecord) (string, error)
	// GetIndexRecord retrieves index record entry by ID
	GetIndexRecord(ID string) (IndexRecord, error)
	// UpdateIndexRecord updates index record
	UpdateIndexRecord(record IndexRecord) error
	// DeleteIndexRecord deletes index record by ID
	DeleteIndexRecord(ID string) error
	// QueryIndexRecords lists query matching index record entries
	QueryIndexRecords(query IndexRecordQuery) (QueryResult[IndexRecord, string], error)

	// Search performs full text search across existing index records
	// the query string should be formed in accordance with the pgroonga manual
	// for the `&@~` operator (https://pgroonga.github.io/reference/operators/query-v2.html)
	Search(query SearchQuery) (QueryResult[SearchQueryResultItem, string], error)
}

ModelTx provides a transaction with some methods for accessing to the Model objects

type QueryResult

type QueryResult[T any, N any] struct {
	Items  []T
	NextID N
	Total  int64
}

type SearchQuery added in v0.7.0

type SearchQuery struct {
	IndexIDs []string
	Query    string // underlying search engine query
	Tags     Tags   // index tags
	Distinct *bool  // if true, returns at most 1 result per index
	FromID   string
	Limit    int
}

type SearchQueryResultItem added in v0.7.0

type SearchQueryResultItem struct {
	IndexRecord
	Score int
}

type SqlTestSuite

type SqlTestSuite struct {
	Dir string
	suite.Suite
	// contains filtered or unexported fields
}

SqlTestSuite struct used to wrap all related database connection stuff into one suite

func (*SqlTestSuite) AfterTest

func (s *SqlTestSuite) AfterTest(suiteName, testName string)

func (*SqlTestSuite) BeforeTest

func (s *SqlTestSuite) BeforeTest(suiteName, testName string)

func (*SqlTestSuite) GetDb

func (s *SqlTestSuite) GetDb() Db

func (*SqlTestSuite) SetupSuite

func (s *SqlTestSuite) SetupSuite()

func (*SqlTestSuite) TearDownSuite

func (s *SqlTestSuite) TearDownSuite()

type Tags added in v0.5.0

type Tags map[string]string

func (*Tags) Scan added in v0.5.0

func (t *Tags) Scan(value any) error

func (Tags) Value added in v0.5.0

func (t Tags) Value() (value driver.Value, err error)

type Tx

type Tx interface {
	// MustBegin starts the transaction
	MustBegin()
	// MustBeginSerializable starts new transaction with Serializable isolation level
	MustBeginSerializable(ctx context.Context)
	// Commit commits the changes made within the transaction
	Commit() error
	// Rollback rolls the transaction back
	Rollback() error
	// ExecScript allows to execute the sql statements from the file provided
	ExecScript(sqlScript string) error
}

Tx interface describes an abstract DB transaction.

type Type added in v0.5.0

type Type string
const (
	DTypeNumber Type = "number"
	DTypeString Type = "string"
)

func DType added in v0.5.0

func DType(c Component) Type

type Vector added in v0.5.0

type Vector []Component

func NewVector added in v0.5.0

func NewVector(basis Basis, comps ...Component) (Vector, error)

func (*Vector) Scan added in v0.5.0

func (v *Vector) Scan(value any) error

func (Vector) Value added in v0.5.0

func (v Vector) Value() (value driver.Value, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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