@@ -233,6 +233,7 @@ actix-web = "4"
233233
234234``` rust
235235use sqlx_oldapi :: postgres :: PgPoolOptions ;
236+ use sqlx_oldapi :: {query, query_as, query_as_unchecked, query_scalar, query_with};
236237// use sqlx_oldapi::mysql::MySqlPoolOptions;
237238// etc.
238239
@@ -249,7 +250,7 @@ async fn main() -> Result<(), sqlx_oldapi::Error> {
249250 . connect (" postgres://postgres:password@localhost/test" ). await ? ;
250251
251252 // Make a simple query to return the given parameter (use a question mark `?` instead of `$1` for MySQL)
252- let row : (i64 ,) = sqlx_oldapi :: query_as (" SELECT $1" )
253+ let row : (i64 ,) = query_as (" SELECT $1" )
253254 . bind (150_i64 )
254255 . fetch_one (& pool ). await ? ;
255256
@@ -289,21 +290,21 @@ and a `Query` or `QueryAs` struct is treated as a prepared query.
289290``` rust
290291// low-level, Executor trait
291292conn . execute (" BEGIN" ). await ? ; // unprepared, simple query
292- conn . execute (sqlx_oldapi :: query (" DELETE FROM table" )). await ? ; // prepared, cached query
293+ conn . execute (query (" DELETE FROM table" )). await ? ; // prepared, cached query
293294```
294295
295296We should prefer to use the high level, ` query ` interface whenever possible. To make this easier, there are finalizers
296297on the type to avoid the need to wrap with an executor.
297298
298299``` rust
299- sqlx_oldapi :: query (" DELETE FROM table" ). execute (& mut conn ). await ? ;
300- sqlx_oldapi :: query (" DELETE FROM table" ). execute (& pool ). await ? ;
300+ query (" DELETE FROM table" ). execute (& mut conn ). await ? ;
301+ query (" DELETE FROM table" ). execute (& pool ). await ? ;
301302```
302303
303304The ` execute ` query finalizer returns the number of affected rows, if any, and drops all received results.
304305In addition, there are ` fetch ` , ` fetch_one ` , ` fetch_optional ` , and ` fetch_all ` to receive results.
305306
306- The ` Query ` type returned from ` sqlx_oldapi:: query` will return ` Row<'conn> ` from the database. Column values can be accessed
307+ The ` Query ` type returned from ` query ` will return ` Row<'conn> ` from the database. Column values can be accessed
307308by ordinal or by name with ` row.get() ` . As the ` Row ` retains an immutable borrow on the connection, only one
308309` Row ` may exist at a time.
309310
@@ -313,7 +314,7 @@ The `fetch` query finalizer returns a stream-like type that iterates through the
313314// provides `try_next`
314315use futures :: TryStreamExt ;
315316
316- let mut rows = sqlx_oldapi :: query (" SELECT * FROM users WHERE email = ?" )
317+ let mut rows = query (" SELECT * FROM users WHERE email = ?" )
317318 . bind (email )
318319 . fetch (& mut conn );
319320
@@ -326,7 +327,7 @@ while let Some(row) = rows.try_next().await? {
326327To assist with mapping the row into a domain type, there are two idioms that may be used:
327328
328329``` rust
329- let mut stream = sqlx_oldapi :: query (" SELECT * FROM users" )
330+ let mut stream = query (" SELECT * FROM users" )
330331 . map (| row : PgRow | {
331332 // map the row into a user-defined domain type
332333 })
@@ -337,7 +338,7 @@ let mut stream = sqlx_oldapi::query("SELECT * FROM users")
337338#[derive(sqlx_oldapi:: FromRow )]
338339struct User { name : String , id : i64 }
339340
340- let mut stream = sqlx_oldapi :: query_as :: <_ , User >(" SELECT * FROM users WHERE email = ? OR name = ?" )
341+ let mut stream = query_as :: <_ , User >(" SELECT * FROM users WHERE email = ? OR name = ?" )
341342 . bind (user_email )
342343 . bind (user_name )
343344 . fetch (& mut conn );
@@ -352,7 +353,7 @@ We can use the macro, `sqlx_oldapi::query!` to achieve compile-time syntactic an
352353an output to an anonymous record type where each SQL column is a Rust field (using raw identifiers where needed).
353354
354355``` rust
355- let countries = sqlx_oldapi :: query! (
356+ let countries = query! (
356357 "
357358SELECT country, COUNT(*) as count
358359FROM users
@@ -399,7 +400,7 @@ mostly identical except that you can name the output type.
399400// no traits are needed
400401struct Country { country: String , count: i64 }
401402
402- let countries = sqlx_oldapi :: query_as! (Country ,
403+ let countries = query_as! (Country ,
403404 "
404405SELECT country, COUNT (* ) as count
405406FROM users
0 commit comments