Example #1
0
// Table returns an Accessor
func Table(name string) managers.Accessor {
	relation := nodes.Relation(name)
	return func(name interface{}) *nodes.AttributeNode {
		if _, ok := name.(string); ok {
			return nodes.Attribute(nodes.Column(name), relation)
		}

		return nodes.Attribute(name, relation)
	}
}
func TestUnaliasedAttribute(t *testing.T) {
	relation := nodes.Relation("table")
	column := nodes.Column("column")
	attribute := nodes.Attribute(column, relation)
	expected := `"table"."column"`
	if got, _ := sql.Accept(attribute); expected != got {
		t.Errorf("TestUnaliasedAttribute was expected to return %s, got %s", expected, got)
	}
}
Example #3
0
// Calls a visitor's Accept method based on the manager's SQL Engine.
func (self *SelectManager) ToSql() (string, error) {
	for _, core := range self.Tree.Cores {
		if 0 == len(core.Projections) {
			core.Projections = append(core.Projections, nodes.Attribute(nodes.Star(), core.Relation))
		}
	}

	if nil == self.engine {
		self.engine = "to_sql"
	}

	return VISITORS[self.engine].Accept(self.Tree)
}
Example #4
0
func TestAttribute(t *testing.T) {
	attr := nodes.Attribute("column", nodes.Relation("table"))

	// The following struct members should exist.
	_ = attr.Name
	_ = attr.Relation

	// The following receiver methods should exist.
	_ = attr.And(1)
	_ = attr.Or(1)
	_ = attr.Eq(1)
	_ = attr.Neq(1)
	_ = attr.Gt(1)
	_ = attr.Gte(1)
	_ = attr.Lt(1)
	_ = attr.Lte(1)
	_ = attr.Like(1)
	_ = attr.Unlike(1)
	_ = attr.Asc()
	_ = attr.Desc()
}