indexstore

package module
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Index Store

tests Go Report Card PkgGoDev

Package for creating indexes to optimize query performance and scalability

License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0). You can find a copy of the license at https://www.gnu.org/licenses/agpl-3.0.en.html

For commercial use, please use my contact page to obtain a commercial license.

Introduction

In database design, creating separate tables specifically for indexing and searching purposes is a technique often employed to optimize query performance and scalability. This approach, while requiring additional database overhead, can significantly improve the speed and efficiency of complex search operations.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnDefinition added in v1.1.0

type ColumnDefinition struct {
	Name       string
	Type       string
	PrimaryKey bool
}

ColumnDefinition defines a column for the index table

type NewStoreOptions

type NewStoreOptions struct {
	TableName          string
	DB                 *sql.DB
	AutomigrateEnabled bool
	DebugEnabled       bool
	Columns            []ColumnDefinition
}

NewStoreOptions define the options for creating a new index store

type SearchQuery

type SearchQuery struct {
	Where     map[string]any
	Offset    int
	Limit     int
	SortOrder string
	OrderBy   string
}

SearchQuery defines the query parameters for searching the index store

type Store

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

Store is the index store

func NewStore

func NewStore(opts NewStoreOptions) (*Store, error)

NewStore creates a new index store

func (*Store) Count

func (store *Store) Count(query SearchQuery) (int64, error)

func (*Store) Debug added in v0.4.0

func (st *Store) Debug(debug bool)

Debug enables or disables SQL logging (alias of EnableDebug)

func (*Store) DeleteWhereEquals added in v0.4.0

func (store *Store) DeleteWhereEquals(filters map[string]any) error

DeleteWhereEquals deletes rows matching all equality filters. Example: DeleteWhereEquals(map[string]any{"record_id": id, "status": "draft"})

func (*Store) Drop

func (store *Store) Drop() error

func (*Store) EnableDebug

func (st *Store) EnableDebug(debug bool)

EnableDebug - enables the debug option

func (*Store) Insert

func (store *Store) Insert(data map[string]any) error

func (*Store) InsertMany

func (store *Store) InsertMany(data []map[string]any) error

func (*Store) MigrateDown added in v1.0.0

func (st *Store) MigrateDown(ctx context.Context, tx ...*sql.Tx) error

MigrateDown drops the index table

func (*Store) MigrateUp added in v1.0.0

func (st *Store) MigrateUp(ctx context.Context, tx ...*sql.Tx) error

MigrateUp creates the index table

func (*Store) Search

func (store *Store) Search(query SearchQuery) ([]map[string]any, error)

func (*Store) Truncate

func (store *Store) Truncate() error

func (*Store) Upsert added in v0.4.0

func (store *Store) Upsert(data map[string]any, conflictColumns []string) error

Upsert keeps backward compatibility with the original interface by delegating to UpsertWhereEquals using the provided conflict columns

func (*Store) UpsertWhereEquals added in v0.4.0

func (store *Store) UpsertWhereEquals(filters map[string]any, data map[string]any) error

UpsertWhereEquals performs an upsert using equality filters as the match criteria. It updates non-filter columns when a match exists, otherwise inserts a new row composed from filters and data (data keys override filters on conflict).

type StoreInterface

type StoreInterface interface {
	// MigrateDown drops the index table
	MigrateDown(ctx context.Context, tx ...*sql.Tx) error

	// MigrateUp creates the index table
	MigrateUp(ctx context.Context, tx ...*sql.Tx) error

	// Debug enables or disables SQL logging
	Debug(debug bool)

	// Insert inserts a record into the index table
	Insert(data map[string]any) error

	// InsertMany inserts multiple records into the index table
	InsertMany(data []map[string]any) error

	// Upsert inserts or updates a record based on the specified conflict columns (e.g., unique keys)
	// When a conflict occurs, columns present in data (except the conflict columns) will be updated
	Upsert(data map[string]any, conflictColumns []string) error

	// DeleteWhereEquals deletes rows matching all equality filters provided
	// Example: DeleteWhereEquals(map[string]any{"record_id": id, "status": "draft"})
	DeleteWhereEquals(filters map[string]any) error

	// UpsertWhereEquals performs an upsert using equality filters as the match criteria.
	// It updates non-filter columns when a match exists, otherwise inserts a new row
	// composed from filters and data (data keys override filters on conflict).
	UpsertWhereEquals(filters map[string]any, data map[string]any) error

	// Search queries the index table
	Search(query SearchQuery) ([]map[string]any, error)

	// Drop removes the index table
	Drop() error

	// Truncate removes all records from the index table
	Truncate() error
}

StoreInterface is the interface for the index store

Jump to

Keyboard shortcuts

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