Add support for conditional constructed projection list.
This commit is contained in:
parent
74725e8e11
commit
d2fbdb68e6
4 changed files with 72 additions and 0 deletions
|
|
@ -7,3 +7,6 @@ type Statement = jet.Statement
|
||||||
|
|
||||||
// Projection is interface for all projection types. Types that can be part of, for instance SELECT clause.
|
// Projection is interface for all projection types. Types that can be part of, for instance SELECT clause.
|
||||||
type Projection = jet.Projection
|
type Projection = jet.Projection
|
||||||
|
|
||||||
|
// ProjectionList can be used to create conditional constructed projection list.
|
||||||
|
type ProjectionList = jet.ProjectionList
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,6 @@ type Statement = jet.Statement
|
||||||
|
|
||||||
// Projection is interface for all projection types. Types that can be part of, for instance SELECT clause.
|
// Projection is interface for all projection types. Types that can be part of, for instance SELECT clause.
|
||||||
type Projection = jet.Projection
|
type Projection = jet.Projection
|
||||||
|
|
||||||
|
// ProjectionList can be used to create conditional constructed projection list.
|
||||||
|
type ProjectionList = jet.ProjectionList
|
||||||
|
|
|
||||||
|
|
@ -708,3 +708,36 @@ func TestJoinViewWithTable(t *testing.T) {
|
||||||
assert.Equal(t, len(dest[0].Rentals), 32)
|
assert.Equal(t, len(dest[0].Rentals), 32)
|
||||||
assert.Equal(t, len(dest[1].Rentals), 27)
|
assert.Equal(t, len(dest[1].Rentals), 27)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConditionalProjectionList(t *testing.T) {
|
||||||
|
projectionList := ProjectionList{}
|
||||||
|
|
||||||
|
columnsToSelect := []string{"customer_id", "create_date"}
|
||||||
|
|
||||||
|
for _, columnName := range columnsToSelect {
|
||||||
|
switch columnName {
|
||||||
|
case Customer.CustomerID.Name():
|
||||||
|
projectionList = append(projectionList, Customer.CustomerID)
|
||||||
|
case Customer.Email.Name():
|
||||||
|
projectionList = append(projectionList, Customer.Email)
|
||||||
|
case Customer.CreateDate.Name():
|
||||||
|
projectionList = append(projectionList, Customer.CreateDate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt := SELECT(projectionList).
|
||||||
|
FROM(Customer).
|
||||||
|
LIMIT(3)
|
||||||
|
|
||||||
|
testutils.AssertDebugStatementSql(t, stmt, `
|
||||||
|
SELECT customer.customer_id AS "customer.customer_id",
|
||||||
|
customer.create_date AS "customer.create_date"
|
||||||
|
FROM dvds.customer
|
||||||
|
LIMIT 3;
|
||||||
|
`)
|
||||||
|
var dest []model.Customer
|
||||||
|
err := stmt.Query(db, &dest)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, len(dest), 3)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1791,3 +1791,36 @@ func TestJoinViewWithTable(t *testing.T) {
|
||||||
assert.Equal(t, len(dest[0].Rentals), 32)
|
assert.Equal(t, len(dest[0].Rentals), 32)
|
||||||
assert.Equal(t, len(dest[1].Rentals), 27)
|
assert.Equal(t, len(dest[1].Rentals), 27)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConditionalProjectionList(t *testing.T) {
|
||||||
|
projectionList := ProjectionList{}
|
||||||
|
|
||||||
|
columnsToSelect := []string{"customer_id", "create_date"}
|
||||||
|
|
||||||
|
for _, columnName := range columnsToSelect {
|
||||||
|
switch columnName {
|
||||||
|
case Customer.CustomerID.Name():
|
||||||
|
projectionList = append(projectionList, Customer.CustomerID)
|
||||||
|
case Customer.Email.Name():
|
||||||
|
projectionList = append(projectionList, Customer.Email)
|
||||||
|
case Customer.CreateDate.Name():
|
||||||
|
projectionList = append(projectionList, Customer.CreateDate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt := SELECT(projectionList).
|
||||||
|
FROM(Customer).
|
||||||
|
LIMIT(3)
|
||||||
|
|
||||||
|
testutils.AssertDebugStatementSql(t, stmt, `
|
||||||
|
SELECT customer.customer_id AS "customer.customer_id",
|
||||||
|
customer.create_date AS "customer.create_date"
|
||||||
|
FROM dvds.customer
|
||||||
|
LIMIT 3;
|
||||||
|
`)
|
||||||
|
var dest []model.Customer
|
||||||
|
err := stmt.Query(db, &dest)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, len(dest), 3)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue