tree-search-language

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2018 License: Apache-2.0

README

tsl

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

Go Report Card Build Status GoDoc License

Cli tools
$ ./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()
  ...

Directories

Path Synopsis
cmd
tsl_parser command
Package main
Package main
tsl_to_sql command
Package main
Package main
pkg
tsl
Package tsl describe and parse the Tree Search Language (TSL).
Package tsl describe and parse the Tree Search Language (TSL).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL