You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: rust/sqlx/README.md
+34-26Lines changed: 34 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,26 @@
1
-
# Aurora DSQL with Rust
1
+
# Aurora DSQL with Rust SQLx
2
2
3
3
## Overview
4
4
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.
7
7
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.
11
11
12
12
## About the code example
13
13
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.
15
15
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:
20
17
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.
22
20
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
24
24
25
25
* Running this code might result in charges to your AWS account.
26
26
* 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
48
48
49
49
### Run the code
50
50
51
-
The example demonstrates the following operations:
51
+
The **preferred example** demonstrates the following operations:
52
52
53
-
- Opening a pooled connection to an Aurora DSQL cluster with periodic credential refresh
53
+
- Opening a connection pool to an Aurora DSQL cluster
54
54
- 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
61
58
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.
63
60
64
61
Set environment variables for your cluster details:
0 commit comments