Skip to content

Commit

Permalink
An example how to connect using named pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius de Bruijn committed Mar 1, 2021
1 parent f9c702d commit d3f38d9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ opentls = { version = "0.2.1", features = ["io-async-std"]}
async-native-tls = { version = "0.3", features = ["runtime-async-std"]}

[dependencies.tokio]
version = "1.0"
git = "https://github.com/blackbeam/tokio"
branch = "named-pipes"
optional = true
features = ["net", "time"]

[dependencies.tokio-util]
version = "0.6"
git = "https://github.com/blackbeam/tokio"
branch = "named-pipes"
features = ["compat"]
optional = true

Expand Down Expand Up @@ -109,12 +111,14 @@ optional = true
features = ["std"]

[dev-dependencies.tokio-util]
version = "0.6"
git = "https://github.com/blackbeam/tokio"
branch = "named-pipes"
features = ["compat"]

[dev-dependencies.tokio]
git = "https://github.com/blackbeam/tokio"
features = ["macros", "sync", "io-std", "time", "io-util", "net", "rt-multi-thread"]
version = "1.0"
branch = "named-pipes"

[dev-dependencies.async-std]
features = ["attributes"]
Expand Down
28 changes: 28 additions & 0 deletions examples/named-pipes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#[cfg(windows)]
#[tokio::main]
async fn main() -> anyhow::Result<()> {
use tokio::net::windows::named_pipe::NamedPipe;
use tokio_util::compat::TokioAsyncWriteCompatExt;
use tiberius::{Config, AuthMethod, Client};

let mut config = Config::new();
config.authentication(AuthMethod::Integrated);
config.trust_cert();

let pipe = NamedPipe::connect("\\\\.\\pipe\\sql\\query").await?;
let mut client = Client::connect(config, pipe.compat_write()).await?;

let stream = client.query("SELECT @P1", &[&1i32]).await?;
let row = stream.into_row().await?.unwrap();

println!("{:?}", row);
assert_eq!(Some(1), row.get(0));

Ok(())
}

#[cfg(not(windows))]
#[tokio::main]
async fn main() -> anyhow::Result<()> {
panic!("Only works on Windows.");
}

0 comments on commit d3f38d9

Please sign in to comment.