diff --git a/inline-postgres/Cargo.toml b/inline-postgres/Cargo.toml index 50d4e47..ecefe27 100644 --- a/inline-postgres/Cargo.toml +++ b/inline-postgres/Cargo.toml @@ -7,4 +7,7 @@ edition = "2021" [dependencies] inline-postgres-impl = { path = "../inline-postgres-impl" } -inline-postgres-macros = { path = "../inline-postgres-macros" } \ No newline at end of file +inline-postgres-macros = { path = "../inline-postgres-macros" } + +[dev-dependencies] +tokio = { version = "1", features = ["full"] } \ No newline at end of file diff --git a/inline-postgres/examples/atla.rs b/inline-postgres/examples/atla.rs new file mode 100644 index 0000000..1b16681 --- /dev/null +++ b/inline-postgres/examples/atla.rs @@ -0,0 +1,50 @@ +use inline_postgres as pg; +use inline_postgres::prelude::*; + +#[tokio::main] +async fn main() -> Result<(), pg::Error> { + let (client, connection) = pg::connect("host=localhost user=postgres", pg::NoTls).await?; + + // wait for the connection + tokio::spawn(async move { + if let Err(e) = connection.await { + eprintln!("connection error: {}", e); + } + }); + + client.exec(stmt!{ + CREATE TABLE KID ( + NAME VARCHAR(10), + AGE INT4 + ) + }).await?; + + client.exec(stmt!{ + INSERT INTO KID (NAME, AGE) + VALUES + ("Aang", 12), + ("Sokka", 14), + ("Toph", 12), + ("Zuko", 16) + }).await?; + + let actual_age = 112; + + client.exec(stmt!{ + UPDATE KID + SET AGE = {actual_age} + WHERE NAME = "Aang" + }).await?; + + let ages = client.fetch(sql! { + SELECT SUM(AGE) as [sum: i64] FROM KID + }).await?; + + println!("{}", ages[0].sum); + + client.exec(stmt! { + DROP TABLE KID + }).await?; + + Ok(()) +} diff --git a/inline-postgres/examples/output.rs b/inline-postgres/examples/output.rs deleted file mode 100644 index 1dda2e0..0000000 --- a/inline-postgres/examples/output.rs +++ /dev/null @@ -1,18 +0,0 @@ -use inline_postgres as pg; -use inline_postgres::prelude::*; - -fn main() -> Result<(), pg::Error> { - let mut client = pg::Client::connect("host=localhost, user=postgres", pg::NoTls)?; - - let x = 5; - - let rows = client.fetch(sql! { - select 1 as [a:i32], generate_series(1, {x}) as [b: i32] - })?; - - for row in rows { - println!("{row:?}"); - } - - Ok(()) -}