sql

package
v5.2.12 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package sql helps to create SQL squirrel filters using the TSL package.

Example

Example for the tsl package.

// Set a TSL input string.
input := "name = 'joe' and city != 'rome'"

// Parse input string into a TSL tree.
tree, _ := tsl.ParseTSL(input)

// Set filter
filter, _ := Walk(tree)

// Convert TSL tree into SQL string using squirrel sql builder.
sql, args, _ := sq.Select("name, city, state").
	From("users").
	Where(filter).
	ToSql()

fmt.Printf("SQL : %s\n", sql)
fmt.Printf("Args: %v\n", args)
Output:

SQL : SELECT name, city, state FROM users WHERE (name = ? AND city <> ?)
Args: [joe rome]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Walk

func Walk(n tsl.Node) (s sq.Sqlizer, err error)

Walk travel the TSL tree to create squirrel SQL select operators.

Users can call the Walk method inside a squirrel Where to add the query.

filter, _ := sql.Walk(tree)
sql, args, _ := sq.Select("name, city, state").
  From("users").
  Where(filter).
  ToSql()

Squirrel: https://github.com/Masterminds/squirrel

Types

This section is empty.

Jump to

Keyboard shortcuts

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