Skip to content

Commit

Permalink
insert builder supports values from iterator (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
brahmlower committed Jan 29, 2024
1 parent b4f2a3d commit 9f8315f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/query/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,44 @@ impl InsertStatement {
self.values(values).unwrap()
}

/// Add rows to be inserted from an iterator, variation of [`InsertStatement::values_panic`].
///
/// # Examples
///
/// ```
/// use sea_query::{tests_cfg::*, *};
///
/// let rows = vec![[2.1345.into(), "24B".into()], [5.15.into(), "12A".into()]];
///
/// let query = Query::insert()
/// .into_table(Glyph::Table)
/// .columns([Glyph::Aspect, Glyph::Image])
/// .values_from_panic(rows)
/// .to_owned();
///
/// assert_eq!(
/// query.to_string(MysqlQueryBuilder),
/// r#"INSERT INTO `glyph` (`aspect`, `image`) VALUES (2.1345, '24B'), (5.15, '12A')"#
/// );
/// assert_eq!(
/// query.to_string(PostgresQueryBuilder),
/// r#"INSERT INTO "glyph" ("aspect", "image") VALUES (2.1345, '24B'), (5.15, '12A')"#
/// );
/// assert_eq!(
/// query.to_string(SqliteQueryBuilder),
/// r#"INSERT INTO "glyph" ("aspect", "image") VALUES (2.1345, '24B'), (5.15, '12A')"#
/// );
/// ```
pub fn values_from_panic<I>(&mut self, values_iter: impl IntoIterator<Item = I>) -> &mut Self
where
I: IntoIterator<Item = SimpleExpr>,
{
values_iter.into_iter().for_each(|values| {
self.values_panic(values);
});
self
}

/// ON CONFLICT expression
///
/// # Examples
Expand Down

0 comments on commit 9f8315f

Please sign in to comment.