diff --git a/example_test.go b/example_test.go index 93e95747..a610ad1d 100644 --- a/example_test.go +++ b/example_test.go @@ -1,13 +1,23 @@ package goqu_test import ( + "database/sql" "fmt" + "github.com/DATA-DOG/go-sqlmock" "github.com/doug-martin/goqu" "regexp" ) +var driver *sql.DB + +func init() { + db, _ := sqlmock.New() + driver = db +} + func ExampleOr() { - sql, _ := goqu.From("test").Where( + db := goqu.New("default", driver) + sql, _ := db.From("test").Where( goqu.Or( goqu.I("a").Gt(10), goqu.I("a").Lt(5), @@ -18,7 +28,8 @@ func ExampleOr() { } func ExampleOr_withAnd() { - sql, _ := goqu.From("items").Where( + db := goqu.New("default", driver) + sql, _ := db.From("items").Where( goqu.Or( goqu.I("a").Gt(10), goqu.And( @@ -33,8 +44,9 @@ func ExampleOr_withAnd() { } func ExampleAnd() { + db := goqu.New("default", driver) //by default Where assumes an And - sql, _ := goqu.From("test").Where( + sql, _ := db.From("test").Where( goqu.I("a").Gt(10), goqu.I("b").Lt(5), ).Sql() @@ -44,7 +56,8 @@ func ExampleAnd() { } func ExampleAnd_withOr() { - sql, _ := goqu.From("test").Where( + db := goqu.New("default", driver) + sql, _ := db.From("test").Where( goqu.I("a").Gt(10), goqu.Or( goqu.I("b").Lt(5), @@ -57,7 +70,8 @@ func ExampleAnd_withOr() { } func ExampleI() { - sql, _ := goqu.From("test").Where( + db := goqu.New("default", driver) + sql, _ := db.From("test").Where( goqu.I("a").Eq(10), goqu.I("b").Lt(10), goqu.I("d").IsTrue(), @@ -65,17 +79,17 @@ func ExampleI() { fmt.Println(sql) //qualify with schema - sql, _ = goqu.From(goqu.I("test").Schema("my_schema")).Sql() + sql, _ = db.From(goqu.I("test").Schema("my_schema")).Sql() fmt.Println(sql) - sql, _ = goqu.From(goqu.I("mychema.test")).Where( + sql, _ = db.From(goqu.I("mychema.test")).Where( //qualify with schema, table, and col goqu.I("my_schema.test.a").Eq(10), ).Sql() fmt.Println(sql) //* will be taken literally and no quoted - sql, _ = goqu.From(goqu.I("test")).Select(goqu.I("test.*")).Sql() + sql, _ = db.From(goqu.I("test")).Select(goqu.I("test.*")).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" WHERE (("a" = 10) AND ("b" < 10) AND ("d" IS TRUE)) @@ -86,13 +100,14 @@ func ExampleI() { } func ExampleAliasMethods() { - sql, _ := goqu.From("test").Select(goqu.I("a").As("as_a")).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Select(goqu.I("a").As("as_a")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Select(goqu.COUNT("*").As("count")).Sql() + sql, _ = db.From("test").Select(goqu.COUNT("*").As("count")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Select(goqu.L("sum(amount)").As("total_amount")).Sql() + sql, _ = db.From("test").Select(goqu.L("sum(amount)").As("total_amount")).Sql() fmt.Println(sql) // Output: // SELECT "a" AS "as_a" FROM "test" @@ -102,40 +117,41 @@ func ExampleAliasMethods() { } func ExampleComparisonMethods() { - sql, _ := goqu.From("test").Where(goqu.I("a").Eq(10)).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Where(goqu.I("a").Eq(10)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").Neq(10)).Sql() + sql, _ = db.From("test").Where(goqu.I("a").Neq(10)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").Gt(10)).Sql() + sql, _ = db.From("test").Where(goqu.I("a").Gt(10)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").Gte(10)).Sql() + sql, _ = db.From("test").Where(goqu.I("a").Gte(10)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").Lt(10)).Sql() + sql, _ = db.From("test").Where(goqu.I("a").Lt(10)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").Lte(10)).Sql() + sql, _ = db.From("test").Where(goqu.I("a").Lte(10)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.L("(a + b)").Eq(10)).Sql() + sql, _ = db.From("test").Where(goqu.L("(a + b)").Eq(10)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.L("(a + b)").Neq(10)).Sql() + sql, _ = db.From("test").Where(goqu.L("(a + b)").Neq(10)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.L("(a + b)").Gt(10)).Sql() + sql, _ = db.From("test").Where(goqu.L("(a + b)").Gt(10)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.L("(a + b)").Gte(10)).Sql() + sql, _ = db.From("test").Where(goqu.L("(a + b)").Gte(10)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.L("(a + b)").Lt(10)).Sql() + sql, _ = db.From("test").Where(goqu.L("(a + b)").Lt(10)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.L("(a + b)").Lte(10)).Sql() + sql, _ = db.From("test").Where(goqu.L("(a + b)").Lte(10)).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" WHERE ("a" = 10) @@ -153,18 +169,19 @@ func ExampleComparisonMethods() { } func ExampleInMethods() { - sql, _ := goqu.From("test").Where(goqu.I("a").In("a", "b", "c")).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Where(goqu.I("a").In("a", "b", "c")).Sql() fmt.Println(sql) //with a slice - sql, _ = goqu.From("test").Where(goqu.I("a").In([]string{"a", "b", "c"})).Sql() + sql, _ = db.From("test").Where(goqu.I("a").In([]string{"a", "b", "c"})).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").NotIn("a", "b", "c")).Sql() + sql, _ = db.From("test").Where(goqu.I("a").NotIn("a", "b", "c")).Sql() fmt.Println(sql) //with a slice - sql, _ = goqu.From("test").Where(goqu.I("a").NotIn([]string{"a", "b", "c"})).Sql() + sql, _ = db.From("test").Where(goqu.I("a").NotIn([]string{"a", "b", "c"})).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" WHERE ("a" IN ('a', 'b', 'c')) @@ -174,16 +191,17 @@ func ExampleInMethods() { } func ExampleOrderedMethods() { - sql, _ := goqu.From("test").Order(goqu.I("a").Asc()).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Order(goqu.I("a").Asc()).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Order(goqu.I("a").Desc()).Sql() + sql, _ = db.From("test").Order(goqu.I("a").Desc()).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Order(goqu.I("a").Desc().NullsFirst()).Sql() + sql, _ = db.From("test").Order(goqu.I("a").Desc().NullsFirst()).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Order(goqu.I("a").Desc().NullsLast()).Sql() + sql, _ = db.From("test").Order(goqu.I("a").Desc().NullsLast()).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" ORDER BY "a" ASC @@ -193,28 +211,29 @@ func ExampleOrderedMethods() { } func ExampleStringMethods() { - sql, _ := goqu.From("test").Where(goqu.I("a").Like("%a%")).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Where(goqu.I("a").Like("%a%")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").Like(regexp.MustCompile("(a|b)"))).Sql() + sql, _ = db.From("test").Where(goqu.I("a").Like(regexp.MustCompile("(a|b)"))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").NotLike("%a%")).Sql() + sql, _ = db.From("test").Where(goqu.I("a").NotLike("%a%")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").NotLike(regexp.MustCompile("(a|b)"))).Sql() + sql, _ = db.From("test").Where(goqu.I("a").NotLike(regexp.MustCompile("(a|b)"))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").ILike("%a%")).Sql() + sql, _ = db.From("test").Where(goqu.I("a").ILike("%a%")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").ILike(regexp.MustCompile("(a|b)"))).Sql() + sql, _ = db.From("test").Where(goqu.I("a").ILike(regexp.MustCompile("(a|b)"))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").NotILike("%a%")).Sql() + sql, _ = db.From("test").Where(goqu.I("a").NotILike("%a%")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").NotILike(regexp.MustCompile("(a|b)"))).Sql() + sql, _ = db.From("test").Where(goqu.I("a").NotILike(regexp.MustCompile("(a|b)"))).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" WHERE ("a" LIKE '%a%') @@ -228,28 +247,29 @@ func ExampleStringMethods() { } func ExampleBooleanMethods() { - sql, _ := goqu.From("test").Where(goqu.I("a").Is(nil)).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Where(goqu.I("a").Is(nil)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").Is(true)).Sql() + sql, _ = db.From("test").Where(goqu.I("a").Is(true)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").Is(false)).Sql() + sql, _ = db.From("test").Where(goqu.I("a").Is(false)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").IsNot(nil)).Sql() + sql, _ = db.From("test").Where(goqu.I("a").IsNot(nil)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").IsNot(true)).Sql() + sql, _ = db.From("test").Where(goqu.I("a").IsNot(true)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").IsNull(), goqu.I("b").IsNull()).Sql() + sql, _ = db.From("test").Where(goqu.I("a").IsNull(), goqu.I("b").IsNull()).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").IsTrue(), goqu.I("b").IsNotTrue()).Sql() + sql, _ = db.From("test").Where(goqu.I("a").IsTrue(), goqu.I("b").IsNotTrue()).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.I("a").IsFalse(), goqu.I("b").IsNotFalse()).Sql() + sql, _ = db.From("test").Where(goqu.I("a").IsFalse(), goqu.I("b").IsNotFalse()).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" WHERE ("a" IS NULL) @@ -263,34 +283,45 @@ func ExampleBooleanMethods() { } func ExampleCastMethods() { - sql, _ := goqu.From("test").Where(goqu.I("json1").Cast("TEXT").Neq(goqu.I("json2").Cast("TEXT"))).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Where(goqu.I("json1").Cast("TEXT").Neq(goqu.I("json2").Cast("TEXT"))).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" WHERE (CAST("json1" AS TEXT) != CAST("json2" AS TEXT)) } func ExampleCast() { - sql, _ := goqu.From("test").Where(goqu.I("json1").Cast("TEXT").Neq(goqu.I("json2").Cast("TEXT"))).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Where(goqu.I("json1").Cast("TEXT").Neq(goqu.I("json2").Cast("TEXT"))).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" WHERE (CAST("json1" AS TEXT) != CAST("json2" AS TEXT)) } func ExampleDistinctMethods() { - sql, _ := goqu.From("test").Select(goqu.COUNT(goqu.I("a").Distinct())).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Select(goqu.COUNT(goqu.I("a").Distinct())).Sql() fmt.Println(sql) // Output: // SELECT COUNT(DISTINCT("a")) FROM "test" } func ExampleL() { - sql, _ := goqu.From("test").Where(goqu.L("a = 1")).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Where(goqu.L("a = 1")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.L("a = 1 AND (b = ? OR ? = ?)", "a", goqu.I("c"), 0.01)).Sql() + sql, _ = db.From("test").Where(goqu.L("a = 1 AND (b = ? OR ? = ?)", "a", goqu.I("c"), 0.01)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Where(goqu.L("(? AND ?) OR ?", goqu.I("a").Eq(1), goqu.I("b").Eq("b"), goqu.I("c").In([]string{"a", "b", "c"}))).Sql() + sql, _ = db.From("test").Where( + goqu.L( + "(? AND ?) OR ?", + goqu.I("a").Eq(1), + goqu.I("b").Eq("b"), + goqu.I("c").In([]string{"a", "b", "c"}), + ), + ).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" WHERE a = 1 @@ -299,40 +330,64 @@ func ExampleL() { } func ExampleOn() { - sql, _ := goqu.From("test").Join(goqu.I("my_table"), goqu.On(goqu.I("my_table.fkey").Eq(goqu.I("test.id")))).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Join( + goqu.I("my_table"), + goqu.On(goqu.I("my_table.fkey").Eq(goqu.I("test.id"))), + ).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" INNER JOIN "my_table" ON ("my_table"."fkey" = "test"."id") } func ExampleUsing() { - sql, _ := goqu.From("test").Join(goqu.I("my_table"), goqu.Using(goqu.I("common_column"))).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Join(goqu.I("my_table"), goqu.Using(goqu.I("common_column"))).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" INNER JOIN "my_table" USING ("common_column") } func ExampleDataset_ToUpdateSql() { + db := goqu.New("default", driver) type item struct { Address string `db:"address"` Name string `db:"name"` } - sql, args, _ := goqu.From("items").ToUpdateSql(false, item{Name: "Test", Address: "111 Test Addr"}) + sql, args, _ := db.From("items").ToUpdateSql( + false, + item{Name: "Test", Address: "111 Test Addr"}, + ) fmt.Printf("\n%s %+v)", sql, args) - sql, args, _ = goqu.From("items").ToUpdateSql(true, item{Name: "Test", Address: "111 Test Addr"}) + sql, args, _ = db.From("items").ToUpdateSql( + true, + item{Name: "Test", Address: "111 Test Addr"}, + ) fmt.Printf("\n%s %+v)", sql, args) - sql, args, _ = goqu.From("items").ToUpdateSql(false, goqu.Record{"name": "Test", "address": "111 Test Addr"}) + sql, args, _ = db.From("items").ToUpdateSql( + false, + goqu.Record{"name": "Test", "address": "111 Test Addr"}, + ) fmt.Printf("\n%s %+v)", sql, args) - sql, args, _ = goqu.From("items").ToUpdateSql(true, goqu.Record{"name": "Test", "address": "111 Test Addr"}) + sql, args, _ = db.From("items").ToUpdateSql( + true, + goqu.Record{"name": "Test", "address": "111 Test Addr"}, + ) fmt.Printf("\n%s %+v)", sql, args) - sql, args, _ = goqu.From("items").ToUpdateSql(false, map[string]interface{}{"name": "Test", "address": "111 Test Addr"}) + sql, args, _ = db.From("items").ToUpdateSql( + false, + map[string]interface{}{"name": "Test", "address": "111 Test Addr"}, + ) fmt.Printf("\n%s %+v)", sql, args) - sql, args, _ = goqu.From("items").ToUpdateSql(true, map[string]interface{}{"name": "Test", "address": "111 Test Addr"}) + sql, args, _ = db.From("items").ToUpdateSql( + true, + map[string]interface{}{"name": "Test", "address": "111 Test Addr"}, + ) fmt.Printf("\n%s %+v)", sql, args) // Output: // UPDATE "items" SET "address"='111 Test Addr',"name"='Test' []) @@ -344,14 +399,15 @@ func ExampleDataset_ToUpdateSql() { } func ExampleDataset_UpdateSql() { + db := goqu.New("default", driver) type item struct { Address string `db:"address"` Name string `db:"name"` } - sql, _ := goqu.From("items").UpdateSql(item{Name: "Test", Address: "111 Test Addr"}) + sql, _ := db.From("items").UpdateSql(item{Name: "Test", Address: "111 Test Addr"}) fmt.Println(sql) - sql, _ = goqu.From("items").UpdateSql(goqu.Record{"name": "Test", "address": "111 Test Addr"}) + sql, _ = db.From("items").UpdateSql(goqu.Record{"name": "Test", "address": "111 Test Addr"}) fmt.Println(sql) // Output: // UPDATE "items" SET "address"='111 Test Addr',"name"='Test' @@ -359,11 +415,12 @@ func ExampleDataset_UpdateSql() { } func ExampleDataset_ToSql() { - sql, args, _ := goqu.From("items").Where(goqu.I("a").Eq(1)).ToSql(false) + db := goqu.New("default", driver) + sql, args, _ := db.From("items").Where(goqu.I("a").Eq(1)).ToSql(false) fmt.Printf("\n%s %+v)", sql, args) // Output: - sql, args, _ = goqu.From("items").Where(goqu.I("a").Eq(1)).ToSql(true) + sql, args, _ = db.From("items").Where(goqu.I("a").Eq(1)).ToSql(true) fmt.Printf("\n%s %+v)", sql, args) // Output: // SELECT * FROM "items" WHERE ("a" = 1) []) @@ -371,24 +428,33 @@ func ExampleDataset_ToSql() { } func ExampleDataset_Sql() { - sql, _ := goqu.From("items").Where(goqu.I("a").Eq(1)).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("items").Where(goqu.I("a").Eq(1)).Sql() fmt.Println(sql) // Output: SELECT * FROM "items" WHERE ("a" = 1) } func ExampleDataset_As() { - ds := goqu.From("test").As("t") - sql, _ := goqu.From(ds).Sql() + db := goqu.New("default", driver) + ds := db.From("test").As("t") + sql, _ := db.From(ds).Sql() fmt.Println(sql) // Output: SELECT * FROM (SELECT * FROM "test") AS "t" } func ExampleDataset_Returning() { - sql, _ := goqu.From("test").Returning("id").InsertSql(goqu.Record{"a": "a", "b": "b"}) + db := goqu.New("default", driver) + sql, _ := db.From("test"). + Returning("id"). + InsertSql(goqu.Record{"a": "a", "b": "b"}) fmt.Println(sql) - sql, _ = goqu.From("test").Returning(goqu.I("test.*")).InsertSql(goqu.Record{"a": "a", "b": "b"}) + sql, _ = db.From("test"). + Returning(goqu.I("test.*")). + InsertSql(goqu.Record{"a": "a", "b": "b"}) fmt.Println(sql) - sql, _ = goqu.From("test").Returning("a", "b").InsertSql(goqu.Record{"a": "a", "b": "b"}) + sql, _ = db.From("test"). + Returning("a", "b"). + InsertSql(goqu.Record{"a": "a", "b": "b"}) fmt.Println(sql) // Output: // INSERT INTO "test" ("a", "b") VALUES ('a', 'b') RETURNING "id" @@ -397,11 +463,21 @@ func ExampleDataset_Returning() { } func ExampleDataset_Union() { - sql, _ := goqu.From("test").Union(goqu.From("test2")).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test"). + Union(db.From("test2")). + Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Limit(1).Union(goqu.From("test2")).Sql() + sql, _ = db.From("test"). + Limit(1). + Union(db.From("test2")). + Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Limit(1).Union(goqu.From("test2").Order(goqu.I("id").Desc())).Sql() + sql, _ = db.From("test"). + Limit(1). + Union(db.From("test2"). + Order(goqu.I("id").Desc())). + Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" UNION (SELECT * FROM "test2") @@ -410,11 +486,21 @@ func ExampleDataset_Union() { } func ExampleDataset_UnionAll() { - sql, _ := goqu.From("test").UnionAll(goqu.From("test2")).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test"). + UnionAll(db.From("test2")). + Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Limit(1).UnionAll(goqu.From("test2")).Sql() + sql, _ = db.From("test"). + Limit(1). + UnionAll(db.From("test2")). + Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Limit(1).UnionAll(goqu.From("test2").Order(goqu.I("id").Desc())).Sql() + sql, _ = db.From("test"). + Limit(1). + UnionAll(db.From("test2"). + Order(goqu.I("id").Desc())). + Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" UNION ALL (SELECT * FROM "test2") @@ -423,11 +509,21 @@ func ExampleDataset_UnionAll() { } func ExampleDataset_Intersect() { - sql, _ := goqu.From("test").Intersect(goqu.From("test2")).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test"). + Intersect(db.From("test2")). + Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Limit(1).Intersect(goqu.From("test2")).Sql() + sql, _ = db.From("test"). + Limit(1). + Intersect(db.From("test2")). + Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Limit(1).Intersect(goqu.From("test2").Order(goqu.I("id").Desc())).Sql() + sql, _ = db.From("test"). + Limit(1). + Intersect(db.From("test2"). + Order(goqu.I("id").Desc())). + Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" INTERSECT (SELECT * FROM "test2") @@ -436,11 +532,22 @@ func ExampleDataset_Intersect() { } func ExampleDataset_IntersectAll() { - sql, _ := goqu.From("test").IntersectAll(goqu.From("test2")).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test"). + IntersectAll(db.From("test2")). + Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Limit(1).IntersectAll(goqu.From("test2")).Sql() + sql, _ = db.From("test"). + Limit(1). + IntersectAll(db.From("test2")). + Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Limit(1).IntersectAll(goqu.From("test2").Order(goqu.I("id").Desc())).Sql() + sql, _ = goqu. + From("test"). + Limit(1). + IntersectAll(db.From("test2"). + Order(goqu.I("id").Desc())). + Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" INTERSECT ALL (SELECT * FROM "test2") @@ -449,15 +556,21 @@ func ExampleDataset_IntersectAll() { } func ExampleDataset_ClearOffset() { - ds := goqu.From("test").Offset(2) - sql, _ := ds.ClearOffset().Sql() + db := goqu.New("default", driver) + ds := db.From("test"). + Offset(2) + sql, _ := ds. + ClearOffset(). + Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" } func ExampleDataset_Offset() { - ds := goqu.From("test").Offset(2) + db := goqu.New("default", driver) + ds := db.From("test"). + Offset(2) sql, _ := ds.Sql() fmt.Println(sql) // Output: @@ -465,7 +578,8 @@ func ExampleDataset_Offset() { } func ExampleDataset_Limit() { - ds := goqu.From("test").Limit(10) + db := goqu.New("default", driver) + ds := db.From("test").Limit(10) sql, _ := ds.Sql() fmt.Println(sql) // Output: @@ -473,7 +587,8 @@ func ExampleDataset_Limit() { } func ExampleDataset_LimitAll() { - ds := goqu.From("test").LimitAll() + db := goqu.New("default", driver) + ds := db.From("test").LimitAll() sql, _ := ds.Sql() fmt.Println(sql) // Output: @@ -481,7 +596,8 @@ func ExampleDataset_LimitAll() { } func ExampleDataset_ClearLimit() { - ds := goqu.From("test").Limit(10) + db := goqu.New("default", driver) + ds := db.From("test").Limit(10) sql, _ := ds.ClearLimit().Sql() fmt.Println(sql) // Output: @@ -489,7 +605,9 @@ func ExampleDataset_ClearLimit() { } func ExampleDataset_Order() { - ds := goqu.From("test").Order(goqu.I("a").Asc()) + db := goqu.New("default", driver) + ds := db.From("test"). + Order(goqu.I("a").Asc()) sql, _ := ds.Sql() fmt.Println(sql) // Output: @@ -497,7 +615,8 @@ func ExampleDataset_Order() { } func ExampleDataset_OrderAppend() { - ds := goqu.From("test").Order(goqu.I("a").Asc()) + db := goqu.New("default", driver) + ds := db.From("test").Order(goqu.I("a").Asc()) sql, _ := ds.OrderAppend(goqu.I("b").Desc().NullsLast()).Sql() fmt.Println(sql) // Output: @@ -505,7 +624,8 @@ func ExampleDataset_OrderAppend() { } func ExampleDataset_ClearOrder() { - ds := goqu.From("test").Order(goqu.I("a").Asc()) + db := goqu.New("default", driver) + ds := db.From("test").Order(goqu.I("a").Asc()) sql, _ := ds.ClearOrder().Sql() fmt.Println(sql) // Output: @@ -513,9 +633,10 @@ func ExampleDataset_ClearOrder() { } func ExampleDataset_Having() { - sql, _ := goqu.From("test").Having(goqu.SUM("income").Gt(1000)).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Having(goqu.SUM("income").Gt(1000)).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").GroupBy("age").Having(goqu.SUM("income").Gt(1000)).Sql() + sql, _ = db.From("test").GroupBy("age").Having(goqu.SUM("income").Gt(1000)).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" HAVING (SUM("income") > 1000) @@ -523,8 +644,9 @@ func ExampleDataset_Having() { } func ExampleDataset_Where() { + db := goqu.New("default", driver) //By default everyting is added together - sql, _ := goqu.From("test").Where( + sql, _ := db.From("test").Where( goqu.I("a").Gt(10), goqu.I("b").Lt(10), goqu.I("c").IsNull(), @@ -532,7 +654,7 @@ func ExampleDataset_Where() { fmt.Println(sql) //You can use a combination of Ors and Ands - sql, _ = goqu.From("test").Where( + sql, _ = db.From("test").Where( goqu.Or( goqu.I("a").Gt(10), goqu.And( @@ -548,7 +670,8 @@ func ExampleDataset_Where() { } func ExampleDataset_ClearWhere() { - ds := goqu.From("test").Where( + db := goqu.New("default", driver) + ds := db.From("test").Where( goqu.Or( goqu.I("a").Gt(10), goqu.And( @@ -564,13 +687,14 @@ func ExampleDataset_ClearWhere() { } func ExampleDataset_Join() { - sql, _ := goqu.From("test").Join(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Join(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Join(goqu.I("test2"), goqu.Using("common_column")).Sql() + sql, _ = db.From("test").Join(goqu.I("test2"), goqu.Using("common_column")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Join(goqu.From("test2").Where(goqu.I("amount").Gt(0)), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() + sql, _ = db.From("test").Join(db.From("test2").Where(goqu.I("amount").Gt(0)), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").Join(goqu.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("t.Id")))).Sql() + sql, _ = db.From("test").Join(db.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("t.Id")))).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" INNER JOIN "test2" ON ("test"."fkey" = "test2"."Id") @@ -581,13 +705,14 @@ func ExampleDataset_Join() { } func ExampleDataset_InnerJoin() { - sql, _ := goqu.From("test").InnerJoin(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").InnerJoin(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").InnerJoin(goqu.I("test2"), goqu.Using("common_column")).Sql() + sql, _ = db.From("test").InnerJoin(goqu.I("test2"), goqu.Using("common_column")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").InnerJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() + sql, _ = db.From("test").InnerJoin(db.From("test2").Where(goqu.I("amount").Gt(0)), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").InnerJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("t.Id")))).Sql() + sql, _ = db.From("test").InnerJoin(db.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("t.Id")))).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" INNER JOIN "test2" ON ("test"."fkey" = "test2"."Id") @@ -596,13 +721,14 @@ func ExampleDataset_InnerJoin() { // SELECT * FROM "test" INNER JOIN (SELECT * FROM "test2" WHERE ("amount" > 0)) AS "t" ON ("test"."fkey" = "t"."Id") } func ExampleDataset_FullOuterJoin() { - sql, _ := goqu.From("test").FullOuterJoin(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").FullOuterJoin(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").FullOuterJoin(goqu.I("test2"), goqu.Using("common_column")).Sql() + sql, _ = db.From("test").FullOuterJoin(goqu.I("test2"), goqu.Using("common_column")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").FullOuterJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() + sql, _ = db.From("test").FullOuterJoin(db.From("test2").Where(goqu.I("amount").Gt(0)), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").FullOuterJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("t.Id")))).Sql() + sql, _ = db.From("test").FullOuterJoin(db.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("t.Id")))).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" FULL OUTER JOIN "test2" ON ("test"."fkey" = "test2"."Id") @@ -611,17 +737,18 @@ func ExampleDataset_FullOuterJoin() { // SELECT * FROM "test" FULL OUTER JOIN (SELECT * FROM "test2" WHERE ("amount" > 0)) AS "t" ON ("test"."fkey" = "t"."Id") } func ExampleDataset_RightOuterJoin() { - sql, _ := goqu.From("test").RightOuterJoin(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").RightOuterJoin(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").RightOuterJoin(goqu.I("test2"), goqu.Using("common_column")).Sql() + sql, _ = db.From("test").RightOuterJoin(goqu.I("test2"), goqu.Using("common_column")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").RightOuterJoin( - goqu.From("test2").Where(goqu.I("amount").Gt(0)), + sql, _ = db.From("test").RightOuterJoin( + db.From("test2").Where(goqu.I("amount").Gt(0)), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id"))), ).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").RightOuterJoin( - goqu.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), + sql, _ = db.From("test").RightOuterJoin( + db.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("t.Id"))), ).Sql() fmt.Println(sql) @@ -632,13 +759,14 @@ func ExampleDataset_RightOuterJoin() { // SELECT * FROM "test" RIGHT OUTER JOIN (SELECT * FROM "test2" WHERE ("amount" > 0)) AS "t" ON ("test"."fkey" = "t"."Id") } func ExampleDataset_LeftOuterJoin() { - sql, _ := goqu.From("test").LeftOuterJoin(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").LeftOuterJoin(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").LeftOuterJoin(goqu.I("test2"), goqu.Using("common_column")).Sql() + sql, _ = db.From("test").LeftOuterJoin(goqu.I("test2"), goqu.Using("common_column")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").LeftOuterJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() + sql, _ = db.From("test").LeftOuterJoin(db.From("test2").Where(goqu.I("amount").Gt(0)), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").LeftOuterJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("t.Id")))).Sql() + sql, _ = db.From("test").LeftOuterJoin(db.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("t.Id")))).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" LEFT OUTER JOIN "test2" ON ("test"."fkey" = "test2"."Id") @@ -647,13 +775,14 @@ func ExampleDataset_LeftOuterJoin() { // SELECT * FROM "test" LEFT OUTER JOIN (SELECT * FROM "test2" WHERE ("amount" > 0)) AS "t" ON ("test"."fkey" = "t"."Id") } func ExampleDataset_FullJoin() { - sql, _ := goqu.From("test").FullJoin(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").FullJoin(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").FullJoin(goqu.I("test2"), goqu.Using("common_column")).Sql() + sql, _ = db.From("test").FullJoin(goqu.I("test2"), goqu.Using("common_column")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").FullJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() + sql, _ = db.From("test").FullJoin(db.From("test2").Where(goqu.I("amount").Gt(0)), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").FullJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("t.Id")))).Sql() + sql, _ = db.From("test").FullJoin(db.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("t.Id")))).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" FULL JOIN "test2" ON ("test"."fkey" = "test2"."Id") @@ -662,13 +791,14 @@ func ExampleDataset_FullJoin() { // SELECT * FROM "test" FULL JOIN (SELECT * FROM "test2" WHERE ("amount" > 0)) AS "t" ON ("test"."fkey" = "t"."Id") } func ExampleDataset_RightJoin() { - sql, _ := goqu.From("test").RightJoin(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").RightJoin(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").RightJoin(goqu.I("test2"), goqu.Using("common_column")).Sql() + sql, _ = db.From("test").RightJoin(goqu.I("test2"), goqu.Using("common_column")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").RightJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() + sql, _ = db.From("test").RightJoin(db.From("test2").Where(goqu.I("amount").Gt(0)), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").RightJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("t.Id")))).Sql() + sql, _ = db.From("test").RightJoin(db.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("t.Id")))).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" RIGHT JOIN "test2" ON ("test"."fkey" = "test2"."Id") @@ -677,13 +807,14 @@ func ExampleDataset_RightJoin() { // SELECT * FROM "test" RIGHT JOIN (SELECT * FROM "test2" WHERE ("amount" > 0)) AS "t" ON ("test"."fkey" = "t"."Id") } func ExampleDataset_LeftJoin() { - sql, _ := goqu.From("test").LeftJoin(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").LeftJoin(goqu.I("test2"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").LeftJoin(goqu.I("test2"), goqu.Using("common_column")).Sql() + sql, _ = db.From("test").LeftJoin(goqu.I("test2"), goqu.Using("common_column")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").LeftJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() + sql, _ = db.From("test").LeftJoin(db.From("test2").Where(goqu.I("amount").Gt(0)), goqu.On(goqu.I("test.fkey").Eq(goqu.I("test2.Id")))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").LeftJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("t.Id")))).Sql() + sql, _ = db.From("test").LeftJoin(db.From("test2").Where(goqu.I("amount").Gt(0)).As("t"), goqu.On(goqu.I("test.fkey").Eq(goqu.I("t.Id")))).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" LEFT JOIN "test2" ON ("test"."fkey" = "test2"."Id") @@ -692,11 +823,12 @@ func ExampleDataset_LeftJoin() { // SELECT * FROM "test" LEFT JOIN (SELECT * FROM "test2" WHERE ("amount" > 0)) AS "t" ON ("test"."fkey" = "t"."Id") } func ExampleDataset_NaturalJoin() { - sql, _ := goqu.From("test").NaturalJoin(goqu.I("test2")).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").NaturalJoin(goqu.I("test2")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").NaturalJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0))).Sql() + sql, _ = db.From("test").NaturalJoin(db.From("test2").Where(goqu.I("amount").Gt(0))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").NaturalJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)).As("t")).Sql() + sql, _ = db.From("test").NaturalJoin(db.From("test2").Where(goqu.I("amount").Gt(0)).As("t")).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" NATURAL JOIN "test2" @@ -704,11 +836,12 @@ func ExampleDataset_NaturalJoin() { // SELECT * FROM "test" NATURAL JOIN (SELECT * FROM "test2" WHERE ("amount" > 0)) AS "t" } func ExampleDataset_NaturalLeftJoin() { - sql, _ := goqu.From("test").NaturalLeftJoin(goqu.I("test2")).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").NaturalLeftJoin(goqu.I("test2")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").NaturalLeftJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0))).Sql() + sql, _ = db.From("test").NaturalLeftJoin(db.From("test2").Where(goqu.I("amount").Gt(0))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").NaturalLeftJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)).As("t")).Sql() + sql, _ = db.From("test").NaturalLeftJoin(db.From("test2").Where(goqu.I("amount").Gt(0)).As("t")).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" NATURAL LEFT JOIN "test2" @@ -716,11 +849,12 @@ func ExampleDataset_NaturalLeftJoin() { // SELECT * FROM "test" NATURAL LEFT JOIN (SELECT * FROM "test2" WHERE ("amount" > 0)) AS "t" } func ExampleDataset_NaturalRightJoin() { - sql, _ := goqu.From("test").NaturalRightJoin(goqu.I("test2")).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").NaturalRightJoin(goqu.I("test2")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").NaturalRightJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0))).Sql() + sql, _ = db.From("test").NaturalRightJoin(db.From("test2").Where(goqu.I("amount").Gt(0))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").NaturalRightJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)).As("t")).Sql() + sql, _ = db.From("test").NaturalRightJoin(db.From("test2").Where(goqu.I("amount").Gt(0)).As("t")).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" NATURAL RIGHT JOIN "test2" @@ -728,11 +862,12 @@ func ExampleDataset_NaturalRightJoin() { // SELECT * FROM "test" NATURAL RIGHT JOIN (SELECT * FROM "test2" WHERE ("amount" > 0)) AS "t" } func ExampleDataset_NaturalFullJoin() { - sql, _ := goqu.From("test").NaturalFullJoin(goqu.I("test2")).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").NaturalFullJoin(goqu.I("test2")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").NaturalFullJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0))).Sql() + sql, _ = db.From("test").NaturalFullJoin(db.From("test2").Where(goqu.I("amount").Gt(0))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").NaturalFullJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)).As("t")).Sql() + sql, _ = db.From("test").NaturalFullJoin(db.From("test2").Where(goqu.I("amount").Gt(0)).As("t")).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" NATURAL FULL JOIN "test2" @@ -741,11 +876,12 @@ func ExampleDataset_NaturalFullJoin() { } func ExampleDataset_CrossJoin() { - sql, _ := goqu.From("test").CrossJoin(goqu.I("test2")).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").CrossJoin(goqu.I("test2")).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").CrossJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0))).Sql() + sql, _ = db.From("test").CrossJoin(db.From("test2").Where(goqu.I("amount").Gt(0))).Sql() fmt.Println(sql) - sql, _ = goqu.From("test").CrossJoin(goqu.From("test2").Where(goqu.I("amount").Gt(0)).As("t")).Sql() + sql, _ = db.From("test").CrossJoin(db.From("test2").Where(goqu.I("amount").Gt(0)).As("t")).Sql() fmt.Println(sql) // Output: // SELECT * FROM "test" CROSS JOIN "test2" @@ -754,9 +890,10 @@ func ExampleDataset_CrossJoin() { } func ExampleDataset_FromSelf() { - sql, _ := goqu.From("test").FromSelf().Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").FromSelf().Sql() fmt.Println(sql) - sql, _ = goqu.From("test").As("my_test_table").FromSelf().Sql() + sql, _ = db.From("test").As("my_test_table").FromSelf().Sql() fmt.Println(sql) // Output: // SELECT * FROM (SELECT * FROM "test") AS "t1" @@ -764,7 +901,8 @@ func ExampleDataset_FromSelf() { } func ExampleDataset_From() { - ds := goqu.From("test") + db := goqu.New("default", driver) + ds := db.From("test") sql, _ := ds.From("test2").Sql() fmt.Println(sql) // Output: @@ -772,7 +910,8 @@ func ExampleDataset_From() { } func ExampleDataset_From_withDataset() { - ds := goqu.From("test") + db := goqu.New("default", driver) + ds := db.From("test") fromDs := ds.Where(goqu.I("age").Gt(10)) sql, _ := ds.From(fromDs).Sql() fmt.Println(sql) @@ -781,7 +920,8 @@ func ExampleDataset_From_withDataset() { } func ExampleDataset_From_withAliasedDataset() { - ds := goqu.From("test") + db := goqu.New("default", driver) + ds := db.From("test") fromDs := ds.Where(goqu.I("age").Gt(10)) sql, _ := ds.From(fromDs.As("test2")).Sql() fmt.Println(sql) @@ -790,14 +930,16 @@ func ExampleDataset_From_withAliasedDataset() { } func ExampleDataset_Select() { - sql, _ := goqu.From("test").Select("a", "b", "c").Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Select("a", "b", "c").Sql() fmt.Println(sql) // Output: // SELECT "a", "b", "c" FROM "test" } func ExampleDataset_Select_withDataset() { - ds := goqu.From("test") + db := goqu.New("default", driver) + ds := db.From("test") fromDs := ds.Select("age").Where(goqu.I("age").Gt(10)) sql, _ := ds.From().Select(fromDs).Sql() fmt.Println(sql) @@ -806,7 +948,8 @@ func ExampleDataset_Select_withDataset() { } func ExampleDataset_Select_withAliasedDataset() { - ds := goqu.From("test") + db := goqu.New("default", driver) + ds := db.From("test") fromDs := ds.Select("age").Where(goqu.I("age").Gt(10)) sql, _ := ds.From().Select(fromDs.As("ages")).Sql() fmt.Println(sql) @@ -815,14 +958,16 @@ func ExampleDataset_Select_withAliasedDataset() { } func ExampleDataset_Select_withLiteral() { - sql, _ := goqu.From("test").Select(goqu.L("a + b").As("sum")).Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").Select(goqu.L("a + b").As("sum")).Sql() fmt.Println(sql) // Output: // SELECT a + b AS "sum" FROM "test" } func ExampleDataset_Select_withSqlFunctionExpression() { - sql, _ := goqu.From("test").Select( + db := goqu.New("default", driver) + sql, _ := db.From("test").Select( goqu.COUNT("*").As("age_count"), goqu.MAX("age").As("max_age"), goqu.AVG("age").As("avg_age"), @@ -833,17 +978,19 @@ func ExampleDataset_Select_withSqlFunctionExpression() { } func ExampleDataset_SelectDistinct() { - sql, _ := goqu.From("test").SelectDistinct("a", "b").Sql() + db := goqu.New("default", driver) + sql, _ := db.From("test").SelectDistinct("a", "b").Sql() fmt.Println(sql) // Output: // SELECT DISTINCT "a", "b" FROM "test" } func ExampleDataset_SelectAppend() { - ds := goqu.From("test").Select("a", "b") + db := goqu.New("default", driver) + ds := db.From("test").Select("a", "b") sql, _ := ds.SelectAppend("c").Sql() fmt.Println(sql) - ds = goqu.From("test").SelectDistinct("a", "b") + ds = db.From("test").SelectDistinct("a", "b") sql, _ = ds.SelectAppend("c").Sql() fmt.Println(sql) // Output: @@ -852,10 +999,11 @@ func ExampleDataset_SelectAppend() { } func ExampleDataset_ClearSelect() { - ds := goqu.From("test").Select("a", "b") + db := goqu.New("default", driver) + ds := db.From("test").Select("a", "b") sql, _ := ds.ClearSelect().Sql() fmt.Println(sql) - ds = goqu.From("test").SelectDistinct("a", "b") + ds = db.From("test").SelectDistinct("a", "b") sql, _ = ds.ClearSelect().Sql() fmt.Println(sql) // Output: @@ -864,26 +1012,27 @@ func ExampleDataset_ClearSelect() { } func ExampleDataset_ToInsertSql() { + db := goqu.New("default", driver) type item struct { Id uint32 `db:"id" goqu:"skipinsert"` Address string `db:"address"` Name string `db:"name"` } - sql, args, _ := goqu.From("items").ToInsertSql( + sql, args, _ := db.From("items").ToInsertSql( false, item{Name: "Test1", Address: "111 Test Addr"}, item{Name: "Test2", Address: "112 Test Addr"}, ) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").ToInsertSql( + sql, args, _ = db.From("items").ToInsertSql( false, goqu.Record{"name": "Test1", "address": "111 Test Addr"}, goqu.Record{"name": "Test2", "address": "112 Test Addr"}, ) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").ToInsertSql( + sql, args, _ = db.From("items").ToInsertSql( false, []item{ {Name: "Test1", Address: "111 Test Addr"}, @@ -891,28 +1040,28 @@ func ExampleDataset_ToInsertSql() { }) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").ToInsertSql( + sql, args, _ = db.From("items").ToInsertSql( false, []goqu.Record{ {"name": "Test1", "address": "111 Test Addr"}, {"name": "Test2", "address": "112 Test Addr"}, }) - sql, args, _ = goqu.From("items").ToInsertSql( + sql, args, _ = db.From("items").ToInsertSql( true, item{Name: "Test1", Address: "111 Test Addr"}, item{Name: "Test2", Address: "112 Test Addr"}, ) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").ToInsertSql( + sql, args, _ = db.From("items").ToInsertSql( true, goqu.Record{"name": "Test1", "address": "111 Test Addr"}, goqu.Record{"name": "Test2", "address": "112 Test Addr"}, ) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").ToInsertSql( + sql, args, _ = db.From("items").ToInsertSql( true, []item{ {Name: "Test1", Address: "111 Test Addr"}, @@ -920,7 +1069,7 @@ func ExampleDataset_ToInsertSql() { }) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").ToInsertSql( + sql, args, _ = db.From("items").ToInsertSql( true, []goqu.Record{ {"name": "Test1", "address": "111 Test Addr"}, @@ -938,30 +1087,31 @@ func ExampleDataset_ToInsertSql() { } func ExampleDataset_InsertSql() { + db := goqu.New("default", driver) type item struct { Id uint32 `db:"id" goqu:"skipinsert"` Address string `db:"address"` Name string `db:"name"` } - sql, _ := goqu.From("items").InsertSql( + sql, _ := db.From("items").InsertSql( item{Name: "Test1", Address: "111 Test Addr"}, item{Name: "Test2", Address: "112 Test Addr"}, ) fmt.Println(sql) - sql, _ = goqu.From("items").InsertSql( + sql, _ = db.From("items").InsertSql( goqu.Record{"name": "Test1", "address": "111 Test Addr"}, goqu.Record{"name": "Test2", "address": "112 Test Addr"}, ) fmt.Println(sql) - sql, _ = goqu.From("items").InsertSql([]item{ + sql, _ = db.From("items").InsertSql([]item{ {Name: "Test1", Address: "111 Test Addr"}, {Name: "Test2", Address: "112 Test Addr"}, }) fmt.Println(sql) - sql, _ = goqu.From("items").InsertSql([]goqu.Record{ + sql, _ = db.From("items").InsertSql([]goqu.Record{ {"name": "Test1", "address": "111 Test Addr"}, {"name": "Test2", "address": "112 Test Addr"}, }) @@ -974,13 +1124,18 @@ func ExampleDataset_InsertSql() { } func ExampleDataset_ToDeleteSql() { - sql, args, _ := goqu.From("items").ToDeleteSql(false) + db := goqu.New("default", driver) + sql, args, _ := db.From("items").ToDeleteSql(false) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").Where(goqu.I("id").Gt(10)).ToDeleteSql(false) + sql, args, _ = db.From("items"). + Where(goqu.I("id").Gt(10)). + ToDeleteSql(false) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").Where(goqu.I("id").Gt(10)).ToDeleteSql(true) + sql, args, _ = db.From("items"). + Where(goqu.I("id").Gt(10)). + ToDeleteSql(true) fmt.Printf("\n%s %+v", sql, args) // Output: @@ -990,10 +1145,13 @@ func ExampleDataset_ToDeleteSql() { } func ExampleDataset_DeleteSql() { - sql, _ := goqu.From("items").DeleteSql() + db := goqu.New("default", driver) + sql, _ := db.From("items").DeleteSql() fmt.Println(sql) - sql, _ = goqu.From("items").Where(goqu.I("id").Gt(10)).DeleteSql() + sql, _ = db.From("items"). + Where(goqu.I("id").Gt(10)). + DeleteSql() fmt.Println(sql) // Output: @@ -1002,23 +1160,33 @@ func ExampleDataset_DeleteSql() { } func ExampleDataset_ToTruncateSql() { - sql, args, _ := goqu.From("items").ToTruncateSql(false, goqu.TruncateOptions{}) + db := goqu.New("default", driver) + sql, args, _ := db.From("items"). + ToTruncateSql(false, goqu.TruncateOptions{}) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").ToTruncateSql(false, goqu.TruncateOptions{Cascade: true}) + sql, args, _ = db.From("items"). + ToTruncateSql(false, goqu.TruncateOptions{Cascade: true}) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").ToTruncateSql(false, goqu.TruncateOptions{Restrict: true}) + sql, args, _ = db.From("items"). + ToTruncateSql(false, goqu.TruncateOptions{Restrict: true}) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").ToTruncateSql(false, goqu.TruncateOptions{Identity: "RESTART"}) + sql, args, _ = db.From("items"). + ToTruncateSql(false, goqu.TruncateOptions{Identity: "RESTART"}) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").ToTruncateSql(false, goqu.TruncateOptions{Identity: "RESTART", Cascade: true}) + sql, args, _ = db.From("items"). + ToTruncateSql(false, goqu.TruncateOptions{Identity: "RESTART", Cascade: true}) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").ToTruncateSql(false, goqu.TruncateOptions{Identity: "RESTART", Restrict: true}) + sql, args, _ = db.From("items"). + ToTruncateSql(false, goqu.TruncateOptions{Identity: "RESTART", Restrict: true}) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").ToTruncateSql(false, goqu.TruncateOptions{Identity: "CONTINUE"}) + sql, args, _ = db.From("items"). + ToTruncateSql(false, goqu.TruncateOptions{Identity: "CONTINUE"}) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").ToTruncateSql(false, goqu.TruncateOptions{Identity: "CONTINUE", Cascade: true}) + sql, args, _ = db.From("items"). + ToTruncateSql(false, goqu.TruncateOptions{Identity: "CONTINUE", Cascade: true}) fmt.Printf("\n%s %+v", sql, args) - sql, args, _ = goqu.From("items").ToTruncateSql(false, goqu.TruncateOptions{Identity: "CONTINUE", Restrict: true}) + sql, args, _ = db.From("items"). + ToTruncateSql(false, goqu.TruncateOptions{Identity: "CONTINUE", Restrict: true}) fmt.Printf("\n%s %+v", sql, args) // Output: // TRUNCATE "items" [] @@ -1033,30 +1201,41 @@ func ExampleDataset_ToTruncateSql() { } func ExampleDataset_TruncateSql() { - sql, _ := goqu.From("items").TruncateSql() + db := goqu.New("default", driver) + sql, _ := db.From("items").TruncateSql() fmt.Println(sql) // Output: // TRUNCATE "items" } func ExampleDataset_TruncateWithOptsSql() { - sql, _ := goqu.From("items").TruncateWithOptsSql(goqu.TruncateOptions{}) + db := goqu.New("default", driver) + sql, _ := db.From("items"). + TruncateWithOptsSql(goqu.TruncateOptions{}) fmt.Println(sql) - sql, _ = goqu.From("items").TruncateWithOptsSql(goqu.TruncateOptions{Cascade: true}) + sql, _ = db.From("items"). + TruncateWithOptsSql(goqu.TruncateOptions{Cascade: true}) fmt.Println(sql) - sql, _ = goqu.From("items").TruncateWithOptsSql(goqu.TruncateOptions{Restrict: true}) + sql, _ = db.From("items"). + TruncateWithOptsSql(goqu.TruncateOptions{Restrict: true}) fmt.Println(sql) - sql, _ = goqu.From("items").TruncateWithOptsSql(goqu.TruncateOptions{Identity: "RESTART"}) + sql, _ = db.From("items"). + TruncateWithOptsSql(goqu.TruncateOptions{Identity: "RESTART"}) fmt.Println(sql) - sql, _ = goqu.From("items").TruncateWithOptsSql(goqu.TruncateOptions{Identity: "RESTART", Cascade: true}) + sql, _ = db.From("items"). + TruncateWithOptsSql(goqu.TruncateOptions{Identity: "RESTART", Cascade: true}) fmt.Println(sql) - sql, _ = goqu.From("items").TruncateWithOptsSql(goqu.TruncateOptions{Identity: "RESTART", Restrict: true}) + sql, _ = db.From("items"). + TruncateWithOptsSql(goqu.TruncateOptions{Identity: "RESTART", Restrict: true}) fmt.Println(sql) - sql, _ = goqu.From("items").TruncateWithOptsSql(goqu.TruncateOptions{Identity: "CONTINUE"}) + sql, _ = db.From("items"). + TruncateWithOptsSql(goqu.TruncateOptions{Identity: "CONTINUE"}) fmt.Println(sql) - sql, _ = goqu.From("items").TruncateWithOptsSql(goqu.TruncateOptions{Identity: "CONTINUE", Cascade: true}) + sql, _ = db.From("items"). + TruncateWithOptsSql(goqu.TruncateOptions{Identity: "CONTINUE", Cascade: true}) fmt.Println(sql) - sql, _ = goqu.From("items").TruncateWithOptsSql(goqu.TruncateOptions{Identity: "CONTINUE", Restrict: true}) + sql, _ = db.From("items"). + TruncateWithOptsSql(goqu.TruncateOptions{Identity: "CONTINUE", Restrict: true}) fmt.Println(sql) // Output: