persistence

package
v0.63.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func Count added in v0.53.0

func Count(ctx context.Context, q sqlx.QueryerContext, query string, params ...any) (int64, error)

func MapError added in v0.51.0

func MapError(err error) error

func MapKeywordsToListFn added in v0.58.0

func MapKeywordsToListFn(startMark, endMark string) func(item SearchQueryResultItem) SearchQueryResultItem

func Scan added in v0.53.0

func Scan[T any](rows *sqlx.Rows) (T, error)

func ScanRows added in v0.51.0

func ScanRows[T any](rows *sqlx.Rows) ([]T, error)

func ScanRowsQueryResult added in v0.51.0

func ScanRowsQueryResult[T any](rows *sqlx.Rows) ([]T, error)

func ScanRowsQueryResultAndMap added in v0.51.0

func ScanRowsQueryResultAndMap[T, K any](rows *sqlx.Rows, mapFn func(entity T) K) ([]K, error)

Types

type Basis added in v0.5.0

type Basis json.RawMessage

type Db

type Db interface {
	// NewModelTx creates new ModelTx object
	NewModelTx(ctx context.Context) ModelTx
	// NewTx creates Tx object
	NewTx(ctx context.Context) Tx
}

Db interface exposes

type DbConfig added in v0.51.0

type DbConfig struct {
	Host     string
	Port     string
	User     string
	Password string
	DbName   string
	SslMode  string
}

func (DbConfig) DataSourceFull added in v0.51.0

func (ds DbConfig) DataSourceFull() string

func (DbConfig) DataSourceNoDb added in v0.51.0

func (ds DbConfig) DataSourceNoDb() string

type DbContainer added in v0.53.0

type DbContainer interface {
	io.Closer
	DbConfig() DbConfig
}

func NewNilDbContainer added in v0.53.0

func NewNilDbContainer(opts ...DbOption) (DbContainer, error)

func NewPgDbContainer added in v0.53.0

func NewPgDbContainer(ctx context.Context, image string, opts ...DbOption) (DbContainer, error)

NewPgDbContainer runs pg database in a docker container.

type DbOption added in v0.51.0

type DbOption func(cfg *DbConfig)

func WithDbName added in v0.51.0

func WithDbName(dbName string) DbOption

func WithHost added in v0.51.0

func WithHost(host string) DbOption

func WithPassword added in v0.61.0

func WithPassword(password string) DbOption

func WithPort added in v0.51.0

func WithPort(port string) DbOption

func WithSslMode added in v0.61.0

func WithSslMode(sslMode string) DbOption

func WithUser added in v0.61.0

func WithUser(user string) DbOption

type Format added in v0.4.0

type Format struct {
	ID        string    `db:"id"`
	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 IndexRecordID added in v0.11.0

type IndexRecordID struct {
	IndexID  string `json:"index_id"`
	RecordID string `json:"record_id"`
}

func (*IndexRecordID) Decode added in v0.11.0

func (id *IndexRecordID) Decode(s string) error

func (IndexRecordID) Encode added in v0.11.0

func (id IndexRecordID) Encode() string

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) (Format, error)
	// GetFormat retrieves format entry by ID
	GetFormat(ID string) (Format, error)
	// DeleteFormat deletes format entry by ID (only if not referenced)
	DeleteFormat(ID string) error
	// ListFormats lists all the existing format entries
	ListFormats() ([]Format, error)

	// CreateIndex creates index entry based on source ID
	CreateIndex(index Index) (Index, 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)

	// UpsertIndexRecords creates or updates index record entries
	UpsertIndexRecords(records ...IndexRecord) error
	// GetIndexRecord retrieves index record entry
	GetIndexRecord(ID, indexID string) (IndexRecord, error)
	// UpdateIndexRecord updates index record
	UpdateIndexRecord(record IndexRecord) error
	// DeleteIndexRecords deletes index record entries
	DeleteIndexRecords(records ...IndexRecord) (int, error)
	// QueryIndexRecords lists query matching index record entries
	QueryIndexRecords(query IndexRecordQuery) (QueryResult[IndexRecord, string], error)

	// Search performs search across existing index records
	// the query string should be formed in accordance with the query
	// language of the underlying search engine
	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
	OrderByScore bool   // if true, sorts the result by the result relevancy score
	FromID       string
	Offset       int
	Limit        int
}

type SearchQueryResultItem added in v0.7.0

type SearchQueryResultItem struct {
	IndexRecord
	MatchedKeywordsList []string // mapped manually after filling the MatchedKeywords
	MatchedKeywords     string   `db:"matched_keywords"`
	Score               float32  `db:"score"`
}

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()
	// 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 Vector added in v0.5.0

type Vector json.RawMessage

Directories

Path Synopsis
fts

Jump to

Keyboard shortcuts

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