Skip to content

Commit 877d297

Browse files
author
lucas11776
committed
Added: Postgres merge arguments
1 parent 84c8ae3 commit 877d297

5 files changed

Lines changed: 14 additions & 74 deletions

File tree

sqlx-core/src/any/arguments.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ impl Arguments for AnyArguments {
3535
fn merge(&mut self, arguments: Self) {
3636
todo!()
3737
}
38-
39-
fn position<'t, T>(&mut self, position: u32, value: T) -> Result<(), BoxDynError>
40-
where
41-
T: Encode<'t, Self::Database> + Type<Self::Database> {
42-
todo!()
43-
}
4438
}
4539

4640
#[derive(Default)]

sqlx-core/src/arguments.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ pub trait Arguments: Send + Sized + Default {
2929
}
3030

3131
fn merge(&mut self, arguments: Self);
32-
33-
fn position<'t, T>(&mut self, position: u32, value: T) -> Result<(), BoxDynError>
34-
where
35-
T: Encode<'t, Self::Database> + Type<Self::Database>;
3632
}
3733

3834
pub trait IntoArguments<DB: Database>: Sized + Send {

sqlx-mysql/src/arguments.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ impl Arguments for MySqlArguments {
5959
fn merge(&mut self, arguments: Self) {
6060
panic!("function not implemented");
6161
}
62-
63-
fn position<'t, T>(&mut self, position: u32, value: T) -> Result<(), BoxDynError>
64-
where
65-
T: Encode<'t, Self::Database> + Type<Self::Database>
66-
{
67-
panic!("function not implemented");
68-
}
6962
}
7063

7164
#[derive(Debug, Default, Clone)]

sqlx-postgres/src/arguments.rs

Lines changed: 14 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -162,62 +162,26 @@ impl Arguments for PgArguments {
162162
self.buffer.count
163163
}
164164

165-
fn merge(&mut self, mut arguments: Self) {
166-
// Merge `Arguments.types`
167-
{
168-
self.types.append(&mut arguments.types);
165+
fn merge(&mut self, arguments: Self) {
166+
let buf_offset = self.buffer.len();
167+
let count_offset = self.buffer.count;
168+
169+
self.types.extend(arguments.types);
170+
self.buffer.count += arguments.buffer.count;
171+
self.buffer.buffer.extend(arguments.buffer.buffer);
172+
173+
for mut patch in arguments.buffer.patches {
174+
patch.buf_offset += buf_offset;
175+
patch.arg_index += count_offset;
176+
self.buffer.patches.push(patch);
169177
}
170-
// Merge `Arguments.Buffer`
171-
{
172-
// Merge `buffer`
173-
self.buffer.buffer.append(&mut arguments.buffer.buffer);
174178

175-
// Merge `patches`
176-
self.buffer.patches.append(&mut arguments.buffer.patches);
177-
178-
// Merge `type_holes`
179-
self.buffer.type_holes.append(&mut arguments.buffer.type_holes);
180-
181-
// Increment number of arguments
182-
self.buffer.count += arguments.buffer.count;
179+
for (offset, kind) in arguments.buffer.type_holes {
180+
self.buffer.type_holes.push((offset + buf_offset, kind));
183181
}
184-
185-
// drop(arguments);
186-
}
187-
188-
fn position<'t, T>(&mut self, position: u32, value: T) -> Result<(), BoxDynError>
189-
where
190-
T: Encode<'t, Self::Database> + Type<Self::Database>
191-
{
192-
todo!()
193182
}
194183
}
195184

196-
197-
// #[derive(Default, Debug, Clone)]
198-
// pub struct PgArgumentBuffer {
199-
// buffer: Vec<u8>,
200-
201-
// // Number of arguments
202-
// count: usize,
203-
204-
// // Whenever an `Encode` impl needs to defer some work until after we resolve parameter types
205-
// // it can use `patch`.
206-
// //
207-
// // This currently is only setup to be useful if there is a *fixed-size* slot that needs to be
208-
// // tweaked from the input type. However, that's the only use case we currently have.
209-
// patches: Vec<Patch>,
210-
211-
// // Whenever an `Encode` impl encounters a `PgTypeInfo` object that does not have an OID
212-
// // It pushes a "hole" that must be patched later.
213-
// //
214-
// // The hole is a `usize` offset into the buffer with the type name that should be resolved
215-
// // This is done for Records and Arrays as the OID is needed well before we are in an async
216-
// // function and can just ask postgres.
217-
// //
218-
// type_holes: Vec<(usize, HoleKind)>, // Vec<{ offset, type_name }>
219-
// }
220-
221185
impl PgArgumentBuffer {
222186
pub(crate) fn encode<'q, T>(&mut self, value: T) -> Result<(), BoxDynError>
223187
where

sqlx-sqlite/src/arguments.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ impl Arguments for SqliteArguments {
7070
fn merge(&mut self, arguments: Self) {
7171
panic!("function not implemented");
7272
}
73-
74-
fn position<'t, T>(&mut self, position: u32, value: T) -> Result<(), BoxDynError>
75-
where
76-
T: Encode<'t, Self::Database> + sqlx_core::types::Type<Self::Database>
77-
{
78-
panic!("function not implemented");
79-
}
8073
}
8174

8275
impl SqliteArguments {

0 commit comments

Comments
 (0)