Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add merge to Arguments #3652

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions sqlx-postgres/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ 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);
self.buffer.count += other.buffer.count;
self.buffer.patches.extend(other.buffer.patches);
self.buffer.type_holes.extend(other.buffer.type_holes);
}

#[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