tsl
Tree Search Language (TSL) is a simple SQL like langauge

$ ./tsl_parser -h
Usage of ./tls_parser:
-i string
the tsl string to parse (e.g. "animal = 'kitty'")
-o string
output format [json/yaml/prettyjson] (default "json")
$ ./tsl_parser -i "(name = 'joe' or name = 'jane') and city = 'rome'" -o yaml
func: $and
left:
func: $eq
left: city
right: rome
right:
func: $or
left:
func: $eq
left: name
right: jane
right:
func: $eq
left: name
right: joe
$ ./tsl_to_sql -h
Usage of ./tsl_to_sql:
-i string
the tsl string to parse (e.g. "animal = 'kitty'")
-o string
output format [mysql/pgsql] (default "mysql")
-t string
the table name to use for SQL generation (default "<table-name>")
$ ./tsl_to_sql -i "name != 'eli''s' or city like '%rome%' and state not between 'italy' and 'france'" -t users -o pgsql
sql: SELECT * FROM users WHERE (name <> $1 OR (city LIKE $2 AND state NOT BETWEEN $3 AND $4))
args: [eli's %rome% italy france]
Language
TSL is generated using Antlr4 tool, the grammer file used for generation is TSL.g4.
Keywords
and or not is null like between in
Operators
= <= >= != ~= ~! <>
Examples
name = 'Joe'
city in ('paris', 'rome', 'milan') or sate = 'spain'
(name = 'joe' or city = 'rome') and state = 'italy'
Code snippets
import (
"github.com/yaacov/tsl/pkg/tsl"
)
...
// Set a TSL input string
input = "name='joe' or name='jane'"
// Parse input string into a TSL tree
tree, err := tsl.ParseTSL(input)
...
...
// Convert TSL tree into SQL string
sql, args, err = tsl.ToSelectBuilder(tree, false).
From(*tablePtr).
ToSql()
...