Skip to content

Commit 7321107

Browse files
author
Prabakaran Annadurai
committed
Update Rust SQLx README to reflect connector usage
1 parent 15752c2 commit 7321107

1 file changed

Lines changed: 34 additions & 26 deletions

File tree

rust/sqlx/README.md

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
# Aurora DSQL with Rust
1+
# Aurora DSQL with Rust SQLx
22

33
## Overview
44

5-
This code example demonstrates how to use Rust SQLx with Amazon Aurora DSQL. The example shows you how to connect to an
6-
Aurora DSQL cluster and perform basic database operations.
5+
This code example demonstrates how to use SQLx with Amazon Aurora DSQL.
6+
The example shows you how to connect to an Aurora DSQL cluster and perform basic database operations.
77

8-
Aurora DSQL is a distributed SQL database service that provides high availability and scalability for your
9-
PostgreSQL-compatible applications. SQLx is a popular SQL toolkit for Rust that allows you to interact with PostgreSQL
10-
databases using Rust code.
8+
Aurora DSQL is a distributed SQL database service that provides high availability and scalability for
9+
your PostgreSQL-compatible applications. SQLx is a popular async SQL toolkit for Rust that allows
10+
you to interact with PostgreSQL databases using Rust code.
1111

1212
## About the code example
1313

14-
The example demonstrates a flexible connection approach that works for both admin and non-admin users:
14+
This example uses the [Aurora DSQL SQLx Connector](https://github.com/awslabs/aurora-dsql-connectors/tree/main/rust/sqlx) which automatically handles IAM token generation for authentication.
1515

16-
* When connecting as an **admin user**, the example uses the `public` schema and generates an admin authentication
17-
token.
18-
* When connecting as a **non-admin user**, the example uses a custom `myschema` schema and generates a standard
19-
authentication token.
16+
The preferred example (`example_preferred`) uses connection pooling with automatic token management and OCC retry support. It demonstrates a flexible approach that works for both admin and non-admin users:
2017

21-
The code automatically detects the user type and adjusts its behavior accordingly.
18+
* When connecting as an **admin user**, the example uses the `public` schema.
19+
* When connecting as a **non-admin user**, the example uses a custom `myschema` schema.
2220

23-
## ⚠️ Important
21+
The **no connection pool example** (`example_no_connection_pool`) demonstrates simpler single-connection usage without pooling or automatic schema detection.
22+
23+
## Important
2424

2525
* Running this code might result in charges to your AWS account.
2626
* We recommend that you grant your code least privilege. At most, grant only the
@@ -48,18 +48,15 @@ The code automatically detects the user type and adjusts its behavior accordingl
4848

4949
### Run the code
5050

51-
The example demonstrates the following operations:
51+
The **preferred example** demonstrates the following operations:
5252

53-
- Opening a pooled connection to an Aurora DSQL cluster with periodic credential refresh
53+
- Opening a connection pool to an Aurora DSQL cluster
5454
- Creating a table
55-
- Inserting and querying data
56-
57-
The example is designed to work with both admin and non-admin users:
58-
59-
- When run as an admin user, it uses the `public` schema
60-
- When run as a non-admin user, it uses the `myschema` schema
55+
- Performing a transactional insert with OCC retry using the `OCCRetryExt` trait (transactions must be idempotent)
56+
- Opting out of OCC retry for operations that don't need it
57+
- Running concurrent queries across multiple tokio tasks
6158

62-
**Note:** running the example will use actual resources in your AWS account and may incur charges.
59+
**Note:** Running the example will use actual resources in your AWS account and may incur charges.
6360

6461
Set environment variables for your cluster details:
6562

@@ -69,23 +66,34 @@ export CLUSTER_USER="<your user>"
6966

7067
# e.g. "foo0bar1baz2quux3quuux4.dsql.us-east-1.on.aws"
7168
export CLUSTER_ENDPOINT="<your endpoint>"
69+
```
70+
71+
Run the preferred example (connection pool with OCC retry):
7272

73-
# e.g. "us-east-1"
74-
export REGION="<your region>"
73+
```bash
74+
cargo run --bin example_preferred
75+
```
76+
77+
Run the no connection pool example:
78+
79+
```bash
80+
cargo run --bin example_no_connection_pool
7581
```
7682

77-
Run the example:
83+
Run the tests:
7884

7985
```bash
80-
cargo run
86+
cargo test
8187
```
8288

8389
The example contains comments explaining the code and the operations being performed.
8490

8591
## Additional resources
8692

8793
* [Amazon Aurora DSQL Documentation](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/what-is-aurora-dsql.html)
94+
* [Aurora DSQL SQLx Connector](https://github.com/awslabs/aurora-dsql-connectors/tree/main/rust/sqlx)
8895
* [SQLx Documentation](https://docs.rs/sqlx/latest/sqlx/)
96+
* [AWS SDK for Rust Documentation](https://docs.aws.amazon.com/sdk-for-rust/latest/dg/welcome.html)
8997

9098
---
9199

0 commit comments

Comments
 (0)