Documentation
¶
Index ¶
- type ColumnDefinition
- type NewStoreOptions
- type SearchQuery
- type Store
- func (store *Store) Count(query SearchQuery) (int64, error)
- func (st *Store) Debug(debug bool)
- func (store *Store) DeleteWhereEquals(filters map[string]any) error
- func (store *Store) Drop() error
- func (st *Store) EnableDebug(debug bool)
- func (store *Store) Insert(data map[string]any) error
- func (store *Store) InsertMany(data []map[string]any) error
- func (st *Store) MigrateDown(ctx context.Context, tx ...*sql.Tx) error
- func (st *Store) MigrateUp(ctx context.Context, tx ...*sql.Tx) error
- func (store *Store) Search(query SearchQuery) ([]map[string]any, error)
- func (store *Store) Truncate() error
- func (store *Store) Upsert(data map[string]any, conflictColumns []string) error
- func (store *Store) UpsertWhereEquals(filters map[string]any, data map[string]any) error
- type StoreInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColumnDefinition ¶ added in v1.1.0
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) DeleteWhereEquals ¶ added in v0.4.0
DeleteWhereEquals deletes rows matching all equality filters. Example: DeleteWhereEquals(map[string]any{"record_id": id, "status": "draft"})
func (*Store) EnableDebug ¶
EnableDebug - enables the debug option
func (*Store) MigrateDown ¶ added in v1.0.0
MigrateDown drops the index table
func (*Store) Upsert ¶ added in v0.4.0
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
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