mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-03 07:45:30 +00:00
Minor fixes and run rustfmt
This commit is contained in:
parent
f16c805f4c
commit
871183d23b
@ -1,6 +1,6 @@
|
||||
use sqlx::{FromRow, Pool, Postgres};
|
||||
use sqlx::{Pool, Postgres};
|
||||
use std::env;
|
||||
use tide::{http::StatusCode, Request, Response, ResultExt};
|
||||
use tide::{Request, Response};
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
@ -34,10 +34,11 @@ async fn register(mut req: Request<Pool<Postgres>>) -> Response {
|
||||
let mut pool = req.state();
|
||||
|
||||
// TODO: Handle the unwrap
|
||||
let (user_id,): (i64,) =
|
||||
sqlx::query("INSERT INTO users (username, email) VALUES ($1, $2) RETURNING id")
|
||||
.bind(body.username)
|
||||
.bind(body.email)
|
||||
let (user_id,): (i64,) = sqlx::query!(
|
||||
"INSERT INTO users (username, email) VALUES ($1, $2) RETURNING id",
|
||||
&*body.username,
|
||||
&*body.email
|
||||
)
|
||||
.fetch_one(&mut pool)
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -2,8 +2,8 @@ use async_std::io::{
|
||||
prelude::{ReadExt, WriteExt},
|
||||
Read, Write,
|
||||
};
|
||||
use std::io;
|
||||
use bitflags::_core::mem::MaybeUninit;
|
||||
use std::io;
|
||||
|
||||
pub struct BufStream<S> {
|
||||
pub(crate) stream: S,
|
||||
|
@ -1,13 +1,11 @@
|
||||
use super::MariaDb;
|
||||
use crate::mariadb::protocol::ResultRow;
|
||||
use crate::mariadb::query::MariaDbQueryParameters;
|
||||
use crate::{
|
||||
backend::Backend,
|
||||
describe::{Describe, ResultField},
|
||||
mariadb::{protocol::ResultRow, query::MariaDbQueryParameters},
|
||||
url::Url,
|
||||
};
|
||||
use futures_core::stream::BoxStream;
|
||||
use futures_core::future::BoxFuture;
|
||||
use crate::url::Url;
|
||||
use futures_core::{future::BoxFuture, stream::BoxStream};
|
||||
|
||||
impl Backend for MariaDb {
|
||||
type QueryParameters = MariaDbQueryParameters;
|
||||
@ -24,9 +22,7 @@ impl Backend for MariaDb {
|
||||
}
|
||||
|
||||
fn close(self) -> BoxFuture<'static, crate::Result<()>> {
|
||||
Box::pin(async move {
|
||||
self.close().await
|
||||
})
|
||||
Box::pin(async move { self.close().await })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ use crate::{
|
||||
},
|
||||
query::MariaDbQueryParameters,
|
||||
},
|
||||
url::Url,
|
||||
Error, Result,
|
||||
};
|
||||
use async_std::net::TcpStream;
|
||||
@ -17,7 +18,6 @@ use std::{
|
||||
io,
|
||||
net::{IpAddr, SocketAddr},
|
||||
};
|
||||
use crate::url::Url;
|
||||
|
||||
pub struct MariaDb {
|
||||
pub(crate) stream: BufStream<TcpStream>,
|
||||
@ -208,9 +208,7 @@ impl MariaDb {
|
||||
Ok(ok)
|
||||
}
|
||||
|
||||
pub(super) async fn column_definitions(
|
||||
&mut self
|
||||
) -> Result<Vec<ColumnDefinitionPacket>> {
|
||||
pub(super) async fn column_definitions(&mut self) -> Result<Vec<ColumnDefinitionPacket>> {
|
||||
let packet = self.receive().await?;
|
||||
|
||||
// A Resultset starts with a [ColumnCountPacket] which is a single field that encodes
|
||||
|
@ -3,9 +3,9 @@ use crate::{
|
||||
connection::MariaDb,
|
||||
protocol::{Capabilities, HandshakeResponsePacket, InitialHandshakePacket},
|
||||
},
|
||||
url::Url,
|
||||
Result,
|
||||
};
|
||||
use crate::url::Url;
|
||||
|
||||
pub(crate) async fn establish(conn: &mut MariaDb, url: &Url) -> Result<()> {
|
||||
let initial = InitialHandshakePacket::decode(conn.receive().await?)?;
|
||||
|
@ -3,12 +3,14 @@ use crate::{
|
||||
backend::Backend,
|
||||
describe::{Describe, ResultField},
|
||||
executor::Executor,
|
||||
params::{IntoQueryParameters, QueryParameters},
|
||||
mariadb::protocol::{
|
||||
mariadb::{
|
||||
protocol::{
|
||||
Capabilities, ColumnCountPacket, ColumnDefinitionPacket, ComStmtExecute, EofPacket,
|
||||
ErrPacket, OkPacket, ResultRow, StmtExecFlag,
|
||||
},
|
||||
mariadb::query::MariaDbQueryParameters,
|
||||
query::MariaDbQueryParameters,
|
||||
},
|
||||
params::{IntoQueryParameters, QueryParameters},
|
||||
row::FromRow,
|
||||
url::Url,
|
||||
};
|
||||
|
@ -5,7 +5,7 @@ use crate::{
|
||||
mariadb::protocol::{FieldType, ParameterFlag},
|
||||
types::HasSqlType,
|
||||
};
|
||||
use byteorder::{LittleEndian, ByteOrder};
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
|
||||
impl HasSqlType<i16> for MariaDb {
|
||||
#[inline]
|
||||
|
@ -2,12 +2,11 @@ use super::{connection::Step, Postgres};
|
||||
use crate::{
|
||||
backend::Backend,
|
||||
describe::{Describe, ResultField},
|
||||
postgres::protocol::DataRow,
|
||||
params::QueryParameters,
|
||||
postgres::{protocol::DataRow, query::PostgresQueryParameters},
|
||||
url::Url,
|
||||
};
|
||||
use futures_core::{future::BoxFuture, stream::BoxStream};
|
||||
use crate::postgres::query::PostgresQueryParameters;
|
||||
|
||||
impl Backend for Postgres {
|
||||
type QueryParameters = PostgresQueryParameters;
|
||||
|
@ -1,7 +1,9 @@
|
||||
use crate::{
|
||||
io::{Buf, BufStream},
|
||||
postgres::{
|
||||
error::PostgresDatabaseError,
|
||||
protocol::{self, Decode, Encode, Message},
|
||||
query::PostgresQueryParameters,
|
||||
},
|
||||
};
|
||||
use async_std::net::TcpStream;
|
||||
@ -10,8 +12,6 @@ use std::{
|
||||
io,
|
||||
net::{Shutdown, SocketAddr},
|
||||
};
|
||||
use crate::postgres::query::PostgresQueryParameters;
|
||||
use crate::postgres::error::PostgresDatabaseError;
|
||||
|
||||
pub struct Postgres {
|
||||
stream: BufStream<TcpStream>,
|
||||
@ -75,12 +75,10 @@ impl Postgres {
|
||||
self.stream.flush().await?;
|
||||
|
||||
while let Some(message) = self.receive().await? {
|
||||
println!("recv!?");
|
||||
match message {
|
||||
Message::Authentication(auth) => {
|
||||
match *auth {
|
||||
protocol::Authentication::Ok => {
|
||||
println!("no auth?");
|
||||
// Do nothing. No password is needed to continue.
|
||||
}
|
||||
|
||||
@ -128,8 +126,6 @@ impl Postgres {
|
||||
}
|
||||
}
|
||||
|
||||
println!("done");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,4 @@ pub mod protocol;
|
||||
|
||||
pub mod types;
|
||||
|
||||
pub use self::{
|
||||
connection::Postgres
|
||||
};
|
||||
pub use self::connection::Postgres;
|
||||
|
@ -188,11 +188,10 @@ where
|
||||
Ok(quote! {{
|
||||
#params
|
||||
|
||||
sqlx::Query::<#backend_path, _, (#(#output_types),*,), _> {
|
||||
sqlx::Query::<#backend_path, _, (#(#output_types),*,)> {
|
||||
query: #query,
|
||||
input: params,
|
||||
output: ::core::marker::PhantomData,
|
||||
target: ::core::marker::PhantomData,
|
||||
backend: ::core::marker::PhantomData,
|
||||
}
|
||||
}}
|
||||
|
@ -26,5 +26,3 @@ macro_rules! test {
|
||||
|
||||
test!(mysql_bool: bool: "false" == false, "true" == true);
|
||||
test!(mysql_long: i32: "2141512" == 2141512_i32);
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user