Skip to content

Commit

Permalink
feat: added QueryBuilder interface for SelectQuery, UpdateQuery, Dele…
Browse files Browse the repository at this point in the history
…teQuery (#499)

* added QueryBuilder interface for SelectQuery,UpdateQuery,DeleteQuery

* tests, compile time checks, replaced WhereGroups

* changed comment

* using returned value in WhereGroup
  • Loading branch information
derkan authored Mar 26, 2022
1 parent fbcb87b commit 59fef48
Show file tree
Hide file tree
Showing 131 changed files with 351 additions and 0 deletions.
72 changes: 72 additions & 0 deletions internal/dbtest/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,78 @@ func TestQuery(t *testing.T) {
}
return db.NewSelect().Where("x IN (?)", bun.In(values))
},
func(db *bun.DB) schema.QueryAppender {
return db.NewSelect().Query().
WhereGroup("", func(q bun.QueryBuilder) bun.QueryBuilder {
return q.Where("a = 1").Where("b = 1")
}).
WhereGroup(" OR ", func(q bun.QueryBuilder) bun.QueryBuilder {
return q.Where("a = 2").Where("b = 2")
})
},
func(db *bun.DB) schema.QueryAppender {
return db.NewSelect().Model(new(Model)).Query().Where("id = 42")
},
func(db *bun.DB) schema.QueryAppender {
return db.NewSelect().Model(new(Model)).Query().WhereOr("id = 42")
},
func(db *bun.DB) schema.QueryAppender {
return db.NewSelect().Model(new(SoftDelete1)).Query().WherePK()
},
func(db *bun.DB) schema.QueryAppender {
return db.NewSelect().Model(new(SoftDelete1)).Query().WhereDeleted()
},
func(db *bun.DB) schema.QueryAppender {
return db.NewSelect().Model(new(SoftDelete1)).Query().WhereAllWithDeleted()
},
func(db *bun.DB) schema.QueryAppender {
return db.NewUpdate().Model(new(SoftDelete1)).Query().WherePK().
WhereGroup("", func(q bun.QueryBuilder) bun.QueryBuilder {
return q.Where("a = 1").Where("b = 1")
}).
WhereGroup(" OR ", func(q bun.QueryBuilder) bun.QueryBuilder {
return q.Where("a = 2").Where("b = 2")
})
},
func(db *bun.DB) schema.QueryAppender {
return db.NewUpdate().Model(new(Model)).Query().Where("id = 42")
},
func(db *bun.DB) schema.QueryAppender {
return db.NewUpdate().Model(new(Model)).Query().WhereOr("id = 42")
},
func(db *bun.DB) schema.QueryAppender {
return db.NewUpdate().Model(new(SoftDelete1)).Query().WherePK()
},
func(db *bun.DB) schema.QueryAppender {
return db.NewUpdate().Model(new(SoftDelete1)).Query().WherePK().WhereDeleted()
},
func(db *bun.DB) schema.QueryAppender {
return db.NewUpdate().Model(new(SoftDelete1)).Query().WherePK().WhereAllWithDeleted()
},
func(db *bun.DB) schema.QueryAppender {
return db.NewDelete().Model(new(SoftDelete1)).Query().WherePK().
WhereGroup("", func(q bun.QueryBuilder) bun.QueryBuilder {
return q.Where("a = 1").Where("b = 1")
}).
WhereGroup(" OR ", func(q bun.QueryBuilder) bun.QueryBuilder {
return q.Where("a = 2").Where("b = 2")
})
},
func(db *bun.DB) schema.QueryAppender {
return db.NewDelete().Model(new(Model)).Query().Where("id = 42")
},
func(db *bun.DB) schema.QueryAppender {
return db.NewDelete().Model(new(Model)).Query().WhereOr("id = 42")
},
func(db *bun.DB) schema.QueryAppender {
return db.NewDelete().Model(new(SoftDelete1)).Query().WherePK()
},
func(db *bun.DB) schema.QueryAppender {
return db.NewDelete().Model(new(SoftDelete1)).Query().WherePK().WhereDeleted()
},
func(db *bun.DB) schema.QueryAppender {
return db.NewDelete().Model(new(SoftDelete1)).Query().WherePK().WhereAllWithDeleted()
},
}

