Skip to content

Commit

Permalink
fix doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
wseaton committed Jun 6, 2024
1 parent 09b78cc commit 39996b2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
15 changes: 9 additions & 6 deletions snowflake-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,24 @@ snowflake-api = "0.7.0"

Check [examples](./examples) for working programs using the library.


```rust
use anyhow::Result;
use snowflake_api::{QueryResult, SnowflakeApi};
use snowflake_api::{QueryResult, AuthArgs, PasswordArgs, AuthType, SnowflakeApi, SnowflakeApiBuilder};

async fn run_query(sql: &str) -> Result<QueryResult> {
let mut api = SnowflakeApi::with_password_auth(

let auth = AuthArgs::new(
"ACCOUNT_IDENTIFIER",
Some("WAREHOUSE"),
Some("DATABASE"),
Some("SCHEMA"),
"USERNAME",
Some("ROLE"),
"PASSWORD",
)?;
AuthType::Password(PasswordArgs { password: "password".to_string() })
);

let mut api: SnowflakeApi = SnowflakeApiBuilder::new(auth)
.build()?;
let res = api.exec(sql).await?;

Ok(res)
Expand All @@ -68,7 +71,7 @@ async fn run_query(sql: &str) -> Result<QueryResult> {
Or using environment variables:

```rust
use anyhow::Result;
use anyhow::Result;
use snowflake_api::{QueryResult, SnowflakeApi};

async fn run_query(sql: &str) -> Result<QueryResult> {
Expand Down
20 changes: 20 additions & 0 deletions snowflake-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,26 @@ pub struct AuthArgs {
}

impl AuthArgs {
pub fn new(
account_identifier: &str,
warehouse: Option<&str>,
database: Option<&str>,
schema: Option<&str>,
username: &str,
role: Option<&str>,
auth_type: AuthType,
) -> Self {
Self {
account_identifier: account_identifier.to_string(),
warehouse: warehouse.map(str::to_string),
database: database.map(str::to_string),
schema: schema.map(str::to_string),
username: username.to_string(),
role: role.map(str::to_string),
auth_type,
}
}

pub fn from_env() -> Result<AuthArgs, SnowflakeApiError> {
let auth_type = if let Ok(password) = std::env::var("SNOWFLAKE_PASSWORD") {
Ok(AuthType::Password(PasswordArgs { password }))
Expand Down

0 comments on commit 39996b2

Please sign in to comment.