Documentation
¶
Overview ¶
Package loomlog provides a Go library for reading, writing, and querying Loomlog (.lml) files.
Loomlog is a fast, line-oriented log format with data up front and metadata in a tiny trailer. It is append-friendly, human-diffable, and storage-agnostic.
File Format ¶
A loomlog file consists of:
- Magic line: # LOOMLOG1
- Record lines: id: <id>, len: <uint>, data: <token>
- Trailer separator: +++
- Trailer entries: rec: ts:<i64>, id:<id>, line:<u32>, off:<u64>, len:<u32>[, <key>:<value> ...]
Basic Usage ¶
Create a new file:
data, _ := loomlog.Create()
Insert records:
data, _ = loomlog.Insert(data, map[string]string{
"id": "msg-001",
"data": "hello-world",
}, map[string]string{
"user": "alice",
})
Query records:
results, _ := loomlog.Query(data, loomlog.QuerySpec{
Where: []loomlog.Pred{
{Key: "user", Op: "eq", Val: "alice"},
},
})
Update records:
data, _ = loomlog.Update(data, "msg-001", map[string]string{
"data": "new-payload",
})
Delete records:
data, _ = loomlog.Delete(data, "msg-001")
Error Handling ¶
All mutation and query functions return *ErrDetail for structured errors:
data, err := loomlog.Insert(data, record, extras)
if err != nil {
fmt.Printf("Error %s: %s\n", err.Code, err.Hint)
}
Performance ¶
Loomlog is optimized for append-heavy workloads:
- Appends add one record line and one trailer entry
- Queries read only the trailer to filter results
- Updates trigger partial trailer rebuild
- Same-size updates use a fast path
For more details, see https://github.com/popchatlabs/loomlog/blob/main/SPEC.md
Index ¶
- Variables
- func GetExtras(b []byte, id string) (Extras, *ErrDetail)
- type ErrDetail
- func CheckStructure(b []byte) *ErrDetail
- func Create() ([]byte, *ErrDetail)
- func Delete(b []byte, id string) ([]byte, *ErrDetail)
- func EncodeRecLine(ts int64, id string, line uint32, off uint64, length uint32, extras Extras) ([]byte, *ErrDetail)
- func EncodeRecordData(kv map[string]string) ([]byte, *ErrDetail)
- func FindIDs(b []byte, q QuerySpec) ([]string, *ErrDetail)
- func Insert(b []byte, lineKV map[string]string, extras Extras) ([]byte, *ErrDetail)
- func Parse(b []byte, opts *ParseOpts) (map[string]RecIndex, *ErrDetail)
- func Plan(b []byte, in PlanIn) (int64, int64, *ErrDetail)
- func Query(b []byte, q QuerySpec) ([]map[string]any, *ErrDetail)
- func QueryIter(b []byte, q QuerySpec, emit func(map[string]any) bool) *ErrDetail
- func RenderRows(rows []map[string]any, format ViewFormat, opts *RenderOpts, w io.Writer) *ErrDetail
- func RenderRowsStream(iter RowIterator, format ViewFormat, opts *RenderOpts, w io.Writer) *ErrDetail
- func Stats(b []byte) (int64, int, int64, *ErrDetail)
- func Update(b []byte, id string, newKV map[string]string) ([]byte, *ErrDetail)
- func UpdateExtras(b []byte, id string, extras Extras) ([]byte, *ErrDetail)
- func UpdateSameSize(b []byte, id string, newKV map[string]string) ([]byte, *ErrDetail)
- type Extras
- type Op
- type Order
- type ParseOpts
- type PlanIn
- type Pred
- type QuerySpec
- type RecIndex
- type RenderOpts
- type RowIterator
- type Select
- type ViewFormat
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNoMagic = errors.New("E_NO_MAGIC") ErrUnterminatedLastLine = errors.New("E_UNTERMINATED_LAST_LINE") ErrNoTrailer = errors.New("E_NO_TRAILER") ErrMultipleTrailers = errors.New("E_MULTIPLE_TRAILERS") ErrNoID = errors.New("E_NO_ID") ErrNoLen = errors.New("E_NO_LEN") ErrNoData = errors.New("E_NO_DATA") ErrDataNotLast = errors.New("E_DATA_NOT_LAST") ErrDataWS = errors.New("E_DATA_WS") ErrLenMismatch = errors.New("E_LEN_MISMATCH") ErrDupKey = errors.New("E_DUP_KEY") ErrDupID = errors.New("E_DUP_ID") ErrIDNotFound = errors.New("E_ID_NOT_FOUND") ErrTrailingComma = errors.New("E_TRAILING_COMMA") ErrRenderFormat = errors.New("E_RENDER_FORMAT") ErrRenderTarget = errors.New("E_RENDER_TARGET") )
Functions ¶
Types ¶
type ErrDetail ¶
func CheckStructure ¶
func EncodeRecLine ¶
func RenderRows ¶
func RenderRows(rows []map[string]any, format ViewFormat, opts *RenderOpts, w io.Writer) *ErrDetail
func RenderRowsStream ¶
func RenderRowsStream(iter RowIterator, format ViewFormat, opts *RenderOpts, w io.Writer) *ErrDetail
type RenderOpts ¶
type ViewFormat ¶
type ViewFormat string
const ( FormatTable ViewFormat = "table" FormatBox ViewFormat = "box" FormatJSON ViewFormat = "json" FormatJSONL ViewFormat = "jsonl" FormatCSV ViewFormat = "csv" FormatHTML ViewFormat = "html" )
Click to show internal directories.
Click to hide internal directories.