Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
StuartHarris committed Aug 26, 2024
1 parent 91a8497 commit 6f5fe21
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 11 deletions.
5 changes: 1 addition & 4 deletions platform-wasmcloud/wadm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ spec:
- name: sqldb-postgres
type: capability
properties:
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
image: ghcr.io/wasmcloud/sqldb-postgres:0.5.0
id: sqldb-postgres
config:
- name: default-pg
Expand Down
2 changes: 1 addition & 1 deletion wasm-components/rust/data-init/wit/world.wit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package platform-poc:di;

world di {
import wasmcloud:postgres/query@0.1.0-draft;
import wasmcloud:postgres/query@0.1.1-draft;
import wasi:keyvalue/store@0.2.0-draft;
import wasi:logging/logging;

Expand Down
2 changes: 1 addition & 1 deletion wasm-components/rust/inventory-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Guest for Component {

for sku in skus {
let sql_result = query(
"SELECT sku, quantity FROM inventory.t_inventory WHERE sku = $1",
"SELECT sku, quantity FROM inventory.t_inventory WHERE sku = $1;",
&[PgValue::Text(sku)],
)
.expect("INVENTORY-SERVICE-GET-INVENTORY: failed to query inventory");
Expand Down
2 changes: 1 addition & 1 deletion wasm-components/rust/inventory-service/wit/world.wit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package platform-poc:inventory-service;

world inventory-service {
import wasmcloud:postgres/query@0.1.0-draft;
import wasmcloud:postgres/query@0.1.1-draft;
import wasi:logging/logging;

export platform-poc:inventory/inventory@0.1.0;
Expand Down
2 changes: 1 addition & 1 deletion wasm-components/rust/orders-service/wit/world.wit
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package platform-poc:orders-service;

world orders-service {
import wasi:logging/logging;
import wasmcloud:postgres/query@0.1.0-draft;
import wasmcloud:postgres/query@0.1.1-draft;
import wasmcloud:messaging/consumer@0.2.0;

import platform-poc:inventory/inventory@0.1.0;
Expand Down
14 changes: 12 additions & 2 deletions wasm-components/wit/deps/wasmcloud/postgres/query.wit
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package wasmcloud:postgres@0.1.0-draft;
package wasmcloud:postgres@0.1.1-draft;

/// Interface for querying a Postgres database
interface query {
use types.{pg-value, result-row, query-error};

/// Query a Postgres database, leaving connection/session management
/// to the callee/implementer of this interface (normally a provider configured with conneciton credentials)
/// to the callee/implementer of this interface (normally a provider configured with connection credentials)
///
/// Queries *must* be parameterized, with named arguments in the form of `$<integer>`, for example:
///
Expand All @@ -14,6 +14,16 @@ interface query {
/// ```
///
query: func(query: string, params: list<pg-value>) -> result<list<result-row>, query-error>;

/// Perform a batch query (which could contain multiple statements) against a Postgres database,
/// leaving connection/session management to the callee/implementer of this interface
/// (normally a provider configured with connection credentials)
///
/// No user-provided or untrusted data should be used with this query -- parameters are not allowed
///
/// This query *can* be used to execute multi-statement queries (common in migrations).
///
query-batch: func(query: string) -> result<_, query-error>;
}

/// Interface for querying a Postgres database with prepared statements
Expand Down
2 changes: 1 addition & 1 deletion wasm-components/wit/deps/wasmcloud/postgres/types.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasmcloud:postgres@0.1.0-draft;
package wasmcloud:postgres@0.1.1-draft;

/// Types used by components and providers of a SQLDB Postgres interface
interface types {
Expand Down

0 comments on commit 6f5fe21

Please sign in to comment.