Documentation ¶
Overview ¶
Package query provides functions to transform queries.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Debug bool = false
Debug prints very verbose tracing information to STDOUT.
View Source
var ReplaceNumbersInWords = false
ReplaceNumbersInWords enables replacing numbers in words. For example: `SELECT c FROM org235.t` -> `SELECT c FROM org?.t`. For more examples look at test query_test.go/TestFingerprintWithNumberInDbName.
Functions ¶
func Fingerprint ¶
Fingerprint returns the canonical form of q. The primary transformations are:
- Replace values with ?
- Collapse whitespace
- Remove comments
- Lowercase everything
Additional trasnformations are performed which change the syntax of the original query without affecting its performance characteristics. For example, "ORDER BY col ASC" is the same as "ORDER BY col", so "ASC" in the fingerprint is removed.
Example ¶
package main import ( "fmt" "github.com/XiBao/db/query" ) func main() { q := "SELECT c FROM t WHERE a=1 AND b='foo'\n" + "/* some comment */ ORDER BY c ASC LIMIT 1" f := query.Fingerprint(q) fmt.Println(f) }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.