Under heavy development. Might be wise to point to git instead of crates.io for now.
Add following line to Cargo.toml:
toml
snowflake-connector = { version = "0.2", features = ["derive"] }
Right now, only key pair authentication is supported.
You must have the text files environment_variables/snowflake_private_key_path.txt
and environment_variables/snowflake_public_key_path.txt
, where your application is executed, and these files must store the path to the keys.
Add your public and private key under environment_variables/local
folder (you will have to create the local
folder). Make sure your private key is named rsa_key.p8
and your public key is rsa_key.pub
.
Point environment_variables/snowflake_private_key_path.txt
to your private key by changing its contents to: ./environment_variables/local/rsa_key.p8
Point environment_variables/snowflake_public_key_path.txt
to your public key: ./environment_variables/local/rsa_key.pub
Make sure to ignore the environment_variables
directory. You do not want to commit your keys to a repository.
Below example is not tested, but you get the gist: ```rust use snowflake_connector::{*, errors::SnowflakeError};
fn getfromsnowflake() -> Result
fn main() { if let Ok(data) = getfromsnowflake() { println!("{:#?}", data) } else { panic!("Failed to retrieve data from snowflake!"); } }
// Fields must be in order of columns!
pub struct Test { pub id: u32, pub value1: bool, pub value2: String, pub value3: SomeEnumValue, }
// Enum must implement DeserializeFromStr!
pub enum SomeEnumValue { Value1, Value2, }
// Snowflake sends each cell as a string,
// convert the string to the appropriate type!
impl DeserializeFromStr for SomeEnumValue {
type Err = anyhow::Error;
fn deserializefromstr(s: &str) -> Result
Snowflake returns every value as a string. Implement
DeserializeFromStrfor types that can be parsed from a string. Add the
SnowflakeDeserializederive attribute to a
structto allow
SnowflakeConnector` to convert the data to that type. As of now, the order of the fields must correspond to the order of the columns. Let's assume the fields go top-to-bottom, so the top-most field must be the first column, the bottom-most field must be the last column, otherwise deserializing will fail.