Esempio n. 1
0
func TestLiteral(t *testing.T) {
	number := nodes.Literal(1)
	str := nodes.Literal("1")
	n, _ := sql.Accept(number)
	s, _ := sql.Accept(str)
	if n != s {
		t.Errorf("TestLiteral was expected to return the same result, got %s and %s", n, s)
	}
}
Esempio n. 2
0
// Sets the Context's Having member to the given expression.
func (self *SelectManager) Having(expr interface{}) *SelectManager {
	if _, ok := expr.(string); ok {
		expr = nodes.Literal(expr)
	}

	self.Context.Having = nodes.Having(expr)
	return self
}
Esempio n. 3
0
// Appends an expression to the current Context's Orders slice,
// typically an attribute.
func (self *SelectManager) Order(expr interface{}) *SelectManager {
	if _, ok := expr.(string); ok {
		expr = nodes.Literal(expr)
	}

	self.Tree.Orders = append(self.Tree.Orders, expr)
	return self
}
Esempio n. 4
0
// Appends a node to the current Context's Groups slice,
// typically an attribute or column.
func (self *SelectManager) Group(groupings ...interface{}) *SelectManager {
	for _, group := range groupings {
		if _, ok := group.(string); ok {
			group = nodes.Literal(group)
		}

		self.Context.Groups = append(self.Context.Groups, group)
	}
	return self
}
Esempio n. 5
0
// Appends an expression to the current Context's Wheres slice,
// typically a comparison, i.e. 1 = 1
func (self *SelectManager) Where(expr interface{}) *SelectManager {
	if _, ok := expr.(string); ok {
		expr = nodes.Literal(expr)
	}

	if _, ok := expr.(*nodes.GroupingNode); !ok {
		expr = nodes.Grouping(expr)
	}

	self.Context.Wheres = append(self.Context.Wheres, expr)
	return self
}