Skip to content

Commit

Permalink
feat: support INSERT ... RETURNING for MariaDB >= 10.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Jan 6, 2022
1 parent 81b10f8 commit b6531c0
Show file tree
Hide file tree
Showing 112 changed files with 115 additions and 7 deletions.
1 change: 1 addition & 0 deletions dialect/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Feature = internal.Flag
const (
CTE Feature = 1 << iota
Returning
InsertReturning
DefaultPlaceholder
DoubleColonCast
ValuesRow
Expand Down
4 changes: 4 additions & 0 deletions dialect/mysqldialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func (d *Dialect) Init(db *sql.DB) {
}

if strings.Contains(version, "MariaDB") {
version = semver.MajorMinor("v" + cleanupVersion(version))
if semver.Compare(version, "v10.5.0") >= 0 {
d.features |= feature.InsertReturning
}
return
}

Expand Down
1 change: 1 addition & 0 deletions dialect/pgdialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func New() *Dialect {
d.tables = schema.NewTables(d)
d.features = feature.CTE |
feature.Returning |
feature.InsertReturning |
feature.DefaultPlaceholder |
feature.DoubleColonCast |
feature.InsertTableAlias |
Expand Down
1 change: 1 addition & 0 deletions dialect/sqlitedialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func New() *Dialect {
d.tables = schema.NewTables(d)
d.features = feature.CTE |
feature.Returning |
feature.InsertReturning |
feature.InsertTableAlias |
feature.DeleteTableAlias |
feature.InsertOnConflict
Expand Down
5 changes: 0 additions & 5 deletions internal/dbtest/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,6 @@ func TestQuery(t *testing.T) {
timeRE := regexp.MustCompile(`'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+(\+\d{2}:\d{2})?'`)

testEachDB(t, func(t *testing.T, dbName string, db *bun.DB) {
if dbName == mariadbName {
t.Skip()
return
}

for i, fn := range queries {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
q := fn(db)
Expand Down
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VALUES ROW(42, 'hello')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VALUES ROW(42, 'hello'), ROW(43, 'world')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-10
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id`, `model`.`str` FROM `models` AS `model` WHERE (`model`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-100
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id`, `model`.`str` FROM `models` AS `model` WHERE (`model`.`id`, `model`.`str`) IN ((1, 'hello'), (2, 'world'))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-101
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `models` (email VARCHAR, password VARCHAR)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-102
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `models` (`id` BIGINT NOT NULL AUTO_INCREMENT, `str` VARCHAR(255), PRIMARY KEY (`id`)) PARTITION BY HASH (id)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-103
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `models` (`id` BIGINT NOT NULL AUTO_INCREMENT, `str` VARCHAR(255), PRIMARY KEY (`id`)) TABLESPACE `fasttablespace`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-104
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `models` AS `model` SET int = NULL, uint = NULL, str = NULL, time = NULL WHERE (`model`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-105
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`) VALUES ('embed')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-11
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id`, `model`.`str` FROM `models` AS `model` WHERE (`model`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-12
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-13
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT DISTINCT `model`.`id`, `model`.`str` FROM `models` AS `model`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-14
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT DISTINCT ON (foo) `model`.`id`, `model`.`str` FROM `models` AS `model`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-15
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WITH `foo` AS (SELECT `model`.`id`, `model`.`str` FROM `models` AS `model`) SELECT * FROM `foo`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-16
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(SELECT `model`.`id`, `model`.`str` FROM `models` AS `model` WHERE (1)) UNION (SELECT `model`.`id`, `model`.`str` FROM `models` AS `model`)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-17
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WITH `_data` (`id`, `str`, _order) AS (VALUES ROW(42, 'hello', 0), ROW(43, 'world', 1)) SELECT `model`.`id`, `model`.`str` FROM `models` AS `model` WHERE (model.id = _data.id) ORDER BY _data._order
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-18
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id`, `model`.`str` FROM `models` AS `model`, (VALUES ROW(42, 'hello', 0), ROW(43, 'world', 1)) AS (`id`, `str`, _order) WHERE (model.id = _data.id) ORDER BY _data._order
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-19
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`, `str`) VALUES (42, 'hello')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id`, `model`.`str` FROM `models` AS `model`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-20
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`, `str`) VALUES (42, 'hello'), (43, 'world')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-21
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`, `str`) VALUES (42, 'hello'), (43, 'world')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-22
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`, `str`) VALUES (42, 'hello'), (43, 'world') ON CONFLICT DO NOTHING
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-23
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`, `str`) VALUES (42, 'hello'), (43, 'world') ON CONFLICT DO UPDATE model.str = EXCLUDED.str WHERE (model.str IS NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-24
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`, `str`) VALUES (42, 'hello')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-25
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WITH `src` (`id`, `str`) AS (VALUES ROW(42, 'hello'), ROW(43, 'world')) INSERT INTO dest SELECT * FROM src
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-26
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `models` AS `model` SET `str` = '' WHERE (`model`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-27
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `models` AS `model` SET `str` = 'hello' WHERE (`model`.`id` = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-28
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WITH `_data` (`id`, `str`) AS (VALUES ROW(42, 'hello'), ROW(43, 'world')) UPDATE `models` AS `model`, `_data` SET model.str = _data.str WHERE (model.id = _data.id)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-29
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `models` SET `str` = 'hello' WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `id` FROM `models` AS `model`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-30
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WITH `src` (`id`, `str`) AS (VALUES ROW(42, 'hello'), ROW(43, 'world')) UPDATE `dest`, `src` SET dest.str = src.str WHERE (dest.id = src.id)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-31
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM `models` WHERE (`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-32
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `models` (`id` BIGINT NOT NULL AUTO_INCREMENT, `str` VARCHAR(255), PRIMARY KEY (`id`))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-33
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `models` (`id` BIGINT NOT NULL AUTO_INCREMENT, `struct` VARCHAR(255), `map` VARCHAR(255), `slice` VARCHAR(255), `array` VARCHAR(255), PRIMARY KEY (`id`))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-34
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE `models`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-35
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id`, `model`.`str` FROM `models` AS `model` WHERE (1) OR (2) OR ((3) OR (4) OR NOT ((5) OR (6)))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-36
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`str` FROM `models` AS `model`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-37
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `users` (`name` VARCHAR(255) NOT NULL DEFAULT \'unknown\')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-38
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE UNIQUE INDEX `title_idx` ON `films` (`title`)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-39
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE UNIQUE INDEX `title_idx` ON `films` (`title`) INCLUDE (`director`, `rating`)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id` FROM `models` AS `model`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-40
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * WHERE (id IN (1, 2, 3))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-41
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * WHERE ((id1, id2) IN ((1, 2), (3, 4)))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-42
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP INDEX CONCURRENTLY IF EXISTS title_idx
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-43
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `models` ADD column_name VARCHAR(123)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-44
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `models` DROP COLUMN `str`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-45
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TRUNCATE TABLE `models`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-46
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `story`.`id`, `story`.`name`, `story`.`user_id`, `user`.`id` AS `user__id`, `user`.`name` AS `user__name` FROM `stories` AS `story` LEFT JOIN `users` AS `user` ON (`user`.`id` = `story`.`user_id`)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-47
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `story`.`id`, `story`.`name`, `story`.`user_id` FROM `stories` AS `story` LEFT JOIN `users` AS `user` ON (`user`.`id` = `story`.`user_id`)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-48
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `story`.`id`, `story`.`name`, `story`.`user_id`, `user`.`name` AS `user__name` FROM `stories` AS `story` LEFT JOIN `users` AS `user` ON (`user`.`id` = `story`.`user_id`)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-49
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id`, `model`.`str` FROM `models` AS `model` WHERE (`model`.`id` = NULL) FOR UPDATE
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `id`, `str` FROM `models` AS `model`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-50
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bun: to bulk Update, use CTE and VALUES
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-51
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`int`, `uint`, `str`, `time`) VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-52
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`int`, `uint`, `str`, `time`) VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-53
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`array`) VALUES ('["foo","bar"]')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-54
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT IGNORE INTO `models` (`id`, `str`) VALUES (DEFAULT, '')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-55
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REPLACE INTO `models` (`id`, `str`) VALUES (DEFAULT, '')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-56
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`, `str`) VALUES (42, 'hello'), (43, 'world') ON DUPLICATE KEY UPDATE str = upper(str)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-57
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `models` (`id` BIGINT NOT NULL AUTO_INCREMENT, `str` VARCHAR(255), PRIMARY KEY (`id`), FOREIGN KEY ("profile_id") REFERENCES "profiles" ("id"))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-58
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`raw`) VALUES (NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-59
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`raw`) VALUES (NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-6
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id`, `model`.`str` FROM `models` AS `model`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-60
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`bytes`) VALUES (X'00000000000000000000')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-61
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VALUES ROW(NULL), ROW('1970-01-01 00:00:00')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-62
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`, `str`, `foo`) VALUES (DEFAULT, '', 'bar')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-63
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `models` AS `model` SET `str` = '', foo = 'bar' WHERE (`model`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-64
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-65
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM `soft_deletes` WHERE `deleted_at` IS NOT NULL AND (`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-66
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
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-67
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-68
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-69
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WITH `_data` (`id`, `str`) AS (VALUES ROW(42, 'hello'), ROW(43, 'world')) UPDATE `models` AS `model`, _data SET `model`.`str` = _data.`str` WHERE (`model`.`id` = _data.`id`)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-7
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT *
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-70
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE IF NOT EXISTS `models` (`id` VARCHAR(255) NOT NULL, `name` VARCHAR(255), PRIMARY KEY (`id`))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-71
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `models` (`id` BIGINT NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-72
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-73
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * WHERE (1 + 2.34 AS `sum`)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-74
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`) VALUES (0)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-75
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `users` AS `user` SET name = 'Hello' WHERE (id = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-76
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM `users` WHERE (id = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-77
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `users` (`id`, `name`) VALUES (DEFAULT, 'Hello') ON CONFLICT DO UPDATE name = 'Hello'
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-78
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * WHERE ((one) OR (two))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-79
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WITH `_data` (`id`, `str1`, `str2`) AS (VALUES ROW(42, 'hello', 'world'), ROW(43, 'foo', 'bar')) UPDATE `models` AS `model`, _data SET `model`.`str2` = _data.`str2` WHERE (`model`.`id` = _data.`id`)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-8
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM `table`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-80
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`, `str`) VALUES (42, 'custom'), (43, 'custom')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-81
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WITH `_data` (`id`, `str`) AS (VALUES ROW(42, 'custom'), ROW(43, 'custom')) UPDATE `models` AS `model`, _data SET `model`.`str` = _data.`str` WHERE (`model`.`id` = _data.`id`)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-82
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`, `str`) VALUES (42, 'hello') ON CONFLICT (id) DO UPDATE SET `str` = EXCLUDED.`str`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-83
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE `models` (`foo` VARCHAR(255), `bar` VARCHAR(255), `hello` VARCHAR(255), `world` VARCHAR(255), UNIQUE (`foo`), UNIQUE (`bar`), CONSTRAINT `group` UNIQUE (`hello`, `world`))
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-84
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`time`) VALUES ('0001-01-01 00:00:00')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-85
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`) VALUES (0)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-86
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `soft_deletes` (`id`, `deleted_at`) VALUES (DEFAULT, DEFAULT) ON CONFLICT DO NOTHING
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-87
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE `models` AS `model` SET WHERE (`model`.`id` = 42)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-88
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`, `time`) VALUES (123, '1970-01-01 00:00:00')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-89
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `dest` (id, name) SELECT id, name FROM `src`
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM table
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-90
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` = '0001-01-01 00:00:00' AND (`soft_delete`.`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-91
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM `soft_deletes` WHERE `deleted_at` != '0001-01-01 00:00:00' AND (`id` = NULL)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-92
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` = '0001-01-01 00:00:00'
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-93
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` != '0001-01-01 00:00:00'
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-94
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-95
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `soft_deletes` (`id`, `deleted_at`) VALUES (DEFAULT, '0001-01-01 00:00:00') ON CONFLICT DO NOTHING
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-96
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`, `str`) VALUES (DEFAULT, '')
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-97
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `models` (`id`, `str`) VALUES (DEFAULT, 'hello') ON DUPLICATE KEY UPDATE `str` = VALUES(`str`)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-98
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE mytable ADD IF NOT EXISTS column_name VARCHAR(123)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-99
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT `model`.`id`, `model`.`str` FROM `models` AS `model` WHERE `model`.`id` IN (1, 2)
4 changes: 2 additions & 2 deletions query_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (q *InsertQuery) Returning(query string, args ...interface{}) *InsertQuery
}

func (q *InsertQuery) hasReturning() bool {
if !q.db.features.Has(feature.Returning) {
if !q.db.features.Has(feature.InsertReturning) {
return false
}
return q.returningQuery.hasReturning()
Expand All @@ -148,7 +148,7 @@ func (q *InsertQuery) Ignore() *InsertQuery {
return q
}

// Replaces generates a `REPLACE INTO` query (MySQL).
// Replaces generates a `REPLACE INTO` query (MySQL and MariaDB).
func (q *InsertQuery) Replace() *InsertQuery {
q.replace = true
return q
Expand Down

0 comments on commit b6531c0

Please sign in to comment.