File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -179,8 +179,7 @@ A very basic fixed-size connection pool is provided in the `pool` module. A
179179single pool can be shared across tasks and ` get_connection ` will block until a
180180connection is available.
181181``` rust
182- let pool = PostgresConnectionPool :: new (" postgres://postgres@localhost" , 5 )
183- . unwrap ();
182+ let pool = PostgresConnectionPool :: new (" postgres://postgres@localhost" , 5 );
184183
185184for _ in range (0 , 10 ) {
186185 do task :: spawn_with (pool . clone ()) | pool | {
Original file line number Diff line number Diff line change 1+ /*!
2+ Rust-Postgres is a pure-Rust frontend for the popular PostgreSQL database. It
3+ exposes a high level interface in the vein of JDBC or Go's `database/sql`
4+ package.
5+
6+ ```rust
7+ extern mod postgres;
8+
9+ use postgres::PostgresConnection;
10+ use postgres::types::ToSql;
11+
12+ #[deriving(ToStr)]
13+ struct Person {
14+ id: i32,
15+ name: ~str,
16+ awesome: bool,
17+ data: Option<~[u8]>
18+ }
19+
20+ fn main() {
21+ let conn = PostgresConnection::connect("postgres://postgres@localhost");
22+
23+ conn.update("CREATE TABLE person (
24+ id SERIAL PRIMARY KEY,
25+ name VARCHAR NOT NULL,
26+ awesome BOOL NOT NULL,
27+ data BYTEA
28+ )", []);
29+ let me = Person {
30+ id: 0,
31+ name: ~"Steven",
32+ awesome: true,
33+ data: None
34+ };
35+ conn.update("INSERT INTO person (name, awesome, data)
36+ VALUES ($1, $2, $3)",
37+ [&me.name as &ToSql, &me.awesome as &ToSql,
38+ &me.data as &ToSql]);
39+
40+ let stmt = conn.prepare("SELECT id, name, awesome, data FROM person");
41+ for row in stmt.query([]) {
42+ let person = Person {
43+ id: row[0],
44+ name: row[1],
45+ awesome: row[2],
46+ data: row[3]
47+ };
48+ println!("Found person {}", person.to_str());
49+ }
50+ }
51+ ```
52+ */
53+
154#[ desc="A native PostgreSQL driver" ] ;
255#[ license="MIT" ] ;
356
You can’t perform that action at this time.
0 commit comments