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)
	}
}
Exemple #2
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
}
Exemple #3
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)
	}

	self.Context.Wheres = append(self.Context.Wheres, nodes.Grouping(expr))
	return self
}
Exemple #4
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
}
Exemple #5
0
// Appends a projection to the current Context's Projections slice,
// typically an AttributeNode or string.  If a string is provided, it is
// inserted as a LiteralNode.
func (self *SelectManager) Project(projections ...interface{}) *SelectManager {
	for _, projection := range projections {
		if _, ok := projection.(string); ok {
			projection = nodes.Literal(projection)
		}
		self.Context.Projections = append(self.Context.Projections, projection)
	}
	return self
}
Exemple #6
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
}