[][src]Struct tiberius::Client

pub struct Client<S: AsyncRead + AsyncWrite + Unpin + Send> { /* fields omitted */ }

Client is the main entry point to the SQL Server, providing query execution capabilities.

A Client is created using the Config, defining the needed connection options and capabilities.

Example

let mut config = Config::new();

config.host("0.0.0.0");
config.port(1433);
config.authentication(AuthMethod::sql_server("SA", "<Mys3cureP4ssW0rD>"));

let tcp = tokio::net::TcpStream::connect(config.get_addr()).await?;
tcp.set_nodelay(true)?;
// Client is ready to use.
let client = tiberius::Client::connect(config, tcp.compat_write()).await?;

Implementations

impl<S: AsyncRead + AsyncWrite + Unpin + Send> Client<S>[src]

pub async fn connect(config: Config, tcp_stream: S) -> Result<Client<S>>[src]

Uses an instance of Config to specify the connection options required to connect to the database using an established tcp connection

pub async fn execute<'a, '_, '_, '_>(
    &'_ mut self,
    query: impl Into<Cow<'a, str>>,
    params: &'_ [&'_ dyn ToSql]
) -> Result<ExecuteResult>
[src]

Executes SQL statements in the SQL Server, returning the number rows affected. Useful for INSERT, UPDATE and DELETE statements. The query can define the parameter placement by annotating them with @PN, where N is the index of the parameter, starting from 1. If executing multiple queries at a time, delimit them with ; and refer to ExecuteResult how to get results for the separate queries.

Example

let results = client
    .execute(
        "INSERT INTO ##Test (id) VALUES (@P1), (@P2), (@P3)",
        &[&1i32, &2i32, &3i32],
    )
    .await?;

pub async fn query<'a, 'b>(
    &'a mut self,
    query: impl Into<Cow<'b, str>>,
    params: &'b [&'b dyn ToSql]
) -> Result<QueryResult<'a>> where
    'a: 'b, 
[src]

Executes SQL statements in the SQL Server, returning resulting rows. Useful for SELECT statements. The query can define the parameter placement by annotating them with @PN, where N is the index of the parameter, starting from 1. If executing multiple queries at a time, delimit them with ; and refer to QueryResult on proper stream handling.

Example

let stream = client
    .query(
        "SELECT @P1, @P2, @P3",
        &[&1i32, &2i32, &3i32],
    )
    .await?;

pub async fn simple_query<'a, 'b>(
    &'a mut self,
    query: impl Into<Cow<'b, str>>
) -> Result<QueryResult<'a>> where
    'a: 'b, 
[src]

Execute multiple queries, delimited with ; and return multiple result sets; one for each query.

Example

let row = client.simple_query("SELECT 1 AS col").await?.into_row().await?.unwrap();
assert_eq!(Some(1i32), row.get("col"));

Warning

Do not use this with any user specified input. Please resort to prepared statements using the query method.

Trait Implementations

impl<S: Debug + AsyncRead + AsyncWrite + Unpin + Send> Debug for Client<S>[src]

Auto Trait Implementations

impl<S> !RefUnwindSafe for Client<S>

impl<S> Send for Client<S>

impl<S> Sync for Client<S> where
    S: Sync

impl<S> Unpin for Client<S>

impl<S> !UnwindSafe for Client<S>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,