@@ -11,19 +11,42 @@ Connect to CrateDB from Rust applications.
1111
1212[ postgres] is a synchronous Rust client for the PostgreSQL database.
1313
14- :::{rubric} Install
14+ :::{rubric} Synopsis (localhost)
1515:::
1616``` shell
1717cargo add postgres
1818```
19+ ``` rust
20+ use postgres :: {Client , NoTls };
1921
20- :::{rubric} Synopsis
22+ fn main () -> Result <(), Box <dyn std :: error :: Error >> {
23+ let mut client = Client :: connect (" postgresql://crate@localhost:5432/?sslmode=disable" , NoTls )? ;
24+
25+ for row in client . query (
26+ " SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3" ,
27+ & [],
28+ )? {
29+ let mountain : & str = row . get (0 );
30+ let height : i32 = row . get (1 );
31+ println! (" found mountain: {} {}" , mountain , height );
32+ }
33+ Ok (())
34+ }
35+ ```
36+
37+ :::{rubric} Synopsis (CrateDB Cloud)
2138:::
39+ ``` shell
40+ cargo add postgres postgres-native-tls native-tls
41+ ```
2242``` rust
23- use postgres :: {Client , NoTls };
43+ use postgres :: Client ;
44+ use native_tls :: TlsConnector ;
45+ use postgres_native_tls :: MakeTlsConnector ;
2446
2547fn main () -> Result <(), Box <dyn std :: error :: Error >> {
26- let mut client = Client :: connect (" host=localhost user=crate" , NoTls )? ;
48+ let tls = MakeTlsConnector :: new (TlsConnector :: new ()? );
49+ let mut client = Client :: connect (" postgresql://crate:<password>@<cluster-name>.<region>.cratedb.net:5432/?sslmode=require" , tls )? ;
2750
2851 for row in client . query (
2952 " SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3" ,
0 commit comments