Additional documentation.
This commit is contained in:
parent
d253a35161
commit
b10270b502
48 changed files with 892 additions and 699 deletions
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
func TestSelect_ScanToStruct(t *testing.T) {
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
SELECT DISTINCT actor.actor_id AS "actor.actor_id",
|
||||
actor.first_name AS "actor.first_name",
|
||||
actor.last_name AS "actor.last_name",
|
||||
|
|
@ -24,7 +24,7 @@ WHERE actor.actor_id = 1;
|
|||
DISTINCT().
|
||||
WHERE(Actor.ActorID.EQ(Int(1)))
|
||||
|
||||
assertStatementSql(t, query, expectedSql, int64(1))
|
||||
assertStatementSql(t, query, expectedSQL, int64(1))
|
||||
|
||||
actor := model.Actor{}
|
||||
err := query.Query(db, &actor)
|
||||
|
|
@ -42,7 +42,7 @@ WHERE actor.actor_id = 1;
|
|||
}
|
||||
|
||||
func TestClassicSelect(t *testing.T) {
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
SELECT payment.payment_id AS "payment.payment_id",
|
||||
payment.customer_id AS "payment.customer_id",
|
||||
payment.staff_id AS "payment.staff_id",
|
||||
|
|
@ -74,7 +74,7 @@ LIMIT 30;
|
|||
ORDER_BY(Payment.PaymentID.ASC()).
|
||||
LIMIT(30)
|
||||
|
||||
assertStatementSql(t, query, expectedSql, int64(30))
|
||||
assertStatementSql(t, query, expectedSQL, int64(30))
|
||||
|
||||
dest := []model.Payment{}
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ LIMIT 30;
|
|||
}
|
||||
|
||||
func TestSelect_ScanToSlice(t *testing.T) {
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
SELECT customer.customer_id AS "customer.customer_id",
|
||||
customer.store_id AS "customer.store_id",
|
||||
customer.first_name AS "customer.first_name",
|
||||
|
|
@ -103,7 +103,7 @@ ORDER BY customer.customer_id ASC;
|
|||
|
||||
query := Customer.SELECT(Customer.AllColumns).ORDER_BY(Customer.CustomerID.ASC())
|
||||
|
||||
assertStatementSql(t, query, expectedSql)
|
||||
assertStatementSql(t, query, expectedSQL)
|
||||
|
||||
err := query.Query(db, &customers)
|
||||
assert.NilError(t, err)
|
||||
|
|
@ -116,7 +116,7 @@ ORDER BY customer.customer_id ASC;
|
|||
}
|
||||
|
||||
func TestSelectAndUnionInProjection(t *testing.T) {
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
SELECT payment.payment_id AS "payment.payment_id",
|
||||
(
|
||||
SELECT customer.customer_id AS "customer.customer_id"
|
||||
|
|
@ -156,12 +156,12 @@ LIMIT 12;
|
|||
).
|
||||
LIMIT(12)
|
||||
|
||||
assertStatementSql(t, query, expectedSql, int64(1), int64(1), int64(10), int64(1), int64(2), int64(1), int64(12))
|
||||
assertStatementSql(t, query, expectedSQL, int64(1), int64(1), int64(10), int64(1), int64(2), int64(1), int64(12))
|
||||
}
|
||||
|
||||
func TestJoinQueryStruct(t *testing.T) {
|
||||
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
SELECT film_actor.actor_id AS "film_actor.actor_id",
|
||||
film_actor.film_id AS "film_actor.film_id",
|
||||
film_actor.last_update AS "film_actor.last_update",
|
||||
|
|
@ -224,7 +224,7 @@ LIMIT 1000;
|
|||
ORDER_BY(Film.FilmID.ASC()).
|
||||
LIMIT(1000)
|
||||
|
||||
assertStatementSql(t, query, expectedSql, int64(1000))
|
||||
assertStatementSql(t, query, expectedSQL, int64(1000))
|
||||
|
||||
var languageActorFilm []struct {
|
||||
model.Language
|
||||
|
|
@ -253,7 +253,7 @@ LIMIT 1000;
|
|||
}
|
||||
|
||||
func TestJoinQuerySlice(t *testing.T) {
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
SELECT language.language_id AS "language.language_id",
|
||||
language.name AS "language.name",
|
||||
language.last_update AS "language.last_update",
|
||||
|
|
@ -290,7 +290,7 @@ LIMIT 15;
|
|||
WHERE(Film.Rating.EQ(enum.MpaaRating.Nc17)).
|
||||
LIMIT(15)
|
||||
|
||||
assertStatementSql(t, query, expectedSql, int64(15))
|
||||
assertStatementSql(t, query, expectedSQL, int64(15))
|
||||
|
||||
err := query.Query(db, &filmsPerLanguage)
|
||||
|
||||
|
|
@ -657,7 +657,7 @@ func TestSelectOrderByAscDesc(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSelectFullJoin(t *testing.T) {
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
SELECT customer.customer_id AS "customer.customer_id",
|
||||
customer.store_id AS "customer.store_id",
|
||||
customer.first_name AS "customer.first_name",
|
||||
|
|
@ -685,7 +685,7 @@ ORDER BY customer.customer_id ASC;
|
|||
SELECT(Customer.AllColumns, Address.AllColumns).
|
||||
ORDER_BY(Customer.CustomerID.ASC())
|
||||
|
||||
assertStatementSql(t, query, expectedSql)
|
||||
assertStatementSql(t, query, expectedSQL)
|
||||
|
||||
allCustomersAndAddress := []struct {
|
||||
Address *model.Address
|
||||
|
|
@ -708,7 +708,7 @@ ORDER BY customer.customer_id ASC;
|
|||
}
|
||||
|
||||
func TestSelectFullCrossJoin(t *testing.T) {
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
SELECT customer.customer_id AS "customer.customer_id",
|
||||
customer.store_id AS "customer.store_id",
|
||||
customer.first_name AS "customer.first_name",
|
||||
|
|
@ -738,7 +738,7 @@ LIMIT 1000;
|
|||
ORDER_BY(Customer.CustomerID.ASC()).
|
||||
LIMIT(1000)
|
||||
|
||||
assertStatementSql(t, query, expectedSql, int64(1000))
|
||||
assertStatementSql(t, query, expectedSQL, int64(1000))
|
||||
|
||||
var customerAddresCrosJoined []struct {
|
||||
model.Customer
|
||||
|
|
@ -753,7 +753,7 @@ LIMIT 1000;
|
|||
}
|
||||
|
||||
func TestSelectSelfJoin(t *testing.T) {
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
SELECT f1.film_id AS "f1.film_id",
|
||||
f1.title AS "f1.title",
|
||||
f1.description AS "f1.description",
|
||||
|
|
@ -793,7 +793,7 @@ ORDER BY f1.film_id ASC;
|
|||
SELECT(f1.AllColumns, f2.AllColumns).
|
||||
ORDER_BY(f1.FilmID.ASC())
|
||||
|
||||
assertStatementSql(t, query, expectedSql)
|
||||
assertStatementSql(t, query, expectedSQL)
|
||||
|
||||
type F1 model.Film
|
||||
type F2 model.Film
|
||||
|
|
@ -813,7 +813,7 @@ ORDER BY f1.film_id ASC;
|
|||
}
|
||||
|
||||
func TestSelectAliasColumn(t *testing.T) {
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
SELECT f1.title AS "thesame_length_films.title1",
|
||||
f2.title AS "thesame_length_films.title2",
|
||||
f1.length AS "thesame_length_films.length"
|
||||
|
|
@ -835,7 +835,7 @@ LIMIT 1000;
|
|||
ORDER_BY(f1.Length.ASC(), f1.Title.ASC(), f2.Title.ASC()).
|
||||
LIMIT(1000)
|
||||
|
||||
assertStatementSql(t, query, expectedSql, int64(1000))
|
||||
assertStatementSql(t, query, expectedSQL, int64(1000))
|
||||
|
||||
type thesameLengthFilms struct {
|
||||
Title1 string
|
||||
|
|
@ -928,7 +928,7 @@ FROM dvds.film;
|
|||
}
|
||||
|
||||
func TestSelectQueryScalar(t *testing.T) {
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
SELECT film.film_id AS "film.film_id",
|
||||
film.title AS "film.title",
|
||||
film.description AS "film.description",
|
||||
|
|
@ -960,7 +960,7 @@ ORDER BY film.film_id ASC;
|
|||
WHERE(Film.RentalRate.EQ(maxFilmRentalRate)).
|
||||
ORDER_BY(Film.FilmID.ASC())
|
||||
|
||||
assertStatementSql(t, query, expectedSql)
|
||||
assertStatementSql(t, query, expectedSQL)
|
||||
|
||||
maxRentalRateFilms := []model.Film{}
|
||||
err := query.Query(db, &maxRentalRateFilms)
|
||||
|
|
@ -989,7 +989,7 @@ ORDER BY film.film_id ASC;
|
|||
}
|
||||
|
||||
func TestSelectGroupByHaving(t *testing.T) {
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
SELECT payment.customer_id AS "customer_payment_sum.customer_id",
|
||||
SUM(payment.amount) AS "customer_payment_sum.amount_sum",
|
||||
AVG(payment.amount) AS "customer_payment_sum.amount_avg",
|
||||
|
|
@ -1018,7 +1018,7 @@ ORDER BY SUM(payment.amount) ASC;
|
|||
SUMf(Payment.Amount).GT(Float(100)),
|
||||
)
|
||||
|
||||
assertStatementSql(t, customersPaymentQuery, expectedSql, float64(100))
|
||||
assertStatementSql(t, customersPaymentQuery, expectedSQL, float64(100))
|
||||
|
||||
type CustomerPaymentSum struct {
|
||||
CustomerID int16
|
||||
|
|
@ -1047,7 +1047,7 @@ ORDER BY SUM(payment.amount) ASC;
|
|||
}
|
||||
|
||||
func TestSelectGroupBy2(t *testing.T) {
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
SELECT customer.customer_id AS "customer.customer_id",
|
||||
customer.store_id AS "customer.store_id",
|
||||
customer.first_name AS "customer.first_name",
|
||||
|
|
@ -1088,7 +1088,7 @@ ORDER BY customer_payment_sum."amount_sum" ASC;
|
|||
).
|
||||
ORDER_BY(amountSum.ASC())
|
||||
|
||||
assertStatementSql(t, query, expectedSql)
|
||||
assertStatementSql(t, query, expectedSQL)
|
||||
|
||||
type CustomerWithAmounts struct {
|
||||
Customer *model.Customer
|
||||
|
|
@ -1157,7 +1157,7 @@ func TestSelectStaff(t *testing.T) {
|
|||
|
||||
func TestSelectTimeColumns(t *testing.T) {
|
||||
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
SELECT payment.payment_id AS "payment.payment_id",
|
||||
payment.customer_id AS "payment.customer_id",
|
||||
payment.staff_id AS "payment.staff_id",
|
||||
|
|
@ -1173,7 +1173,7 @@ ORDER BY payment.payment_date ASC;
|
|||
WHERE(Payment.PaymentDate.LT(Timestamp(2007, 02, 14, 22, 16, 01, 0))).
|
||||
ORDER_BY(Payment.PaymentDate.ASC())
|
||||
|
||||
assertStatementSql(t, query, expectedSql, "2007-02-14 22:16:01.000")
|
||||
assertStatementSql(t, query, expectedSQL, "2007-02-14 22:16:01.000")
|
||||
|
||||
payments := []model.Payment{}
|
||||
|
||||
|
|
@ -1260,8 +1260,8 @@ func TestAllSetOperators(t *testing.T) {
|
|||
UNION_ALL,
|
||||
INTERSECT,
|
||||
INTERSECT_ALL,
|
||||
EXCEPT,
|
||||
EXCEPT_ALL,
|
||||
//EXCEPT,
|
||||
//EXCEPT_ALL,
|
||||
}
|
||||
|
||||
expectedDestLen := []int{
|
||||
|
|
@ -1316,7 +1316,7 @@ LIMIT 20;
|
|||
}
|
||||
|
||||
func TestLockTable(t *testing.T) {
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
LOCK TABLE dvds.address IN`
|
||||
|
||||
var testData = []TableLockMode{
|
||||
|
|
@ -1333,7 +1333,7 @@ LOCK TABLE dvds.address IN`
|
|||
for _, lockMode := range testData {
|
||||
query := Address.LOCK().IN(lockMode)
|
||||
|
||||
assertStatementSql(t, query, expectedSql+" "+string(lockMode)+" MODE;\n")
|
||||
assertStatementSql(t, query, expectedSQL+" "+string(lockMode)+" MODE;\n")
|
||||
|
||||
tx, _ := db.Begin()
|
||||
|
||||
|
|
@ -1349,7 +1349,7 @@ LOCK TABLE dvds.address IN`
|
|||
for _, lockMode := range testData {
|
||||
query := Address.LOCK().IN(lockMode).NOWAIT()
|
||||
|
||||
assertStatementSql(t, query, expectedSql+" "+string(lockMode)+" MODE NOWAIT;\n")
|
||||
assertStatementSql(t, query, expectedSQL+" "+string(lockMode)+" MODE NOWAIT;\n")
|
||||
|
||||
tx, _ := db.Begin()
|
||||
|
||||
|
|
@ -1373,7 +1373,7 @@ func getRowLockTestData() map[SelectLock]string {
|
|||
}
|
||||
|
||||
func TestRowLock(t *testing.T) {
|
||||
expectedSql := `
|
||||
expectedSQL := `
|
||||
SELECT *
|
||||
FROM dvds.address
|
||||
LIMIT 3
|
||||
|
|
@ -1385,7 +1385,7 @@ FOR`
|
|||
for lockType, lockTypeStr := range getRowLockTestData() {
|
||||
query.FOR(lockType)
|
||||
|
||||
assertStatementSql(t, query, expectedSql+" "+lockTypeStr+";\n", int64(3))
|
||||
assertStatementSql(t, query, expectedSQL+" "+lockTypeStr+";\n", int64(3))
|
||||
|
||||
tx, _ := db.Begin()
|
||||
|
||||
|
|
@ -1401,7 +1401,7 @@ FOR`
|
|||
for lockType, lockTypeStr := range getRowLockTestData() {
|
||||
query.FOR(lockType.NOWAIT())
|
||||
|
||||
assertStatementSql(t, query, expectedSql+" "+lockTypeStr+" NOWAIT;\n", int64(3))
|
||||
assertStatementSql(t, query, expectedSQL+" "+lockTypeStr+" NOWAIT;\n", int64(3))
|
||||
|
||||
tx, _ := db.Begin()
|
||||
|
||||
|
|
@ -1417,7 +1417,7 @@ FOR`
|
|||
for lockType, lockTypeStr := range getRowLockTestData() {
|
||||
query.FOR(lockType.SKIP_LOCKED())
|
||||
|
||||
assertStatementSql(t, query, expectedSql+" "+lockTypeStr+" SKIP LOCKED;\n", int64(3))
|
||||
assertStatementSql(t, query, expectedSQL+" "+lockTypeStr+" SKIP LOCKED;\n", int64(3))
|
||||
|
||||
tx, _ := db.Begin()
|
||||
|
||||
|
|
@ -1433,7 +1433,7 @@ FOR`
|
|||
|
||||
func TestQuickStart(t *testing.T) {
|
||||
|
||||
var expectedSql = `
|
||||
var expectedSQL = `
|
||||
SELECT actor.actor_id AS "actor.actor_id",
|
||||
actor.first_name AS "actor.first_name",
|
||||
actor.last_name AS "actor.last_name",
|
||||
|
|
@ -1488,7 +1488,7 @@ ORDER BY actor.actor_id ASC, film.film_id ASC;
|
|||
Film.FilmID.ASC(),
|
||||
)
|
||||
|
||||
assertStatementSql(t, stmt, expectedSql, "English", "Action", int64(180))
|
||||
assertStatementSql(t, stmt, expectedSQL, "English", "Action", int64(180))
|
||||
|
||||
var dest []struct {
|
||||
model.Actor
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue