Skip to content

Commit a58d39a

Browse files
committed
added test cases
1 parent b3002f0 commit a58d39a

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

src/query/on_conflict.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,51 @@ impl OnConflict {
6464
}
6565
}
6666

67+
/// Set ON CONFLICT do nothing
68+
///
69+
/// # Examples
70+
///
71+
/// ```
72+
/// use sea_query::{tests_cfg::*, *};
73+
///
74+
/// let query = Query::insert()
75+
/// .into_table(Glyph::Table)
76+
/// .columns([Glyph::Aspect, Glyph::Image])
77+
/// .values_panic(["abcd".into(), 3.1415.into()])
78+
/// .on_conflict(
79+
/// OnConflict::columns([Glyph::Id, Glyph::Aspect])
80+
/// .do_nothing()
81+
/// .to_owned(),
82+
/// )
83+
/// .to_owned();
84+
///
85+
/// assert_eq!(
86+
/// query.to_string(MysqlQueryBuilder),
87+
/// [
88+
/// r#"INSERT IGNORE INTO `glyph` (`aspect`, `image`)"#,
89+
/// r#"VALUES ('abcd', 3.1415)"#,
90+
/// ]
91+
/// .join(" ")
92+
/// );
93+
/// assert_eq!(
94+
/// query.to_string(PostgresQueryBuilder),
95+
/// [
96+
/// r#"INSERT INTO "glyph" ("aspect", "image")"#,
97+
/// r#"VALUES ('abcd', 3.1415)"#,
98+
/// r#"ON CONFLICT ("id", "aspect") DO NOTHING"#,
99+
/// ]
100+
/// .join(" ")
101+
/// );
102+
/// assert_eq!(
103+
/// query.to_string(SqliteQueryBuilder),
104+
/// [
105+
/// r#"INSERT INTO "glyph" ("aspect", "image")"#,
106+
/// r#"VALUES ('abcd', 3.1415)"#,
107+
/// r#"ON CONFLICT ("id", "aspect") DO NOTHING"#,
108+
/// ]
109+
/// .join(" ")
110+
/// );
111+
/// ```
67112
pub fn do_nothing(&mut self) -> &mut Self {
68113
self.action = Some(OnConflictAction::DoNothing);
69114
self

tests/mysql/query.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,27 @@ fn insert_from_select() {
11411141
);
11421142
}
11431143

1144+
#[test]
1145+
#[allow(clippy::approx_constant)]
1146+
fn insert_on_conflict_do_nothing() {
1147+
assert_eq!(
1148+
Query::insert()
1149+
.into_table(Glyph::Table)
1150+
.columns([Glyph::Aspect, Glyph::Image])
1151+
.values_panic([
1152+
"04108048005887010020060000204E0180400400".into(),
1153+
3.1415.into(),
1154+
])
1155+
.on_conflict(OnConflict::new().do_nothing().to_owned())
1156+
.to_string(MysqlQueryBuilder),
1157+
[
1158+
r#"INSERT IGNORE INTO `glyph` (`aspect`, `image`)"#,
1159+
r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#,
1160+
]
1161+
.join(" ")
1162+
);
1163+
}
1164+
11441165
#[test]
11451166
#[allow(clippy::approx_constant)]
11461167
fn insert_on_conflict_0() {

tests/postgres/query.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,28 @@ fn insert_10() {
12781278
);
12791279
}
12801280

1281+
#[test]
1282+
#[allow(clippy::approx_constant)]
1283+
fn insert_on_conflict_do_nothing() {
1284+
assert_eq!(
1285+
Query::insert()
1286+
.into_table(Glyph::Table)
1287+
.columns([Glyph::Aspect, Glyph::Image])
1288+
.values_panic([
1289+
"04108048005887010020060000204E0180400400".into(),
1290+
3.1415.into(),
1291+
])
1292+
.on_conflict(OnConflict::column(Glyph::Id).do_nothing().to_owned())
1293+
.to_string(PostgresQueryBuilder),
1294+
[
1295+
r#"INSERT INTO "glyph" ("aspect", "image")"#,
1296+
r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#,
1297+
r#"ON CONFLICT ("id") DO NOTHING"#,
1298+
]
1299+
.join(" ")
1300+
);
1301+
}
1302+
12811303
#[test]
12821304
#[allow(clippy::approx_constant)]
12831305
fn insert_on_conflict_1() {

tests/sqlite/query.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,28 @@ fn insert_7() {
12091209
);
12101210
}
12111211

1212+
#[test]
1213+
#[allow(clippy::approx_constant)]
1214+
fn insert_on_conflict_do_nothing() {
1215+
assert_eq!(
1216+
Query::insert()
1217+
.into_table(Glyph::Table)
1218+
.columns([Glyph::Aspect, Glyph::Image])
1219+
.values_panic([
1220+
"04108048005887010020060000204E0180400400".into(),
1221+
3.1415.into(),
1222+
])
1223+
.on_conflict(OnConflict::column(Glyph::Id).do_nothing().to_owned())
1224+
.to_string(SqliteQueryBuilder),
1225+
[
1226+
r#"INSERT INTO "glyph" ("aspect", "image")"#,
1227+
r#"VALUES ('04108048005887010020060000204E0180400400', 3.1415)"#,
1228+
r#"ON CONFLICT ("id") DO NOTHING"#,
1229+
]
1230+
.join(" ")
1231+
);
1232+
}
1233+
12121234
#[test]
12131235
#[allow(clippy::approx_constant)]
12141236
fn insert_on_conflict_1() {

0 commit comments

Comments
 (0)