Skip to content

Commit

Permalink
feat: add merge capability for arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
dgagn committed Dec 22, 2024
1 parent 9f6ea96 commit 1c461ed
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sqlx-core/src/any/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ impl<'q> Arguments<'q> for AnyArguments<'q> {
fn len(&self) -> usize {
self.values.0.len()
}

fn merge(&mut self, other: Self) {
self.values.0.extend(other.values.0);
}
}

pub struct AnyArgumentBuffer<'q>(#[doc(hidden)] pub Vec<AnyValueKind<'q>>);
Expand Down
2 changes: 2 additions & 0 deletions sqlx-core/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub trait Arguments<'q>: Send + Sized + Default {
fn format_placeholder<W: Write>(&self, writer: &mut W) -> fmt::Result {
writer.write_str("?")
}

fn merge(&mut self, other: Self);
}

pub trait IntoArguments<'q, DB: Database>: Sized + Send {
Expand Down
7 changes: 7 additions & 0 deletions sqlx-mysql/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ impl<'q> Arguments<'q> for MySqlArguments {
fn len(&self) -> usize {
self.types.len()
}

fn merge(&mut self, other: Self) {
self.types.extend(other.types);
self.values.extend(other.values);
self.null_bitmap.bytes.extend(other.null_bitmap.bytes);
self.null_bitmap.length += other.null_bitmap.length;
}
}

#[derive(Debug, Default, Clone)]
Expand Down
5 changes: 5 additions & 0 deletions sqlx-postgres/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ impl<'q> Arguments<'q> for PgArguments {
write!(writer, "${}", self.buffer.count)
}

fn merge(&mut self, other: Self) {
self.types.extend(other.types);
self.buffer.extend_from_slice(&other.buffer);
}

#[inline(always)]
fn len(&self) -> usize {
self.buffer.count
Expand Down
4 changes: 4 additions & 0 deletions sqlx-sqlite/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ impl<'q> Arguments<'q> for SqliteArguments<'q> {
fn len(&self) -> usize {
self.values.len()
}

fn merge(&mut self, other: Self) {
self.values.extend(other.values);
}
}

impl SqliteArguments<'_> {
Expand Down

0 comments on commit 1c461ed

Please sign in to comment.