Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from renancloudwalk/master
Adapt Session Arc and associate a Session to Statement, Prepared Statement & Batch
- Loading branch information
Showing
51 changed files
with
1,160 additions
and
818 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
use cassandra_cpp::*; | ||
|
||
fn main() { | ||
let query = stmt!("SELECT keyspace_name FROM system_schema.keyspaces;"); | ||
let col_name = "keyspace_name"; | ||
|
||
let contact_points = "127.0.0.1"; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let mut cluster = Cluster::default(); | ||
cluster.set_contact_points(contact_points).unwrap(); | ||
cluster.set_contact_points("127.0.0.1").unwrap(); | ||
cluster.set_load_balance_round_robin(); | ||
let session = cluster.connect().await?; | ||
|
||
match cluster.connect() { | ||
Ok(ref mut session) => { | ||
let result = session.execute(&query).wait().unwrap(); | ||
println!("{}", result); | ||
for row in result.iter() { | ||
let col: String = row.get_by_name(col_name).unwrap(); | ||
println!("ks name = {}", col); | ||
} | ||
} | ||
err => println!("{:?}", err), | ||
let result = session | ||
.execute("SELECT keyspace_name FROM system_schema.keyspaces;") | ||
.await?; | ||
println!("{}", result); | ||
|
||
for row in result.iter() { | ||
let col: String = row.get_by_name("keyspace_name")?; | ||
println!("ks name = {}", col); | ||
} | ||
|
||
Ok(()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,34 @@ | ||
use cassandra_cpp::*; | ||
use std::fs; | ||
|
||
fn main() { | ||
let query = stmt!("SELECT keyspace_name FROM system_schema.keyspaces;"); | ||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let col_name = "keyspace_name"; | ||
let contact_points = "127.0.0.1"; | ||
let tls_ca_certificate_path = "ca/certificate/path"; | ||
|
||
let ca_cert = match fs::read_to_string(tls_ca_certificate_path) { | ||
Ok(cert) => { | ||
println!("Read in certificate file"); | ||
cert | ||
} | ||
Err(e) => { | ||
panic!("Failed to open certificate file. Error: {}", e); | ||
} | ||
}; | ||
|
||
let cert = | ||
fs::read_to_string(tls_ca_certificate_path).expect("Failed to open certificate file"); | ||
let mut ssl = cassandra_cpp::Ssl::default(); | ||
|
||
match cassandra_cpp::Ssl::add_trusted_cert(&mut ssl, &ca_cert) { | ||
Ok(_o) => { | ||
println!("Added trusted certificate"); | ||
} | ||
Err(e) => { | ||
panic!("Failed to add trusted certificate. Error: {}", e); | ||
} | ||
} | ||
|
||
println!("Set verification level"); | ||
let verify_level = vec![cassandra_cpp::SslVerifyFlag::PEER_IDENTITY]; | ||
cassandra_cpp::Ssl::set_verify_flags(&mut ssl, &verify_level); | ||
ssl.add_trusted_cert(cert)?; | ||
ssl.set_verify_flags(&[cassandra_cpp::SslVerifyFlag::PEER_IDENTITY]); | ||
|
||
let mut cluster = Cluster::default(); | ||
cluster.set_contact_points(contact_points).unwrap(); | ||
cluster.set_load_balance_round_robin(); | ||
|
||
println!("Adding SSL to cluster"); | ||
cluster.set_ssl(&mut ssl); | ||
|
||
match cluster.connect() { | ||
Ok(ref mut session) => { | ||
let result = session.execute(&query).wait().unwrap(); | ||
println!("{}", result); | ||
for row in result.iter() { | ||
let col: String = row.get_by_name(col_name).unwrap(); | ||
println!("ks name = {}", col); | ||
} | ||
} | ||
err => println!("{:?}", err), | ||
cluster.set_ssl(ssl); | ||
|
||
let session = cluster.connect().await?; | ||
let result = session | ||
.execute("SELECT keyspace_name FROM system_schema.keyspaces;") | ||
.await | ||
.unwrap(); | ||
|
||
println!("{}", result); | ||
for row in result.iter() { | ||
let col: String = row.get_by_name(col_name).unwrap(); | ||
println!("ks name = {}", col); | ||
} | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.