Documentation
¶
Overview ¶
Package mongreldb is the pure-Go HTTP client for MongrelDB.
It talks to a running mongreldb-server daemon's JSON API over the standard library net/http client - no cgo, no external dependencies. The surface mirrors the MongrelDB PHP client: typed CRUD, a fluent query builder that pushes conditions down to the engine's native indexes, idempotent batch transactions, full SQL access, and schema introspection.
Connect with NewClient and a base URL:
db := mongreldb.NewClient("http://127.0.0.1:8453")
ok, _ := db.Health(context.Background())
Index ¶
- Constants
- Variables
- func BuildRetrieveTextRequest(table string, embeddingColumn uint16, text string, opts RetrieveTextOptions) (map[string]any, error)
- type AnnIndexOptions
- type Cells
- type Client
- func (c *Client) BaseURL() string
- func (c *Client) Begin() *Transaction
- func (c *Client) CancelQuery(ctx context.Context, queryID string) (map[string]any, error)
- func (c *Client) CommitTxn(ctx context.Context, ops []map[string]any, idempotencyKey string) ([]map[string]any, error)
- func (c *Client) Compact(ctx context.Context) (map[string]any, error)
- func (c *Client) CompactTable(ctx context.Context, table string) (map[string]any, error)
- func (c *Client) Count(ctx context.Context, table string) (int64, error)
- func (c *Client) CreateTable(ctx context.Context, name string, columns []Column, ...) (int64, error)
- func (c *Client) CreateTableWithOptions(ctx context.Context, name string, columns []Column, options CreateTableOptions) (int64, error)
- func (c *Client) Delete(ctx context.Context, table string, rowID int64) error
- func (c *Client) DeleteByPK(ctx context.Context, table string, pk any) error
- func (c *Client) DropTable(ctx context.Context, name string) error
- func (c *Client) EarliestRetainedEpoch(ctx context.Context) (uint64, error)
- func (c *Client) Health(ctx context.Context) (bool, error)
- func (c *Client) HistoryRetention(ctx context.Context) (HistoryRetention, error)
- func (c *Client) HistoryRetentionEpochs(ctx context.Context) (uint64, error)
- func (c *Client) Put(ctx context.Context, table string, cells Cells, idempotencyKey string) (map[string]any, error)
- func (c *Client) Query(table string) *QueryBuilder
- func (c *Client) QueryStatus(ctx context.Context, queryID string) (*QueryStatus, error)
- func (c *Client) RetrieveText(ctx context.Context, table string, embeddingColumn uint16, text string, ...) (*TextRetrieveResult, error)
- func (c *Client) SQL(ctx context.Context, sql string) ([]map[string]any, error)
- func (c *Client) Schema(ctx context.Context) (map[string]map[string]any, error)
- func (c *Client) SchemaFor(ctx context.Context, table string) (map[string]any, error)
- func (c *Client) Search(table string) *SearchBuilder
- func (c *Client) SetHistoryRetentionEpochs(ctx context.Context, epochs uint64) (HistoryRetention, error)
- func (c *Client) TableNames(ctx context.Context) ([]string, error)
- func (c *Client) Upsert(ctx context.Context, table string, cells Cells, updateCells Cells, ...) (map[string]any, error)
- type Column
- type CommitHlc
- type CreateTableOptions
- type DiskANNOptions
- type DurableOutcome
- type HistoryRetention
- type Index
- type IndexOptions
- type LearnedRangeIndexOptions
- type MinHashIndexOptions
- type Option
- type QueryBuilder
- func (q *QueryBuilder) Build() map[string]any
- func (q *QueryBuilder) Execute(ctx context.Context) ([]map[string]any, error)
- func (q *QueryBuilder) Limit(limit int64) *QueryBuilder
- func (q *QueryBuilder) Offset(offset int64) *QueryBuilder
- func (q *QueryBuilder) Projection(columnIDs []int64) *QueryBuilder
- func (q *QueryBuilder) Truncated() bool
- func (q *QueryBuilder) Where(condType string, params map[string]any) *QueryBuilder
- type QueryStatus
- type ResponseError
- type RetrieveTextOptions
- type SearchBuilder
- func (s *SearchBuilder) AnnRetriever(name string, columnID int64, query []float64, k int, weight float64) *SearchBuilder
- func (s *SearchBuilder) Build() (map[string]any, error)
- func (s *SearchBuilder) Cursor(cursor string) *SearchBuilder
- func (s *SearchBuilder) ExactRerank(embeddingColumn int64, query []float64, metric string, candidateLimit int, ...) *SearchBuilder
- func (s *SearchBuilder) Execute(ctx context.Context) (*SearchResult, error)
- func (s *SearchBuilder) Explain(on bool) *SearchBuilder
- func (s *SearchBuilder) Fusion(constant uint32) *SearchBuilder
- func (s *SearchBuilder) Limit(limit int) *SearchBuilder
- func (s *SearchBuilder) MinHashRetriever(name string, columnID int64, members []string, k int, weight float64) *SearchBuilder
- func (s *SearchBuilder) Must(condType string, params map[string]any) *SearchBuilder
- func (s *SearchBuilder) Projection(columnIDs []int64) *SearchBuilder
- func (s *SearchBuilder) SparseRetriever(name string, columnID int64, terms [][2]float64, k int, weight float64) *SearchBuilder
- type SearchResult
- type TextRetrieveResult
- type Transaction
- func (t *Transaction) Commit(ctx context.Context, idempotencyKey string) ([]map[string]any, error)
- func (t *Transaction) Count() int
- func (t *Transaction) Delete(table string, rowID int64) *Transaction
- func (t *Transaction) DeleteByPK(table string, pk any) *Transaction
- func (t *Transaction) Put(table string, cells Cells, returning bool) *Transaction
- func (t *Transaction) Rollback() error
- func (t *Transaction) Upsert(table string, cells Cells, updateCells Cells, returning bool) *Transaction
Constants ¶
const DefaultBaseURL = "http://127.0.0.1:8453"
DefaultBaseURL is the daemon address used when none is supplied.
const MaxResponseBytes int64 = 268435456
MaxResponseBytes caps the size of a response body read from the daemon (256 MB). Bodies larger than this are aborted with a wrapped ErrQuery to guard client memory against a malicious or buggy server.
const Version = "0.67.1"
Version is the client library version (aligned with the MongrelDB train).
Variables ¶
var ( // ErrNotFound is returned for HTTP 404 responses (missing table, schema, etc.). ErrNotFound = errors.New("mongreldb: not found") // ErrConflict is returned for HTTP 409 responses (unique, foreign key, check, // or trigger constraint violations). ErrConflict = errors.New("mongreldb: constraint conflict") // ErrAuth is returned for HTTP 401 or 403 responses (bad or missing credentials). ErrAuth = errors.New("mongreldb: authentication failed") // ErrQuery is returned for HTTP 400 or 5xx responses and for any other // request-level failure not covered by the more specific sentinels. ErrQuery = errors.New("mongreldb: query failed") )
Typed client errors. Each sentinel corresponds to a class of HTTP status returned by the daemon. Use errors.Is to discriminate:
switch {
case errors.Is(err, mongreldb.ErrNotFound): ...
case errors.Is(err, mongreldb.ErrConflict): ...
case errors.Is(err, mongreldb.ErrAuth): ...
case errors.Is(err, mongreldb.ErrQuery): ...
}
var ErrTxnCommitted = errors.New("mongreldb: transaction already committed")
ErrTxnCommitted is returned when Transaction.Commit or Transaction.Rollback is called on a transaction that has already been committed.
Functions ¶
func BuildRetrieveTextRequest ¶ added in v0.64.2
func BuildRetrieveTextRequest(table string, embeddingColumn uint16, text string, opts RetrieveTextOptions) (map[string]any, error)
BuildRetrieveTextRequest returns the JSON body for POST /kit/retrieve_text.
Types ¶
type AnnIndexOptions ¶ added in v0.62.0
type AnnIndexOptions struct {
M int `json:"m,omitempty"`
EFConstruction int `json:"ef_construction,omitempty"`
EFSearch int `json:"ef_search,omitempty"`
Quantization string `json:"quantization,omitempty"`
Algorithm string `json:"algorithm,omitempty"`
DiskANN *DiskANNOptions `json:"diskann,omitempty"`
}
type Cells ¶
Cells is a column-id-to-value map. The client flattens it to the server's on-wire [col_id, value, col_id, value, ...] array before sending. Pair order is irrelevant - each value is preceded by its own column id.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the MongrelDB HTTP client. Create one with NewClient and use its methods for health, table management, CRUD, query, SQL, and schema. A Client is safe for concurrent use by multiple goroutines once configured.
func NewClient ¶
NewClient returns a Client for the daemon at url. If url is empty, DefaultBaseURL is used. Apply Option values for auth, timeouts, or a custom *http.Client.
func (*Client) CancelQuery ¶ added in v0.64.2
CancelQuery requests cancellation of a running SQL query.
func (*Client) CommitTxn ¶
func (c *Client) CommitTxn(ctx context.Context, ops []map[string]any, idempotencyKey string) ([]map[string]any, error)
CommitTxn sends a batch of staged operations atomically. Exposed for the Transaction type; returns the per-operation results array.
func (*Client) CompactTable ¶
CompactTable merges sorted runs for a single table.
func (*Client) CreateTable ¶
func (c *Client) CreateTable(ctx context.Context, name string, columns []Column, constraints ...map[string]any) (int64, error)
CreateTable creates a table named name with the given columns and returns the assigned table id. Pass at most one constraints map to attach engine constraints such as {"checks": [...]}.
func (*Client) CreateTableWithOptions ¶ added in v0.62.0
func (c *Client) CreateTableWithOptions(ctx context.Context, name string, columns []Column, options CreateTableOptions) (int64, error)
CreateTableWithOptions creates a table with constraints and full index definitions.
func (*Client) DeleteByPK ¶
DeleteByPK removes a row by its primary-key value.
func (*Client) EarliestRetainedEpoch ¶
EarliestRetainedEpoch returns the earliest epoch still available for time-travel queries. Increasing the retention window cannot move this value backward.
func (*Client) Health ¶
Health reports whether the daemon is reachable and healthy. A network failure returns (false, nil) so callers can treat "unhealthy" uniformly; context cancellation still propagates as an error.
func (*Client) HistoryRetention ¶
func (c *Client) HistoryRetention(ctx context.Context) (HistoryRetention, error)
HistoryRetention returns the current retention state from GET /history/retention.
func (*Client) HistoryRetentionEpochs ¶
HistoryRetentionEpochs returns the current history_retention_epochs value.
func (*Client) Put ¶
func (c *Client) Put(ctx context.Context, table string, cells Cells, idempotencyKey string) (map[string]any, error)
Put inserts a row. idempotencyKey, if non-empty, makes the commit safe to retry - the daemon returns the original result on duplicate commits.
Returns the per-operation result object (the first element of the server's results array).
func (*Client) Query ¶
func (c *Client) Query(table string) *QueryBuilder
Query starts a fluent QueryBuilder against table.
func (*Client) QueryStatus ¶ added in v0.64.2
QueryStatus fetches retained SQL execution status for durable recovery.
func (*Client) RetrieveText ¶ added in v0.64.2
func (c *Client) RetrieveText(ctx context.Context, table string, embeddingColumn uint16, text string, opts RetrieveTextOptions) (*TextRetrieveResult, error)
RetrieveText embeds text under the active semantic identity for embeddingColumn and runs ANN retrieval (POST /kit/retrieve_text).
func (*Client) SQL ¶
SQL executes a SQL statement via the /sql endpoint, requesting JSON output. The server returns a JSON array of row objects keyed by column name, e.g. [{"id": 1, "name": "Alice", "score": 95.5}]. For statements that yield no rows (DDL/DML), the body is empty and an empty slice is returned.
Integers in each row are decoded as json.Number (not float64) via encoding/json.Decoder.UseNumber, preserving precision for large table ids or counts that would otherwise lose accuracy in a float64.
func (*Client) Search ¶ added in v0.62.0
func (c *Client) Search(table string) *SearchBuilder
Search starts a hybrid search against table.
func (*Client) SetHistoryRetentionEpochs ¶
func (c *Client) SetHistoryRetentionEpochs(ctx context.Context, epochs uint64) (HistoryRetention, error)
SetHistoryRetentionEpochs sets the database-wide history retention window to epochs and returns the post-update retention state. The call maps to PUT /history/retention with body {"history_retention_epochs": epochs}.
func (*Client) TableNames ¶
TableNames lists all table names in the database.
func (*Client) Upsert ¶
func (c *Client) Upsert(ctx context.Context, table string, cells Cells, updateCells Cells, idempotencyKey string) (map[string]any, error)
Upsert inserts a row, or updates it on a primary-key conflict. updateCells, when non-nil, supplies the values written on conflict (nil means DO NOTHING).
type Column ¶
type Column struct {
ID int64 `json:"id"`
Name string `json:"name"`
Type string `json:"ty"`
PrimaryKey bool `json:"primary_key"`
Nullable bool `json:"nullable"`
EnumVariants []string `json:"enum_variants,omitempty"`
DefaultValue *string `json:"default_value,omitempty"`
// DefaultValueJSON preserves a static JSON scalar. It takes precedence over
// the legacy string-only DefaultValue field.
DefaultValueJSON any `json:"-"`
DefaultExpr *string `json:"default_expr,omitempty"`
// EmbeddingSource is the portable model/source descriptor for embedding columns.
EmbeddingSource any `json:"embedding_source,omitempty"`
}
Column describes one column in a CREATE TABLE request. The struct is sent to the server verbatim; the JSON tags mirror the daemon's table-create extractor. Optional fields are emitted only when set.
func (Column) MarshalJSON ¶
type CommitHlc ¶ added in v0.64.2
type CommitHlc struct {
PhysicalMicros uint64 `json:"physical_micros"`
Logical uint32 `json:"logical"`
NodeTiebreaker uint32 `json:"node_tiebreaker"`
}
CommitHlc is the structural hybrid logical clock from durable recovery (0.64+).
type CreateTableOptions ¶ added in v0.62.0
type DiskANNOptions ¶ added in v0.63.0
type DurableOutcome ¶ added in v0.64.2
type DurableOutcome struct {
Committed *bool `json:"committed"`
CommittedStatements *int `json:"committed_statements"`
LastCommitEpoch *uint64 `json:"last_commit_epoch"`
LastCommitEpochText *string `json:"last_commit_epoch_text"`
LastCommitHlc *CommitHlc `json:"last_commit_hlc"`
FirstCommitStatementIndex *int `json:"first_commit_statement_index"`
LastCommitStatementIndex *int `json:"last_commit_statement_index"`
CompletedStatements *int `json:"completed_statements"`
StatementIndex *int `json:"statement_index"`
Serialization string `json:"serialization"`
SerializationState string `json:"serialization_state"`
TerminalState *string `json:"terminal_state"`
}
DurableOutcome is the nested durable recovery payload on query status/cancel responses (parity with the server DurableOutcome / outcome JSON object).
type HistoryRetention ¶
type HistoryRetention struct {
HistoryRetentionEpochs uint64 `json:"history_retention_epochs"`
EarliestRetainedEpoch uint64 `json:"earliest_retained_epoch"`
}
HistoryRetention is the response shape for the /history/retention endpoint.
type Index ¶ added in v0.62.0
type Index struct {
Name string `json:"name"`
ColumnID int64 `json:"column_id"`
Kind string `json:"kind"`
Predicate string `json:"predicate,omitempty"`
Options IndexOptions `json:"options,omitempty"`
}
Index describes one of MongrelDB's six public secondary index kinds.
type IndexOptions ¶ added in v0.62.0
type IndexOptions struct {
ANN *AnnIndexOptions `json:"ann,omitempty"`
MinHash *MinHashIndexOptions `json:"minhash,omitempty"`
LearnedRange *LearnedRangeIndexOptions `json:"learned_range,omitempty"`
}
type LearnedRangeIndexOptions ¶ added in v0.62.0
type LearnedRangeIndexOptions struct {
Epsilon int `json:"epsilon,omitempty"`
}
type MinHashIndexOptions ¶ added in v0.62.0
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithBasicAuth ¶
WithBasicAuth authenticates requests with HTTP Basic credentials (--auth-users mode). Ignored if WithToken is also supplied.
func WithHTTPClient ¶
WithHTTPClient installs a custom *http.Client (e.g. with a custom transport). Overrides WithTimeout. Passing nil is a no-op (keeps the default client).
func WithTimeout ¶
WithTimeout sets the per-request timeout by configuring the underlying *http.Client. Overrides WithHTTPClient if called after it.
type QueryBuilder ¶
type QueryBuilder struct {
// contains filtered or unexported fields
}
QueryBuilder builds a request for the daemon's /kit/query endpoint, where conditions push down to the engine's specialized indexes for sub-millisecond lookups.
Condition parameters accept friendly aliases that are translated to the server's exact on-wire keys before sending (see QueryBuilder.Where):
- column -> column_id
- min / max -> lo / hi
- min_inclusive -> lo_inclusive
- max_inclusive -> hi_inclusive
The server's canonical keys are accepted directly too.
func (*QueryBuilder) Build ¶
func (q *QueryBuilder) Build() map[string]any
Build returns the request payload that will be sent to /kit/query.
func (*QueryBuilder) Execute ¶
Execute runs the query and returns the matching rows. It also records whether the result was truncated by the QueryBuilder.Limit; check it with QueryBuilder.Truncated.
func (*QueryBuilder) Limit ¶
func (q *QueryBuilder) Limit(limit int64) *QueryBuilder
Limit caps the number of rows returned.
func (*QueryBuilder) Offset ¶
func (q *QueryBuilder) Offset(offset int64) *QueryBuilder
Offset skips matching rows before applying the limit.
func (*QueryBuilder) Projection ¶
func (q *QueryBuilder) Projection(columnIDs []int64) *QueryBuilder
Projection sets the column ids to return (nil means all columns).
func (*QueryBuilder) Truncated ¶
func (q *QueryBuilder) Truncated() bool
Truncated reports whether the most recent QueryBuilder.Execute result was capped by the query limit. It returns false until Execute has been called.
func (*QueryBuilder) Where ¶
func (q *QueryBuilder) Where(condType string, params map[string]any) *QueryBuilder
Where adds a native condition. Available condition types include:
- pk exact primary-key match ({"value": pk})
- bitmap_eq equality on a bitmap-indexed column
- bitmap_in IN predicate on a bitmap-indexed column
- range integer range predicate (lo/hi, inclusive)
- range_f64 float range predicate (lo/hi + lo_inclusive/hi_inclusive)
- is_null null check
- is_not_null non-null check
- fm_contains full-text substring search (FM-index)
- fm_contains_all multiple substring patterns (all must match)
- ann dense vector similarity search (HNSW)
- sparse_match sparse vector match
- min_hash_similar MinHash similarity search
Conditions are AND-ed. The builder returns itself for chaining.
type QueryStatus ¶ added in v0.64.2
type QueryStatus struct {
QueryID string `json:"query_id"`
Status string `json:"status"`
State string `json:"state"`
ServerState string `json:"server_state"`
TerminalState *string `json:"terminal_state"`
Operation string `json:"operation"`
Committed *bool `json:"committed"`
CommittedStatements *int `json:"committed_statements"`
LastCommitEpoch *uint64 `json:"last_commit_epoch"`
LastCommitEpochText *string `json:"last_commit_epoch_text"`
LastCommitHlc *CommitHlc `json:"last_commit_hlc"`
FirstCommitStmtIdx *int `json:"first_commit_statement_index"`
LastCommitStmtIdx *int `json:"last_commit_statement_index"`
CompletedStatements *int `json:"completed_statements"`
StatementIndex *int `json:"statement_index"`
CancelOutcome *string `json:"cancel_outcome"`
CancellationReason string `json:"cancellation_reason"`
Retryable bool `json:"retryable"`
Outcome DurableOutcome `json:"outcome"`
Durable *DurableOutcome `json:"durable"`
TerminalError json.RawMessage `json:"terminal_error"`
Trace json.RawMessage `json:"trace"`
}
QueryStatus is GET /queries/{query_id} (SQL control / durable recovery).
func ParseQueryStatusJSON ¶ added in v0.64.2
func ParseQueryStatusJSON(data []byte) (*QueryStatus, error)
ParseQueryStatusJSON decodes a query-status body (test/helpers).
func (*QueryStatus) CommitHlc ¶ added in v0.64.2
func (s *QueryStatus) CommitHlc() *CommitHlc
CommitHlc returns the authoritative HLC from nested durable / outcome / top-level.
func (*QueryStatus) SerializationState ¶ added in v0.64.2
func (s *QueryStatus) SerializationState() string
SerializationState prefers nested durable/outcome serialization_state, then serialization.
type ResponseError ¶
type ResponseError struct {
// Status is the HTTP status code returned by the daemon.
Status int
// Message is the human-readable error message.
Message string
// Code is the server's structured error code, when present (e.g.
// "UNIQUE_VIOLATION", "FK_VIOLATION").
Code string
// OpIndex is the offending operation index within a transaction, when the
// server reports one (constraint violations during commit).
OpIndex *int
// contains filtered or unexported fields
}
ResponseError carries the HTTP status code and the server's decoded error envelope for a failed request. It wraps the relevant sentinel (ErrNotFound, ErrConflict, ErrAuth, or ErrQuery) so that both errors.Is(err, mongreldb.ErrXxx) and a type assertion (var re *mongreldb.ResponseError) work.
func (*ResponseError) Error ¶
func (e *ResponseError) Error() string
Error implements the error interface.
func (*ResponseError) Unwrap ¶
func (e *ResponseError) Unwrap() error
Unwrap allows errors.Is to match the wrapped sentinel.
type RetrieveTextOptions ¶ added in v0.64.2
RetrieveTextOptions configures text → embed → ANN retrieve.
type SearchBuilder ¶ added in v0.62.0
type SearchBuilder struct {
// contains filtered or unexported fields
}
SearchBuilder builds a request for the daemon's POST /kit/search endpoint: multi-retriever hybrid search with reciprocal-rank fusion and optional exact-vector rerank. This is the scored counterpart to QueryBuilder (which only AND-s conditions via /kit/query).
Wire format matches the server's KitSearchRequest (flattened retrievers, snake_case fusion/rerank tags) so HTTP language clients stay interchangeable.
func (*SearchBuilder) AnnRetriever ¶ added in v0.62.0
func (s *SearchBuilder) AnnRetriever(name string, columnID int64, query []float64, k int, weight float64) *SearchBuilder
AnnRetriever adds a dense ANN retriever (HNSW) over columnID. Wire: {"name","weight","ann":{"column_id","query","k"}} (flattened).
func (*SearchBuilder) Build ¶ added in v0.62.0
func (s *SearchBuilder) Build() (map[string]any, error)
Build returns the JSON body for POST /kit/search.
func (*SearchBuilder) Cursor ¶ added in v0.62.0
func (s *SearchBuilder) Cursor(cursor string) *SearchBuilder
Cursor continues a previous page from next_cursor.
func (*SearchBuilder) ExactRerank ¶ added in v0.62.0
func (s *SearchBuilder) ExactRerank(embeddingColumn int64, query []float64, metric string, candidateLimit int, weight float64) *SearchBuilder
ExactRerank enables exact float-vector rerank after fusion. metric is "cosine", "dot_product", or "euclidean".
func (*SearchBuilder) Execute ¶ added in v0.62.0
func (s *SearchBuilder) Execute(ctx context.Context) (*SearchResult, error)
Execute runs the hybrid search.
func (*SearchBuilder) Explain ¶ added in v0.62.0
func (s *SearchBuilder) Explain(on bool) *SearchBuilder
Explain requests server-side trace metadata when supported.
func (*SearchBuilder) Fusion ¶ added in v0.62.0
func (s *SearchBuilder) Fusion(constant uint32) *SearchBuilder
Fusion sets reciprocal-rank fusion (the only supported kind today).
func (*SearchBuilder) Limit ¶ added in v0.62.0
func (s *SearchBuilder) Limit(limit int) *SearchBuilder
Limit caps the number of final hits (default 10).
func (*SearchBuilder) MinHashRetriever ¶ added in v0.62.0
func (s *SearchBuilder) MinHashRetriever(name string, columnID int64, members []string, k int, weight float64) *SearchBuilder
MinHashRetriever adds a MinHash set-similarity retriever.
func (*SearchBuilder) Must ¶ added in v0.62.0
func (s *SearchBuilder) Must(condType string, params map[string]any) *SearchBuilder
Must adds a hard filter condition (same shapes as QueryBuilder.Where). Conditions are AND-ed against candidate rows.
func (*SearchBuilder) Projection ¶ added in v0.62.0
func (s *SearchBuilder) Projection(columnIDs []int64) *SearchBuilder
Projection restricts returned cell column ids.
func (*SearchBuilder) SparseRetriever ¶ added in v0.62.0
func (s *SearchBuilder) SparseRetriever(name string, columnID int64, terms [][2]float64, k int, weight float64) *SearchBuilder
SparseRetriever adds a sparse (SPLADE-style) retriever. terms are [token_id, weight] pairs.
type SearchResult ¶ added in v0.62.0
SearchResult is the decoded /kit/search response.
type TextRetrieveResult ¶ added in v0.64.2
type TextRetrieveResult struct {
Hits []map[string]any `json:"hits"`
Provenance map[string]any `json:"provenance"`
}
TextRetrieveResult is POST /kit/retrieve_text (0.64+).
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction stages operations locally and commits them atomically in a single /kit/txn request. The engine enforces unique, foreign-key, check, and trigger constraints at commit time; on any violation all operations roll back and Commit returns a ResponseError wrapping ErrConflict.
A Transaction is not safe to reuse after Commit; create a new one with Client.Begin.
func (*Transaction) Commit ¶
Commit sends all staged operations atomically and returns the per-operation results. idempotencyKey, when non-empty, makes the commit safe to retry - the daemon returns the original response on duplicate commits.
Returns ErrTxnCommitted if called twice on the same transaction.
func (*Transaction) Count ¶
func (t *Transaction) Count() int
Count returns the number of staged operations.
func (*Transaction) Delete ¶
func (t *Transaction) Delete(table string, rowID int64) *Transaction
Delete stages a delete by the internal row id.
func (*Transaction) DeleteByPK ¶
func (t *Transaction) DeleteByPK(table string, pk any) *Transaction
DeleteByPK stages a delete by primary-key value.
func (*Transaction) Put ¶
func (t *Transaction) Put(table string, cells Cells, returning bool) *Transaction
Put stages an insert. returning, when true, asks the daemon to echo the row in the per-operation result.
func (*Transaction) Rollback ¶
func (t *Transaction) Rollback() error
Rollback discards all staged operations. Returns ErrTxnCommitted if the transaction was already committed.
func (*Transaction) Upsert ¶
func (t *Transaction) Upsert(table string, cells Cells, updateCells Cells, returning bool) *Transaction
Upsert stages an insert-or-update. updateCells, when non-nil, supplies the values written on a primary-key conflict (nil means DO NOTHING).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic_crud
command
Example: basic CRUD operations with the MongrelDB Go client.
|
Example: basic CRUD operations with the MongrelDB Go client. |
|
query_builder
command
Example: query builder conditions with the MongrelDB Go client.
|
Example: query builder conditions with the MongrelDB Go client. |
|
transactions
command
Example: atomic batch transactions with the MongrelDB Go client.
|
Example: atomic batch transactions with the MongrelDB Go client. |