Skip to content

Commit 3eeb165

Browse files
abonanderjoeydewaal
authored andcommitted
refactor: introduce SqlSafeStr API
1 parent f0be19e commit 3eeb165

File tree

7 files changed

+284
-203
lines changed

7 files changed

+284
-203
lines changed

sqlx-core/src/executor.rs

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -182,76 +182,3 @@ pub trait Executor<'c>: Send + Debug + Sized {
182182
where
183183
'c: 'e;
184184
}
185-
186-
/// A type that may be executed against a database connection.
187-
///
188-
/// Implemented for the following:
189-
///
190-
/// * [`&str`](std::str)
191-
/// * [`Query`](super::query::Query)
192-
///
193-
pub trait Execute<'q, DB: Database>: Send + Sized {
194-
/// Gets the SQL that will be executed.
195-
fn sql(&self) -> &'q str;
196-
197-
/// Gets the previously cached statement, if available.
198-
fn statement(&self) -> Option<&DB::Statement<'q>>;
199-
200-
/// Returns the arguments to be bound against the query string.
201-
///
202-
/// Returning `Ok(None)` for `Arguments` indicates to use a "simple" query protocol and to not
203-
/// prepare the query. Returning `Ok(Some(Default::default()))` is an empty arguments object that
204-
/// will be prepared (and cached) before execution.
205-
///
206-
/// Returns `Err` if encoding any of the arguments failed.
207-
fn take_arguments(&mut self) -> Result<Option<<DB as Database>::Arguments<'q>>, BoxDynError>;
208-
209-
/// Returns `true` if the statement should be cached.
210-
fn persistent(&self) -> bool;
211-
}
212-
213-
// NOTE: `Execute` is explicitly not implemented for String and &String to make it slightly more
214-
// involved to write `conn.execute(format!("SELECT {val}"))`
215-
impl<'q, DB: Database> Execute<'q, DB> for &'q str {
216-
#[inline]
217-
fn sql(&self) -> &'q str {
218-
self
219-
}
220-
221-
#[inline]
222-
fn statement(&self) -> Option<&DB::Statement<'q>> {
223-
None
224-
}
225-
226-
#[inline]
227-
fn take_arguments(&mut self) -> Result<Option<<DB as Database>::Arguments<'q>>, BoxDynError> {
228-
Ok(None)
229-
}
230-
231-
#[inline]
232-
fn persistent(&self) -> bool {
233-
true
234-
}
235-
}
236-
237-
impl<'q, DB: Database> Execute<'q, DB> for (&'q str, Option<<DB as Database>::Arguments<'q>>) {
238-
#[inline]
239-
fn sql(&self) -> &'q str {
240-
self.0
241-
}
242-
243-
#[inline]
244-
fn statement(&self) -> Option<&DB::Statement<'q>> {
245-
None
246-
}
247-
248-
#[inline]
249-
fn take_arguments(&mut self) -> Result<Option<<DB as Database>::Arguments<'q>>, BoxDynError> {
250-
Ok(self.1.take())
251-
}
252-
253-
#[inline]
254-
fn persistent(&self) -> bool {
255-
true
256-
}
257-
}

sqlx-core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub mod net;
7272
pub mod query_as;
7373
pub mod query_builder;
7474
pub mod query_scalar;
75+
pub mod sql_str;
7576

7677
pub mod raw_sql;
7778
pub mod row;

0 commit comments

Comments
 (0)