diff --git a/platform-wasmcloud/delete.fish b/platform-wasmcloud/down.fish similarity index 100% rename from platform-wasmcloud/delete.fish rename to platform-wasmcloud/down.fish diff --git a/platform-wasmcloud/deploy.fish b/platform-wasmcloud/up.fish similarity index 100% rename from platform-wasmcloud/deploy.fish rename to platform-wasmcloud/up.fish diff --git a/platform-wasmcloud/wadm.yaml b/platform-wasmcloud/wadm.yaml index c903a03..56cc9dd 100644 --- a/platform-wasmcloud/wadm.yaml +++ b/platform-wasmcloud/wadm.yaml @@ -177,7 +177,10 @@ spec: - name: sqldb-postgres type: capability properties: - image: ghcr.io/wasmcloud/sqldb-postgres:0.3.0 + image: ghcr.io/wasmcloud/sqldb-postgres:0.2.0 + # this one also works ... + # image: ghcr.io/wasmcloud/sqldb-postgres:877830d + # but 0.3.0 is broken. Have pinged Victor Adossi at Cosmonic in slack id: sqldb-postgres config: - name: default-pg diff --git a/wasm-components/rust/Cargo.lock b/wasm-components/rust/Cargo.lock index ed50d5c..f84cedb 100644 --- a/wasm-components/rust/Cargo.lock +++ b/wasm-components/rust/Cargo.lock @@ -121,6 +121,12 @@ dependencies = [ "serde", ] +[[package]] +name = "indoc" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" + [[package]] name = "inventory-service" version = "0.1.0" @@ -182,6 +188,7 @@ name = "orders-service" version = "0.1.0" dependencies = [ "common", + "indoc", "serde", "serde_json", "uuid", diff --git a/wasm-components/rust/orders-service/Cargo.toml b/wasm-components/rust/orders-service/Cargo.toml index 69752e0..0f7fe4e 100644 --- a/wasm-components/rust/orders-service/Cargo.toml +++ b/wasm-components/rust/orders-service/Cargo.toml @@ -8,6 +8,7 @@ crate-type = ["cdylib"] [dependencies] common = { path = "../common" } +indoc = "2.0.5" serde.workspace = true serde_json.workspace = true uuid = { version = "1.8.0", features = ["v4"] } diff --git a/wasm-components/rust/orders-service/src/lib.rs b/wasm-components/rust/orders-service/src/lib.rs index 1ef5cc9..a85db19 100644 --- a/wasm-components/rust/orders-service/src/lib.rs +++ b/wasm-components/rust/orders-service/src/lib.rs @@ -11,6 +11,7 @@ wit_bindgen::generate!({ generate_all, }); +use indoc::indoc; use std::collections::HashMap; use uuid::Uuid; @@ -35,7 +36,11 @@ struct Component; impl Guest for Component { #[doc = r" Creates an `order` for specified line items"] fn create_order(items: Vec) -> Result<(), Error> { - log(Level::Info, "orders-service", "Order request received..."); + log( + Level::Info, + "orders-service", + &format!("Order request received: {:?}", items), + ); let skus: Vec = items.iter().map(|item| item.sku.clone()).collect(); @@ -61,9 +66,11 @@ impl Guest for Component { ]; let id = query( - "-- Create line item - INSERT INTO orders.t_order_line_items (price, quantity, sku) - VALUES ($1, $2, $3) RETURNING id;", + indoc! {" + -- Create order line item + INSERT INTO orders.t_order_line_items (price, quantity, sku) + VALUES ($1, $2, $3) RETURNING id; + "}, ¶ms, ) .expect("ORDER-SERVICE-CREATE-ORDER: Failed to insert order line item"); @@ -80,9 +87,11 @@ impl Guest for Component { let order_number = Uuid::new_v4().to_string(); let pg_response = query( - "-- Create order entry - INSERT INTO orders.t_orders (order_number, total) - VALUES ($1, $2) RETURNING id", + indoc! {" + -- Create order entry + INSERT INTO orders.t_orders (order_number, total) + VALUES ($1, $2) RETURNING id; + "}, &[ PgValue::Text(order_number.clone()), PgValue::Integer(*total), @@ -100,9 +109,11 @@ impl Guest for Component { for id in ids { query( - "-- Link order and line items - INSERT INTO orders.t_orders_order_line_items_list (order_id, order_line_items_list_id) - VALUES ($1, $2);", + indoc! {" + -- Link order and line items + INSERT INTO orders.t_orders_order_line_items_list (order_id, order_line_items_list_id) + VALUES ($1, $2); + "}, &[PgValue::BigInt(order_id.parse().unwrap()), PgValue::BigInt(id.parse().unwrap())], ).expect("ORDER-SERVICE-CREATE-ORDER: Failed to link order and line items"); } @@ -145,7 +156,7 @@ impl Guest for Component { #[doc = r" Lists all orders"] fn get_orders() -> Result, Error> { - let get_orders_query = r#" + let get_orders_query = indoc! {r#" SELECT "order".order_number, "order".total as order_total, @@ -155,7 +166,8 @@ impl Guest for Component { FROM orders.t_order_line_items as line_items JOIN orders.t_orders_order_line_items_list as order_lines ON "order_lines".order_line_items_list_id = "line_items".id - JOIN orders.t_orders as "order" ON "order".id = "order_lines".order_id;"#; + JOIN orders.t_orders as "order" ON "order".id = "order_lines".order_id; + "#}; let rows = query(get_orders_query, &[]).expect("ORDER-SERVICE-GET-ORDERS: Failed to get orders"); diff --git a/wasm-components/wit/deps/wasmcloud/postgres/query.wit b/wasm-components/wit/deps/wasmcloud/postgres/query.wit index 1309e90..e044f1a 100644 --- a/wasm-components/wit/deps/wasmcloud/postgres/query.wit +++ b/wasm-components/wit/deps/wasmcloud/postgres/query.wit @@ -45,4 +45,4 @@ interface prepared { stmt-token: prepared-statement-token, params: list, ) -> result; -} \ No newline at end of file +}