timeRE := regexp.MustCompile(`'2\d{3}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d+)?(\+\d{2}:\d{2})?'`)
Expand Down
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-112
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-113
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id`, `model`.`str` FROM `models` AS `model` WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-114
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id`, `model`.`str` FROM `models` AS `model` WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-115
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `soft_delete`.`id`, `soft_delete`.`deleted_at` FROM `soft_deletes` AS `soft_delete` WHERE `soft_delete`.`deleted_at` IS NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-116
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `soft_delete`.`id`, `soft_delete`.`deleted_at` FROM `soft_deletes` AS `soft_delete` WHERE `soft_delete`.`deleted_at` IS NOT NULL
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-117
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `soft_delete`.`id`, `soft_delete`.`deleted_at` FROM `soft_deletes` AS `soft_delete`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-118
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `deleted_at` = NULL WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2)) AND `soft_delete`.`deleted_at` IS NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-119
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `models` AS `model` SET `str` = '' WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-120
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `models` AS `model` SET `str` = '' WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-121
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `deleted_at` = NULL WHERE `soft_delete`.`deleted_at` IS NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-122
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `deleted_at` = NULL WHERE `soft_delete`.`deleted_at` IS NOT NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-123
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `deleted_at` = NULL WHERE (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-124
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `soft_delete`.`deleted_at` = [TIME] WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2)) AND `soft_delete`.`deleted_at` IS NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-125
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM `models` WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-126
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM `models` WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-127
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `soft_delete`.`deleted_at` = [TIME] WHERE `soft_delete`.`deleted_at` IS NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-128
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `soft_delete`.`deleted_at` = [TIME] WHERE `soft_delete`.`deleted_at` IS NOT NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-129
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `soft_delete`.`deleted_at` = [TIME] WHERE (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-112
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-113
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "model"."id", "model"."str" FROM "models" AS "model" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-114
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "model"."id", "model"."str" FROM "models" AS "model" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-115
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "soft_delete"."id", "soft_delete"."deleted_at" FROM "soft_deletes" AS "soft_delete" WHERE "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-116
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "soft_delete"."id", "soft_delete"."deleted_at" FROM "soft_deletes" AS "soft_delete" WHERE "soft_delete"."deleted_at" IS NOT NULL
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-117
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "soft_delete"."id", "soft_delete"."deleted_at" FROM "soft_deletes" AS "soft_delete"
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-118
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" SET "deleted_at" = NULL WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2)) AND "soft_deletes"."deleted_at" IS NULL AND ("id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-119
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "models" SET "str" = '' WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-120
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "models" SET "str" = '' WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-121
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" SET "deleted_at" = NULL WHERE "soft_deletes"."deleted_at" IS NULL AND ("id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-122
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" SET "deleted_at" = NULL WHERE "soft_deletes"."deleted_at" IS NOT NULL AND ("id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-123
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" SET "deleted_at" = NULL WHERE ("id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-124
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" SET "deleted_at" = [TIME] WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2)) AND "soft_deletes"."deleted_at" IS NULL AND ("id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-125
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM "models" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-126
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM "models" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-127
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" SET "deleted_at" = [TIME] WHERE "soft_deletes"."deleted_at" IS NULL AND ("id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-128
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" SET "deleted_at" = [TIME] WHERE "soft_deletes"."deleted_at" IS NOT NULL AND ("id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-129
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" SET "deleted_at" = [TIME] WHERE ("id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-112
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-113
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id`, `model`.`str` FROM `models` AS `model` WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-114
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id`, `model`.`str` FROM `models` AS `model` WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-115
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `soft_delete`.`id`, `soft_delete`.`deleted_at` FROM `soft_deletes` AS `soft_delete` WHERE `soft_delete`.`deleted_at` IS NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-116
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `soft_delete`.`id`, `soft_delete`.`deleted_at` FROM `soft_deletes` AS `soft_delete` WHERE `soft_delete`.`deleted_at` IS NOT NULL
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-117
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `soft_delete`.`id`, `soft_delete`.`deleted_at` FROM `soft_deletes` AS `soft_delete`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-118
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `deleted_at` = NULL WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2)) AND `soft_delete`.`deleted_at` IS NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-119
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `models` AS `model` SET `str` = '' WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-120
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `models` AS `model` SET `str` = '' WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-121
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `deleted_at` = NULL WHERE `soft_delete`.`deleted_at` IS NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-122
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `deleted_at` = NULL WHERE `soft_delete`.`deleted_at` IS NOT NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-123
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `deleted_at` = NULL WHERE (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-124
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `soft_delete`.`deleted_at` = [TIME] WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2)) AND `soft_delete`.`deleted_at` IS NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-125
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM `models` WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-126
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM `models` WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-127
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `soft_delete`.`deleted_at` = [TIME] WHERE `soft_delete`.`deleted_at` IS NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-128
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `soft_delete`.`deleted_at` = [TIME] WHERE `soft_delete`.`deleted_at` IS NOT NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-129
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `soft_delete`.`deleted_at` = [TIME] WHERE (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-112
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-113
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id`, `model`.`str` FROM `models` AS `model` WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-114
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id`, `model`.`str` FROM `models` AS `model` WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-115
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `soft_delete`.`id`, `soft_delete`.`deleted_at` FROM `soft_deletes` AS `soft_delete` WHERE `soft_delete`.`deleted_at` IS NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-116
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `soft_delete`.`id`, `soft_delete`.`deleted_at` FROM `soft_deletes` AS `soft_delete` WHERE `soft_delete`.`deleted_at` IS NOT NULL
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-117
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `soft_delete`.`id`, `soft_delete`.`deleted_at` FROM `soft_deletes` AS `soft_delete`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-118
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `deleted_at` = NULL WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2)) AND `soft_delete`.`deleted_at` IS NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-119
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `models` AS `model` SET `str` = '' WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-120
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `models` AS `model` SET `str` = '' WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-121
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `deleted_at` = NULL WHERE `soft_delete`.`deleted_at` IS NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-122
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `deleted_at` = NULL WHERE `soft_delete`.`deleted_at` IS NOT NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-123
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `deleted_at` = NULL WHERE (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-124
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `soft_delete`.`deleted_at` = [TIME] WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2)) AND `soft_delete`.`deleted_at` IS NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-125
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM `models` AS `model` WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-126
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM `models` AS `model` WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-127
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `soft_delete`.`deleted_at` = [TIME] WHERE `soft_delete`.`deleted_at` IS NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-128
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `soft_delete`.`deleted_at` = [TIME] WHERE `soft_delete`.`deleted_at` IS NOT NULL AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-129
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `soft_deletes` AS `soft_delete` SET `soft_delete`.`deleted_at` = [TIME] WHERE (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-112
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-113
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "model"."id", "model"."str" FROM "models" AS "model" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-114
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "model"."id", "model"."str" FROM "models" AS "model" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-115
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "soft_delete"."id", "soft_delete"."deleted_at" FROM "soft_deletes" AS "soft_delete" WHERE "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-116
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "soft_delete"."id", "soft_delete"."deleted_at" FROM "soft_deletes" AS "soft_delete" WHERE "soft_delete"."deleted_at" IS NOT NULL
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-117
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "soft_delete"."id", "soft_delete"."deleted_at" FROM "soft_deletes" AS "soft_delete"
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-118
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = NULL WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2)) AND "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-119
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "models" AS "model" SET "str" = '' WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-120
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "models" AS "model" SET "str" = '' WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-121
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = NULL WHERE "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-122
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = NULL WHERE "soft_delete"."deleted_at" IS NOT NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-123
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = NULL WHERE ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-124
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = [TIME] WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2)) AND "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-125
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM "models" AS "model" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-126
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM "models" AS "model" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-127
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = [TIME] WHERE "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-128
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = [TIME] WHERE "soft_delete"."deleted_at" IS NOT NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-129
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = [TIME] WHERE ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-112
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-113
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "model"."id", "model"."str" FROM "models" AS "model" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-114
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "model"."id", "model"."str" FROM "models" AS "model" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-115
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "soft_delete"."id", "soft_delete"."deleted_at" FROM "soft_deletes" AS "soft_delete" WHERE "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-116
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "soft_delete"."id", "soft_delete"."deleted_at" FROM "soft_deletes" AS "soft_delete" WHERE "soft_delete"."deleted_at" IS NOT NULL
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-117
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "soft_delete"."id", "soft_delete"."deleted_at" FROM "soft_deletes" AS "soft_delete"
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-118
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = NULL WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2)) AND "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-119
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "models" AS "model" SET "str" = '' WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-120
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "models" AS "model" SET "str" = '' WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-121
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = NULL WHERE "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-122
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = NULL WHERE "soft_delete"."deleted_at" IS NOT NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-123
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = NULL WHERE ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-124
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = [TIME] WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2)) AND "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-125
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM "models" AS "model" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-126
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM "models" AS "model" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-127
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = [TIME] WHERE "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-128
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = [TIME] WHERE "soft_delete"."deleted_at" IS NOT NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-129
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = [TIME] WHERE ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-112
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-113
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "model"."id", "model"."str" FROM "models" AS "model" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-114
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "model"."id", "model"."str" FROM "models" AS "model" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-115
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "soft_delete"."id", "soft_delete"."deleted_at" FROM "soft_deletes" AS "soft_delete" WHERE "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-116
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "soft_delete"."id", "soft_delete"."deleted_at" FROM "soft_deletes" AS "soft_delete" WHERE "soft_delete"."deleted_at" IS NOT NULL
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-117
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT "soft_delete"."id", "soft_delete"."deleted_at" FROM "soft_deletes" AS "soft_delete"
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-118
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = NULL WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2)) AND "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-119
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "models" AS "model" SET "str" = '' WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-120
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "models" AS "model" SET "str" = '' WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-121
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = NULL WHERE "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-122
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = NULL WHERE "soft_delete"."deleted_at" IS NOT NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-123
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = NULL WHERE ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-124
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = [TIME] WHERE ((a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2)) AND "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-125
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM "models" AS "model" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-126
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM "models" AS "model" WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-127
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = [TIME] WHERE "soft_delete"."deleted_at" IS NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-128
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = [TIME] WHERE "soft_delete"."deleted_at" IS NOT NULL AND ("soft_delete"."id" = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-129
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE "soft_deletes" AS "soft_delete" SET "deleted_at" = [TIME] WHERE ("soft_delete"."id" = NULL)
18 changes: 18 additions & 0 deletions query_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ var (
_ IDB = (*Tx)(nil)
)

// QueryBuilder is used for common query methods
type QueryBuilder interface {
Query
Where(query string, args ...interface{}) QueryBuilder
WhereGroup(sep string, fn func(QueryBuilder) QueryBuilder) QueryBuilder
WhereOr(query string, args ...interface{}) QueryBuilder
WhereDeleted() QueryBuilder
WhereAllWithDeleted() QueryBuilder
WherePK(cols ...string) QueryBuilder
Unwrap() interface{}
}

var (
_ QueryBuilder = (*selectQueryBuilder)(nil)
_ QueryBuilder = (*updateQueryBuilder)(nil)
_ QueryBuilder = (*deleteQueryBuilder)(nil)
)

type baseQuery struct {
db *DB
conn IConn
Expand Down
Loading

0 comments on commit 59fef48

Please sign in to comment.