l8ql

Query Language

SQL-like query language for Go data structures.

Overview

L8QL is a pure-Go, reflection-based SQL-like query language for filtering Go data structures in memory. No database, no ORM, just struct filtering via reflection. It provides a single, common API to query graph model data of any Go struct at runtime.

Two-Stage Compilation

Queries compile in two stages.

Parser
Takes a query string and produces an L8Query protobuf message. Validates syntax only.
Interpreter
Takes the parsed protobuf and an IResources instance. Resolves field names against the introspected type schema. Produces an executable Query.

Query Syntax

select <columns> from <type>
  [where <conditions>]
  [sort-by <column>] [ascending|descending]
  [limit <number>] [page <number>]
  [match-case]
  [mapreduce]
  [group-by <columns>] [having <conditions>]

Operators

Comparison

=
Equal (supports wildcards: name='J*')
!=
Not equal
>, >=, <, <=
Ordering
in, not in
Membership tests

Logical

and, or
Boolean connectives
()
Parentheses for grouping

Aggregation

Aggregate functions: count(*), count(field), sum(field), avg(field), min(field), max(field). Combine with group-by and having for grouped analytics.

Deep Path Navigation

Query nested objects, arrays, and maps seamlessly.

select name from Employee where addresses.country = 'USA'

Key Features

Wildcard pattern matching (J* matches John, Jane)
Case sensitivity control via match-case
Sorting with sort-by and ascending/descending
Pagination with limit and page
MapReduce mode for distributed query execution
MD5 hash generation for query caching and deduplication
Type-safe comparators for strings, integers, unsigned integers, booleans, and pointers

API

query.Match(obj)
Test a single object against the query
query.Filter(list, onlySelected)
Filter a list, optionally projecting selected columns
query.Aggregate(list)
Execute aggregation and return grouped results
query.Hash()
MD5 hash for caching
query.Properties()
Selected columns as property accessors