Skip to content

Commit

Permalink
change ks to example_ks and change table names to example file name w…
Browse files Browse the repository at this point in the history
…here appropriate
  • Loading branch information
nsipplswezey committed Oct 17, 2023
1 parent b6f8787 commit b1b1ab3
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 96 deletions.
8 changes: 4 additions & 4 deletions examples/allocations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ async fn main() -> Result<()> {
let session: Session = SessionBuilder::new().known_node(args.node).build().await?;
let session = Arc::new(session);

session.query("CREATE KEYSPACE IF NOT EXISTS ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;
session.query("CREATE KEYSPACE IF NOT EXISTS examples_ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;
session.await_schema_agreement().await.unwrap();

session
.query(
"CREATE TABLE IF NOT EXISTS ks.alloc_test (a int, b int, c text, primary key (a, b))",
"CREATE TABLE IF NOT EXISTS examples_ks.allocations (a int, b int, c text, primary key (a, b))",
&[],
)
.await?;
Expand All @@ -145,13 +145,13 @@ async fn main() -> Result<()> {

let prepared_inserts = Arc::new(
session
.prepare("INSERT INTO ks.alloc_test (a, b, c) VALUES (?, ?, 'abc')")
.prepare("INSERT INTO examples_ks.allocations (a, b, c) VALUES (?, ?, 'abc')")
.await?,
);

let prepared_selects = Arc::new(
session
.prepare("SELECT * FROM ks.alloc_test WHERE a = ? and b = ?")
.prepare("SELECT * FROM examples_ks.allocations WHERE a = ? and b = ?")
.await?,
);

Expand Down
4 changes: 2 additions & 2 deletions examples/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ async fn main() -> Result<()> {
.await
.unwrap();

session.query("CREATE KEYSPACE IF NOT EXISTS ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await.unwrap();
session.query("CREATE KEYSPACE IF NOT EXISTS examples_ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await.unwrap();
session
.query("DROP TABLE IF EXISTS ks.t;", &[])
.query("DROP TABLE IF EXISTS examples_ks.auth;", &[])
.await
.unwrap();

Expand Down
16 changes: 8 additions & 8 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ async fn main() -> Result<()> {

let session: Session = SessionBuilder::new().known_node(uri).build().await?;

session.query("CREATE KEYSPACE IF NOT EXISTS ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;
session.query("CREATE KEYSPACE IF NOT EXISTS examples_ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;

session
.query(
"CREATE TABLE IF NOT EXISTS ks.t (a int, b int, c text, primary key (a, b))",
"CREATE TABLE IF NOT EXISTS examples_ks.basic (a int, b int, c text, primary key (a, b))",
&[],
)
.await?;

session
.query("INSERT INTO ks.t (a, b, c) VALUES (?, ?, ?)", (3, 4, "def"))
.query("INSERT INTO examples_ks.basic (a, b, c) VALUES (?, ?, ?)", (3, 4, "def"))
.await?;

session
.query("INSERT INTO ks.t (a, b, c) VALUES (1, 2, 'abc')", &[])
.query("INSERT INTO examples_ks.basic (a, b, c) VALUES (1, 2, 'abc')", &[])
.await?;

let prepared = session
.prepare("INSERT INTO ks.t (a, b, c) VALUES (?, 7, ?)")
.prepare("INSERT INTO examples_ks.basic (a, b, c) VALUES (?, 7, ?)")
.await?;
session
.execute(&prepared, (42_i32, "I'm prepared!"))
Expand All @@ -43,7 +43,7 @@ async fn main() -> Result<()> {
.await?;

// Rows can be parsed as tuples
if let Some(rows) = session.query("SELECT a, b, c FROM ks.t", &[]).await?.rows {
if let Some(rows) = session.query("SELECT a, b, c FROM examples_ks.basic", &[]).await?.rows {
for row in rows.into_typed::<(i32, i32, String)>() {
let (a, b, c) = row?;
println!("a, b, c: {}, {}, {}", a, b, c);
Expand All @@ -58,15 +58,15 @@ async fn main() -> Result<()> {
_c: String,
}

if let Some(rows) = session.query("SELECT a, b, c FROM ks.t", &[]).await?.rows {
if let Some(rows) = session.query("SELECT a, b, c FROM examples_ks.basic", &[]).await?.rows {
for row_data in rows.into_typed::<RowData>() {
let row_data = row_data?;
println!("row_data: {:?}", row_data);
}
}

// Or simply as untyped rows
if let Some(rows) = session.query("SELECT a, b, c FROM ks.t", &[]).await?.rows {
if let Some(rows) = session.query("SELECT a, b, c FROM examples_ks.basic", &[]).await?.rows {
for row in rows {
let a = row.columns[0].as_ref().unwrap().as_int().unwrap();
let b = row.columns[1].as_ref().unwrap().as_int().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions examples/cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ async fn main() -> Result<()> {
.await
.unwrap();

session.query("CREATE KEYSPACE IF NOT EXISTS ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}",
session.query("CREATE KEYSPACE IF NOT EXISTS examples_ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}",
&[]).await.unwrap();
session
.query("DROP TABLE IF EXISTS ks.t;", &[])
.query("DROP TABLE IF EXISTS examples_ks.cloud;", &[])
.await
.unwrap();

Expand Down
10 changes: 5 additions & 5 deletions examples/compare-tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ async fn main() -> Result<()> {

let session: Session = SessionBuilder::new().known_node(uri).build().await?;

session.query("CREATE KEYSPACE IF NOT EXISTS ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;
session.query("CREATE KEYSPACE IF NOT EXISTS examples_ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;

session
.query(
"CREATE TABLE IF NOT EXISTS ks.compare_tokens_example (pk bigint primary key)",
"CREATE TABLE IF NOT EXISTS examples_ks.compare_tokens (pk bigint primary key)",
&[],
)
.await?;

let prepared = session.prepare("INSERT INTO ks.compare_tokens_example (pk) VALUES (?)").await?;
let prepared = session.prepare("INSERT INTO examples_ks.compare_tokens (pk) VALUES (?)").await?;

for pk in (0..100_i64).chain(99840..99936_i64) {
session
.query("INSERT INTO ks.compare_tokens_example (pk) VALUES (?)", (pk,))
.query("INSERT INTO ks.compare_tokens (pk) VALUES (?)", (pk,))
.await?;

let serialized_pk = (pk,).serialized()?.into_owned();
Expand All @@ -43,7 +43,7 @@ async fn main() -> Result<()> {
);

let qt = session
.query(format!("SELECT token(pk) FROM ks.compare_tokens_example where pk = {}", pk), &[])
.query(format!("SELECT token(pk) FROM ks.compare_tokens where pk = {}", pk), &[])
.await?
.rows
.unwrap()
Expand Down
24 changes: 12 additions & 12 deletions examples/cql-time-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ async fn main() -> Result<()> {

let session: Session = SessionBuilder::new().known_node(uri).build().await?;

session.query("CREATE KEYSPACE IF NOT EXISTS ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;
session.query("CREATE KEYSPACE IF NOT EXISTS examples_ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;

// Date
// Date is a year, month and day in the range -5877641-06-23 to -5877641-06-23

session
.query(
"CREATE TABLE IF NOT EXISTS ks.dates (d date primary key)",
"CREATE TABLE IF NOT EXISTS examples_ks.dates (d date primary key)",
&[],
)
.await?;
Expand All @@ -33,10 +33,10 @@ async fn main() -> Result<()> {
let example_date: NaiveDate = NaiveDate::from_ymd_opt(2020, 2, 20).unwrap();

session
.query("INSERT INTO ks.dates (d) VALUES (?)", (example_date,))
.query("INSERT INTO examples_ks.dates (d) VALUES (?)", (example_date,))
.await?;

if let Some(rows) = session.query("SELECT d from ks.dates", &[]).await?.rows {
if let Some(rows) = session.query("SELECT d from examples_ks.dates", &[]).await?.rows {
for row in rows.into_typed::<(NaiveDate,)>() {
let (read_date,): (NaiveDate,) = match row {
Ok(read_date) => read_date,
Expand All @@ -50,10 +50,10 @@ async fn main() -> Result<()> {
// Dates outside this range must be represented in the raw form - an u32 describing days since -5877641-06-23
let example_big_date: Date = Date(u32::MAX);
session
.query("INSERT INTO ks.dates (d) VALUES (?)", (example_big_date,))
.query("INSERT INTO examples_ks.dates (d) VALUES (?)", (example_big_date,))
.await?;

if let Some(rows) = session.query("SELECT d from ks.dates", &[]).await?.rows {
if let Some(rows) = session.query("SELECT d from examples_ks.dates", &[]).await?.rows {
for row in rows {
let read_days: u32 = match row.columns[0] {
Some(CqlValue::Date(days)) => days,
Expand All @@ -69,17 +69,17 @@ async fn main() -> Result<()> {

session
.query(
"CREATE TABLE IF NOT EXISTS ks.times (t time primary key)",
"CREATE TABLE IF NOT EXISTS examples_ks.times (t time primary key)",
&[],
)
.await?;

// Time as bound value must be wrapped in value::Time to differentiate from Timestamp
session
.query("INSERT INTO ks.times (t) VALUES (?)", (Time(example_time),))
.query("INSERT INTO examples_ks.times (t) VALUES (?)", (Time(example_time),))
.await?;

if let Some(rows) = session.query("SELECT t from ks.times", &[]).await?.rows {
if let Some(rows) = session.query("SELECT t from examples_ks.times", &[]).await?.rows {
for row in rows.into_typed::<(Duration,)>() {
let (read_time,): (Duration,) = row?;

Expand All @@ -92,21 +92,21 @@ async fn main() -> Result<()> {

session
.query(
"CREATE TABLE IF NOT EXISTS ks.timestamps (t timestamp primary key)",
"CREATE TABLE IF NOT EXISTS examples_ks.timestamps (t timestamp primary key)",
&[],
)
.await?;

// Timestamp as bound value must be wrapped in value::Timestamp to differentiate from Time
session
.query(
"INSERT INTO ks.timestamps (t) VALUES (?)",
"INSERT INTO examples_ks.timestamps (t) VALUES (?)",
(Timestamp(example_timestamp),),
)
.await?;

if let Some(rows) = session
.query("SELECT t from ks.timestamps", &[])
.query("SELECT t from examples_ks.timestamps", &[])
.await?
.rows
{
Expand Down
10 changes: 5 additions & 5 deletions examples/custom_deserialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ async fn main() -> Result<()> {

let session: Session = SessionBuilder::new().known_node(uri).build().await?;

session.query("CREATE KEYSPACE IF NOT EXISTS ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;
session.query("CREATE KEYSPACE IF NOT EXISTS examples_ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;
session
.query(
"CREATE TABLE IF NOT EXISTS ks.custom_deserialization (pk int primary key, v text)",
"CREATE TABLE IF NOT EXISTS examples_ks.custom_deserialization (pk int primary key, v text)",
&[],
)
.await?;

session
.query("INSERT INTO ks.custom_deserialization (pk, v) VALUES (1, 'asdf')", ())
.query("INSERT INTO examples_ks.custom_deserialization (pk, v) VALUES (1, 'asdf')", ())
.await?;

// You can implement FromCqlVal for your own types
Expand All @@ -38,7 +38,7 @@ async fn main() -> Result<()> {
}

let (v,) = session
.query("SELECT v FROM ks.custom_deserialization WHERE pk = 1", ())
.query("SELECT v FROM examples_ks.custom_deserialization WHERE pk = 1", ())
.await?
.single_row_typed::<(MyType,)>()?;
assert_eq!(v, MyType("asdf".to_owned()));
Expand All @@ -62,7 +62,7 @@ async fn main() -> Result<()> {
impl_from_cql_value_from_method!(MyOtherType, into_my_other_type);

let (v,) = session
.query("SELECT v FROM ks.custom_deserialization WHERE pk = 1", ())
.query("SELECT v FROM examples_ks.custom_deserialization WHERE pk = 1", ())
.await?
.single_row_typed::<(MyOtherType,)>()?;
assert_eq!(v, MyOtherType("asdf".to_owned()));
Expand Down
12 changes: 6 additions & 6 deletions examples/execution_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ async fn main() -> Result<()> {
session_3_config.add_known_node(uri);
let session3: Session = Session::connect(session_3_config).await?;

session1.query("CREATE KEYSPACE IF NOT EXISTS ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;
session1.query("CREATE KEYSPACE IF NOT EXISTS examples_ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;

session2
.query(
"CREATE TABLE IF NOT EXISTS ks.t (a int, b int, c text, primary key (a, b))",
"CREATE TABLE IF NOT EXISTS examples_ks.execution_profile (a int, b int, c text, primary key (a, b))",
&[],
)
.await?;

let mut query_insert: Query = "INSERT INTO ks.t (a, b, c) VALUES (?, ?, ?)".into();
let mut query_insert: Query = "INSERT INTO examples_ks.execution_profile (a, b, c) VALUES (?, ?, ?)".into();

// As `query_insert` is set another handle than session1, the execution profile pointed by query's handle
// will be preferred, so the query below will be executed with `profile2`, even though `session1` is set `profile1`.
Expand All @@ -79,12 +79,12 @@ async fn main() -> Result<()> {
handle2.map_to_another_profile(profile1);
// And now the following queries are executed with profile1:
session1.query(query_insert.clone(), (3, 4, "def")).await?;
session2.query("SELECT * FROM ks.t", ()).await?;
session2.query("SELECT * FROM examples_ks.execution_profile", ()).await?;

// One can unset a profile handle from a statement and, since then, execute it with session's default profile.
query_insert.set_execution_profile_handle(None);
session3.query("SELECT * FROM ks.t", ()).await?; // This executes with default session profile.
session2.query("SELECT * FROM ks.t", ()).await?; // This executes with profile1.
session3.query("SELECT * FROM examples_ks.execution_profile", ()).await?; // This executes with default session profile.
session2.query("SELECT * FROM examples_ks.execution_profile", ()).await?; // This executes with profile1.

Ok(())
}
10 changes: 5 additions & 5 deletions examples/get_by_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@ async fn main() -> Result<()> {

let session: Session = SessionBuilder::new().known_node(uri).build().await?;

session.query("CREATE KEYSPACE IF NOT EXISTS ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;
session.query("CREATE KEYSPACE IF NOT EXISTS examples_ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;

session
.query(
"CREATE TABLE IF NOT EXISTS ks.hello (pk int, ck int, value text, primary key (pk, ck))",
"CREATE TABLE IF NOT EXISTS examples_ks.get_by_name (pk int, ck int, value text, primary key (pk, ck))",
&[],
)
.await?;

session
.query(
"INSERT INTO ks.hello (pk, ck, value) VALUES (?, ?, ?)",
"INSERT INTO examples_ks.get_by_name (pk, ck, value) VALUES (?, ?, ?)",
(3, 4, "def"),
)
.await?;

session
.query(
"INSERT INTO ks.hello (pk, ck, value) VALUES (1, 2, 'abc')",
"INSERT INTO examples_ks.get_by_name (pk, ck, value) VALUES (1, 2, 'abc')",
&[],
)
.await?;

let query_result = session
.query("SELECT pk, ck, value FROM ks.hello", &[])
.query("SELECT pk, ck, value FROM examples_ks.get_by_name", &[])
.await?;
let (ck_idx, _) = query_result
.get_column_spec("ck")
Expand Down
4 changes: 2 additions & 2 deletions examples/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ async fn main() -> Result<()> {
info!("Connecting to {}", uri);

let session: Session = SessionBuilder::new().known_node(uri).build().await?;
session.query("CREATE KEYSPACE IF NOT EXISTS ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;
session.query("CREATE KEYSPACE IF NOT EXISTS examples_ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;

session.query("USE ks", &[]).await?;
session.query("USE examples_ks", &[]).await?;

Ok(())
}
6 changes: 3 additions & 3 deletions examples/parallel-prepared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ async fn main() -> Result<()> {
let session: Session = SessionBuilder::new().known_node(uri).build().await?;
let session = Arc::new(session);

session.query("CREATE KEYSPACE IF NOT EXISTS ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;
session.query("CREATE KEYSPACE IF NOT EXISTS examples_ks WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}", &[]).await?;

session
.query(
"CREATE TABLE IF NOT EXISTS ks.t2 (a int, b int, c text, primary key (a, b))",
"CREATE TABLE IF NOT EXISTS examples_ks.parallel_prepared (a int, b int, c text, primary key (a, b))",
&[],
)
.await?;

let prepared = Arc::new(
session
.prepare("INSERT INTO ks.t2 (a, b, c) VALUES (?, ?, 'abc')")
.prepare("INSERT INTO examples_ks.parallel_prepared (a, b, c) VALUES (?, ?, 'abc')")
.await?,
);
println!("Prepared statement: {:#?}", prepared);
Expand Down
Loading

0 comments on commit b1b1ab3

Please sign in to comment.