Exemplo n.º 1
0
// Table returns an Accessor from the managers package for
// generating SQL to interact with existing tables.
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)
	}
}
Exemplo n.º 2
0
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)
	}
}
Exemplo n.º 3
0
// ToSql calls a visitor's Accept method based on the manager's SQL adapter.
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.adapter {
		self.adapter = "to_sql"
	}

	return VisitorFor(self.adapter).Accept(self.Tree)
}
Exemplo n.º 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()
}