Crate postgres [−] [src]
Rust-Postgres is a pure-Rust frontend for the popular PostgreSQL database. It
exposes a high level interface in the vein of JDBC or Go's database/sql
package.
extern crate postgres; use postgres::{Connection, SslMode}; struct Person { id: i32, name: String, data: Option<Vec<u8>> } fn main() { let conn = Connection::connect("postgresql://postgres@localhost", &SslMode::None) .unwrap(); conn.execute("CREATE TABLE person ( id SERIAL PRIMARY KEY, name VARCHAR NOT NULL, data BYTEA )", &[]).unwrap(); let me = Person { id: 0, name: "Steven".to_string(), data: None }; conn.execute("INSERT INTO person (name, data) VALUES ($1, $2)", &[&me.name, &me.data]).unwrap(); let stmt = conn.prepare("SELECT id, name, data FROM person").unwrap(); for row in stmt.query(&[]).unwrap() { let person = Person { id: row.get(0), name: row.get(1), data: row.get(2) }; println!("Found person {}", person.name); } }
Reexports
pub use stmt::{Statement, Column}; |
Modules
error |
Error types. |
io |
Types and traits for SSL adaptors. |
rows |
Query result rows. |
stmt |
Prepared statements |
types |
Traits dealing with Postgres data types |
Macros
accepts! |
Generates a simple implementation of |
to_sql_checked! |
Generates an implementation of |
Structs
CancelData |
Contains information necessary to cancel queries for a session. |
ConnectParams |
Information necessary to open a new connection to a Postgres server. |
Connection |
A connection to a Postgres database. |
LoggingNoticeHandler |
A notice handler which logs at the |
Notification |
An asynchronous notification. |
Notifications |
An iterator over asynchronous notifications. |
Transaction |
Represents a transaction on a database connection. |
UserInfo |
Authentication information. |
Enums
ConnectTarget |
Specifies the target server to connect to. |
IsolationLevel |
An enumeration of transaction isolation levels. |
SslMode |
Specifies the SSL support requested for a new connection. |
Traits
GenericConnection |
A trait allowing abstraction over connections and transactions |
HandleNotice |
Trait for types that can handle Postgres notice messages |
IntoConnectParams |
A trait implemented by types that can be converted into a |
Functions
cancel_query |
Attempts to cancel an in-progress query. |
Type Definitions
Result |
A type alias of the result returned by many methods. |