コード例 #1
0
func TestExcept(t *testing.T) {
	relationOne := nodes.Relation("table_one")
	relationTwo := nodes.Relation("table_two")
	relationThree := nodes.Relation("table_three")
	one := nodes.SelectStatement(relationOne)
	two := nodes.SelectStatement(relationTwo)
	three := nodes.SelectStatement(relationThree)
	one.Combinator = nodes.Except(one, two)
	two.Combinator = nodes.Except(two, three)
	expected := `(SELECT FROM "table_one" EXCEPT (SELECT FROM "table_two" EXCEPT SELECT FROM "table_three"))`
	if got, _ := sql.Accept(one); expected != got {
		t.Errorf("TestUnion was expected to return %s, got %s", expected, got)
	}
}
コード例 #2
0
func TestSelectManager(t *testing.T) {
	relation := nodes.Relation("table")
	mgr := managers.Selection(relation)

	// The following struct members should exist.
	_ = mgr.Tree
	_ = mgr.Context
	_ = mgr.Engine

	// The following receiver methods should exist.
	_ = mgr.Project(1)
	_ = mgr.Where(1)
	_ = mgr.Offset(1)
	_ = mgr.Limit(1)
	_ = mgr.InnerJoin(1)
	_ = mgr.OuterJoin(1)
	_ = mgr.On(1)
	_ = mgr.Order(1)
	_ = mgr.Group(1)
	_ = mgr.Having(1)
	_ = mgr.Union(managers.Selection(relation))
	_ = mgr.Intersect(managers.Selection(relation))
	_ = mgr.Except(managers.Selection(relation))
	_ = mgr.Engine(1)
	_, _ = mgr.ToSql()
}
コード例 #3
0
func TestUnaliasedRelation(t *testing.T) {
	relation := nodes.Relation("table")
	expected := `"table"`
	if got, _ := sql.Accept(relation); expected != got {
		t.Errorf("TestUnaliasedRelation was expected to return %s, got %s", expected, got)
	}
}
コード例 #4
0
func TestDeleteStatement(t *testing.T) {
	relation := nodes.Relation("table")
	stmt := nodes.DeleteStatement(relation)
	expected := `DELETE FROM "table" `
	if got, _ := sql.Accept(stmt); expected != got {
		t.Errorf("TestDeleteStatement was expected to return %s, got %s", expected, got)
	}
}
コード例 #5
0
func TestInsertStatement(t *testing.T) {
	relation := nodes.Relation("table")
	stmt := nodes.InsertStatement(relation)
	expected := `INSERT INTO "table" `
	if got, _ := sql.Accept(stmt); expected != got {
		t.Errorf("TestInsertStatement was expected to return %s, got %s", expected, got)
	}
}
コード例 #6
0
func TestSelectCore(t *testing.T) {
	relation := nodes.Relation("table")
	core := nodes.SelectCore(relation)
	expected := `SELECT FROM "table"`
	if got, _ := sql.Accept(core); expected != got {
		t.Errorf("TestSelectCore was expected to return %s, got %s", expected, got)
	}
}
コード例 #7
0
func TestJoinSource(t *testing.T) {
	relation := nodes.Relation("table")
	source := nodes.JoinSource(relation)
	expected := `"table"`
	if got, _ := sql.Accept(source); expected != got {
		t.Errorf("TestJoinSource was expected to return %s, got %s", expected, got)
	}
}
コード例 #8
0
func TestExtensiveJoinSource(t *testing.T) {
	relation := nodes.Relation("table")
	source := nodes.JoinSource(relation)
	source.Right = append(source.Right, []interface{}{1, 2, 3}...)
	expected := `"table" 1 2 3`
	if got, _ := sql.Accept(source); expected != got {
		t.Errorf("TestExtensiveJoinSource was expected to return %s, got %s", expected, got)
	}
}
コード例 #9
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)
	}
}
コード例 #10
0
ファイル: table.go プロジェクト: smillaedler/codex
// 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)
	}
}
コード例 #11
0
func TestSelectCoreExtensive(t *testing.T) {
	relation := nodes.Relation("table")
	core := nodes.SelectCore(relation)
	core.Projections = append(core.Projections, 1, 2)
	core.Wheres = append(core.Wheres, 3, 4)
	core.Source.Right = append(core.Source.Right, nodes.InnerJoin(5, nil))
	expected := `SELECT 1, 2 FROM "table" INNER JOIN 5 WHERE 3 AND 4`
	if got, _ := sql.Accept(core); expected != got {
		t.Errorf("TestSelectCoreExtensive was expected to return %s, got %s", expected, got)
	}
}
コード例 #12
0
func TestDeleteManager(t *testing.T) {
	relation := nodes.Relation("table")
	mgr := managers.Deletion(relation)

	// The following struct members should exist.
	_ = mgr.Tree
	_ = mgr.Engine

	// The following receiver methods should exist.
	_ = mgr.Delete(1)
	_ = mgr.Engine(1)
	_, _ = mgr.ToSql()
}
コード例 #13
0
func TestInsertManager(t *testing.T) {
	relation := nodes.Relation("table")
	mgr := managers.Insertion(relation)

	// The following struct members should exist.
	_ = mgr.Tree
	_ = mgr.Engine

	// The following receiver methods should exist.
	_ = mgr.Insert(1)
	_ = mgr.Into(1)
	_ = mgr.Returning(1)
	_ = mgr.Engine(1)
	_, _ = mgr.ToSql()
}
コード例 #14
0
func TestUpdateManager(t *testing.T) {
	relation := nodes.Relation("table")
	mgr := managers.Modification(relation)

	// The following struct members should exist.
	_ = mgr.Tree
	_ = mgr.Engine

	// The following receiver methods should exist.
	_ = mgr.Set(1)
	_ = mgr.To(1)
	_ = mgr.Where(1)
	_ = mgr.Limit(1)
	_ = mgr.Engine(1)
	_, _ = mgr.ToSql()
}
コード例 #15
0
ファイル: attribute_test.go プロジェクト: smillaedler/codex
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()
}