Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rust-sqlx-integ-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
CLUSTER_ENDPOINT: ${{ needs.create-cluster.outputs.cluster-endpoint }}
REGION: ${{ needs.create-cluster.outputs.region }}
run: |
cargo run
cargo test

delete-cluster:
if: always() && needs.create-cluster.result == 'success'
Expand Down
82 changes: 41 additions & 41 deletions javascript/postgres-js/src/alternatives/websocket/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@aws-sdk/client-sts": "^3.1001.0",
"@aws-sdk/types": "^3.973.5",
"@aws-sdk/client-sts": "^3.1021.0",
"@aws-sdk/types": "^3.973.8",
"@aws/aurora-dsql-postgresjs-connector": "^0.2.1",
"buffer": "^6.0.3",
"net-browserify": "^0.2.4",
"performance-now": "^2.1.0",
"postgres": "^3.4.7",
"process": "^0.11.10",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"react-dom": "^19.2.5",
"setimmediate": "^1.0.5",
"timers-browserify": "^2.0.12"
},
Expand Down
11 changes: 11 additions & 0 deletions php/pdo-pgsql/src/example_preferred.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,29 @@
use Aws\AuroraDsql\PdoPgsql\AuroraDsql;
use Aws\AuroraDsql\PdoPgsql\DsqlConfig;

// Works with both admin and non-admin users:
// - Admin users operate in the default "public" schema
// - Non-admin users operate in a custom "myschema" schema
function main(): void
{
$clusterEndpoint = getenv('CLUSTER_ENDPOINT') ?: throw new RuntimeException(
'CLUSTER_ENDPOINT environment variable is required'
);
$clusterUser = getenv('CLUSTER_USER') ?: 'admin';

// Determine schema based on user type
$schema = $clusterUser === 'admin' ? 'public' : 'myschema';

$config = new DsqlConfig(
host: $clusterEndpoint,
user: $clusterUser,
occMaxRetries: 3,
);
$pdo = AuroraDsql::connect($config);

// Set search_path for the appropriate schema
$pdo->exec("SET search_path = '{$schema}'");

// Simple read
$stmt = $pdo->query('SELECT 1 AS result');
$row = $stmt->fetch(PDO::FETCH_ASSOC);
Expand Down
28 changes: 18 additions & 10 deletions rust/sqlx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@ edition = "2021"
include = ["/src"]

[dependencies]
tokio = { version = "1.52", features = ["full"] }
sqlx = { version = "0.8", features = [ "runtime-tokio", "tls-rustls" , "postgres", "uuid"] }
anyhow = { version = "1", features = ["backtrace"] }
aws-config = "1.8"
aws-sdk-dsql = "1.55"
rand = "0.10"
uuid = { version = "1.23", features = ["v4"] }
log = "0.4.29"
aurora-dsql-sqlx-connector = { version = "0.1", features = ["pool", "occ"] }
anyhow = "1"
tokio = { version = "1", features = ["full"] }
sqlx = { version = "0.8", features = ["runtime-tokio", "postgres"] }


[[bin]]
name = "sqlx"
path = "src/main.rs"
name = "example_preferred"
path = "src/example_preferred.rs"

[[bin]]
name = "example_no_connection_pool"
path = "src/alternatives/no_connection_pool/example_no_connection_pool.rs"

[[test]]
name = "example_preferred_test"
path = "tests/example_preferred_test.rs"

[[test]]
name = "example_no_connection_pool_test"
path = "tests/alternatives/no_connection_pool/example_no_connection_pool_test.rs"
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

use aurora_dsql_sqlx_connector::{txn, OCCRetryExt};
use sqlx::{Executor, Row};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cluster_endpoint = std::env::var("CLUSTER_ENDPOINT")
.expect("CLUSTER_ENDPOINT environment variable is not set");
let cluster_user = std::env::var("CLUSTER_USER").unwrap_or_else(|_| "admin".to_string());

let conn_str = format!("postgres://{}@{}/postgres", cluster_user, cluster_endpoint);

let mut conn = aurora_dsql_sqlx_connector::connection::connect(&conn_str).await?;

// Create table
conn.execute(
"CREATE TABLE IF NOT EXISTS owner(
id uuid NOT NULL DEFAULT gen_random_uuid(),
name varchar(30) NOT NULL,
city varchar(80) NOT NULL,
PRIMARY KEY (id))",
)
.await?;

// -- Transactional write WITH OCC retry --
conn.transaction_with_retry(None, |tx| {
txn!({
sqlx::query("INSERT INTO owner(name, city) VALUES($1, $2)")
.bind("John Doe")
.bind("Anytown")
.execute(&mut **tx)
.await?;
Ok(())
})
})
.await?;

// Query it back
let row = sqlx::query("SELECT * FROM owner WHERE name = $1")
.bind("John Doe")
.fetch_one(&mut conn)
.await?;

let name: &str = row.get("name");
let city: &str = row.get("city");
println!("name={}, city={}", name, city);

assert_eq!(name, "John Doe");
assert_eq!(city, "Anytown");

// Clean up
sqlx::query("DELETE FROM owner WHERE name = $1")
.bind("John Doe")
.execute(&mut conn)
.await?;

println!("Connection exercised successfully");
Ok(())
}
Loading
Loading