Crate postgres [] [src]

A pure-Rust frontend for the popular PostgreSQL database.

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_owned(),
        data: None
    };
    conn.execute("INSERT INTO person (name, data) VALUES ($1, $2)",
                 &[&me.name, &me.data]).unwrap();

    for row in &conn.query("SELECT id, name, data FROM person", &[]).unwrap() {
        let person = Person {
            id: row.get(0),
            name: row.get(1),
            data: row.get(2)
        };
        println!("Found person {}", person.name);
    }
}

Modules

error

Error types.

io

Types and traits for SSL adaptors.

notification

Asynchronous notifications.

rows

Query result rows.

stmt

Prepared statements

types

Traits dealing with Postgres data types

Macros

accepts!

Generates a simple implementation of ToSql::accepts which accepts the types passed to it.

to_sql_checked!

Generates an implementation of ToSql::to_sql_checked.

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 info level.

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 ConnectParams.

Functions

cancel_query

Attempts to cancel an in-progress query.

Type Definitions

Result

A type alias of the result returned by many methods.