named query compilation
This commit is contained in:
10
named.go
10
named.go
@@ -3,16 +3,10 @@ package gocqlx
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/gocql/gocql"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Queryx struct {
|
|
||||||
*gocql.Query
|
|
||||||
names []string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow digits and letters in bind params; additionally runes are
|
// Allow digits and letters in bind params; additionally runes are
|
||||||
// checked against underscores, meaning that bind params can have be
|
// checked against underscores, meaning that bind params can have be
|
||||||
// alphanumeric with underscores. Mind the difference between unicode
|
// alphanumeric with underscores. Mind the difference between unicode
|
||||||
@@ -21,7 +15,7 @@ var allowedBindRunes = []*unicode.RangeTable{unicode.Letter, unicode.Digit}
|
|||||||
|
|
||||||
// CompileNamedQuery compiles a named query into an unbound query using the
|
// CompileNamedQuery compiles a named query into an unbound query using the
|
||||||
// '?' bindvar and a list of names.
|
// '?' bindvar and a list of names.
|
||||||
func CompileNamedQuery(qs []byte) (cql string, names []string, err error) {
|
func CompileNamedQuery(qs []byte) (stmt string, names []string, err error) {
|
||||||
// guess number of names
|
// guess number of names
|
||||||
n := bytes.Count(qs, []byte(":"))
|
n := bytes.Count(qs, []byte(":"))
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -44,7 +38,7 @@ func CompileNamedQuery(qs []byte) (cql string, names []string, err error) {
|
|||||||
continue
|
continue
|
||||||
} else if inName {
|
} else if inName {
|
||||||
err = errors.New("unexpected `:` while reading named param at " + strconv.Itoa(i))
|
err = errors.New("unexpected `:` while reading named param at " + strconv.Itoa(i))
|
||||||
return cql, names, err
|
return stmt, names, err
|
||||||
}
|
}
|
||||||
inName = true
|
inName = true
|
||||||
name = []byte{}
|
name = []byte{}
|
||||||
|
|||||||
Reference in New Issue
Block a user