Explicit sqlbuilder cast.
This commit is contained in:
parent
4d7fbf8f49
commit
3c5553b3dc
21 changed files with 293 additions and 104 deletions
|
|
@ -700,27 +700,6 @@ LIMIT 1000;
|
|||
//}
|
||||
|
||||
func TestSubQuery(t *testing.T) {
|
||||
|
||||
//selectStmtTable := Actor.SELECT(Actor.FirstName, Actor.LastName).AsTable("table_expression")
|
||||
//
|
||||
//query := selectStmtTable.SELECT(
|
||||
// selectStmtTable.RefStringColumn(Actor.FirstName).AS("nesto"),
|
||||
// selectStmtTable.RefIntColumnName("actor.last_name").AS("nesto2"),
|
||||
// )
|
||||
//
|
||||
//queryStr, args, err := query.Sql()
|
||||
//
|
||||
//assert.NilError(t, err)
|
||||
//
|
||||
//fmt.Println(queryStr)
|
||||
//
|
||||
//avrgCustomer := NumExp(Customer.SELECT(Customer.LastName).LIMIT(1))
|
||||
//
|
||||
//Customer.
|
||||
// innerJoin(selectStmtTable, Customer.LastName.EQ(selectStmtTable.RefStringColumn(Actor.FirstName))).
|
||||
// SELECT(Customer.AllColumns, selectStmtTable.RefIntColumnName("first_name")).
|
||||
// WHERE(Actor.LastName.Neq(avrgCustomer))
|
||||
|
||||
expectedQuery := `
|
||||
SELECT actor.actor_id AS "actor.actor_id",
|
||||
actor.first_name AS "actor.first_name",
|
||||
|
|
@ -742,12 +721,20 @@ FROM dvds.actor
|
|||
) AS films ON (film_actor.film_id = films."film.film_id");
|
||||
`
|
||||
|
||||
rFilmsOnly := Film.SELECT(Film.FilmID, Film.Title, Film.Rating).
|
||||
rFilmsOnly := Film.
|
||||
SELECT(
|
||||
Film.FilmID,
|
||||
Film.Title,
|
||||
Film.Rating,
|
||||
).
|
||||
WHERE(Film.Rating.EQ(enum.MpaaRating.R)).
|
||||
AsTable("films")
|
||||
|
||||
query := Actor.INNER_JOIN(FilmActor, Actor.ActorID.EQ(FilmActor.FilmID)).
|
||||
INNER_JOIN(rFilmsOnly, FilmActor.FilmID.EQ(rFilmsOnly.RefIntColumn(Film.FilmID))).
|
||||
rFilmId := rFilmsOnly.RefIntColumn(Film.FilmID)
|
||||
|
||||
query := Actor.
|
||||
INNER_JOIN(FilmActor, Actor.ActorID.EQ(FilmActor.FilmID)).
|
||||
INNER_JOIN(rFilmsOnly, FilmActor.FilmID.EQ(rFilmId)).
|
||||
SELECT(
|
||||
Actor.AllColumns,
|
||||
FilmActor.AllColumns,
|
||||
|
|
@ -806,11 +793,11 @@ FROM dvds.film
|
|||
WHERE film.rental_rate = (
|
||||
SELECT MAX(film.rental_rate)
|
||||
FROM dvds.film
|
||||
)
|
||||
)::double precision
|
||||
ORDER BY film.film_id ASC;
|
||||
`
|
||||
|
||||
maxFilmRentalRate := NumExp(Film.SELECT(MAXf(Film.RentalRate)))
|
||||
maxFilmRentalRate := Film.SELECT(MAXf(Film.RentalRate)).TO_DOUBLE()
|
||||
|
||||
query := Film.
|
||||
SELECT(Film.AllColumns).
|
||||
|
|
@ -936,10 +923,14 @@ ORDER BY customer_payment_sum.amount_sum ASC;
|
|||
|
||||
customersPaymentTable := customersPaymentSubQuery.AsTable("customer_payment_sum")
|
||||
amountSumColumn := customersPaymentTable.RefIntColumnName("amount_sum")
|
||||
customerId := customersPaymentTable.RefIntColumn(Payment.CustomerID)
|
||||
|
||||
query := Customer.
|
||||
INNER_JOIN(customersPaymentTable, Customer.CustomerID.EQ(customersPaymentTable.RefIntColumn(Payment.CustomerID))).
|
||||
SELECT(Customer.AllColumns, amountSumColumn.AS("customer_with_amounts.amount_sum")).
|
||||
INNER_JOIN(customersPaymentTable, Customer.CustomerID.EQ(customerId)).
|
||||
SELECT(
|
||||
Customer.AllColumns,
|
||||
amountSumColumn.AS("customer_with_amounts.amount_sum"),
|
||||
).
|
||||
ORDER_BY(amountSumColumn.ASC())
|
||||
|
||||
assertQuery(t, query, expectedSql)
|
||||
|
|
|
|||
|
|
@ -34,15 +34,20 @@ func TestExpressionOperators(t *testing.T) {
|
|||
AllTypes.SmallintPtr.NOT_IN(Int(11), Int(22), NULL),
|
||||
AllTypes.SmallintPtr.NOT_IN(AllTypes.SELECT(AllTypes.IntegerPtr)),
|
||||
|
||||
String("TRUE").CAST_TO_BOOL(),
|
||||
String("111").CAST_TO_INTEGER(),
|
||||
String("11.23").CAST_TO_DOUBLE(),
|
||||
Int(234).CAST_TO_TEXT(),
|
||||
String("1/8/1999").CAST_TO_DATE(),
|
||||
String("04:05:06.789").CAST_TO_TIME(),
|
||||
String("04:05:06 PST").CAST_TO_TIMEZ(),
|
||||
String("1999-01-08 04:05:06").CAST_TO_TIMESTAMP(),
|
||||
String("January 8 04:05:06 1999 PST").CAST_TO_TIMESTAMPZ(),
|
||||
String("TRUE").TO_BOOL(),
|
||||
String("111").TO_SMALLINT(),
|
||||
String("111").TO_INTEGER(),
|
||||
String("111").TO_BIGINT(),
|
||||
String("11.23").TO_NUMERIC(30, 10),
|
||||
String("11.23").TO_NUMERIC(30),
|
||||
String("11.23").TO_REAL(),
|
||||
String("11.23").TO_DOUBLE(),
|
||||
Int(234).TO_TEXT(),
|
||||
String("1/8/1999").TO_DATE(),
|
||||
String("04:05:06.789").TO_TIME(),
|
||||
String("04:05:06 PST").TO_TIMEZ(),
|
||||
String("1999-01-08 04:05:06").TO_TIMESTAMP(),
|
||||
String("January 8 04:05:06 1999 PST").TO_TIMESTAMPZ(),
|
||||
|
||||
TO_CHAR(AllTypes.Timestamp, String("HH12:MI:SS")),
|
||||
TO_CHAR(AllTypes.Integer, String("999")),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue