Docs.rs
  • tokio-postgres-0.2.0
    • tokio-postgres 0.2.0
    • Docs.rs crate page
    • MIT
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • sfackler
    • Dependencies
      • futures-state-stream ^0.1
      • tokio-openssl ^0.1
      • futures ^0.1.7
      • postgres-protocol ^0.2
      • postgres-shared ^0.2
      • tokio-core ^0.1
      • fallible-iterator ^0.1.3
      • tokio-uds ^0.1
      • tokio-dns-unofficial ^0.1
      • openssl ^0.9
    • Versions
  • Go to latest version
  • Platform
    • i686-apple-darwin
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crates

  • tokio_postgres

Crate tokio_postgres [−] [src]

[−] Expand description

An asynchronous Postgres driver using Tokio.

Example

extern crate futures;
extern crate futures_state_stream;
extern crate tokio_core;
extern crate tokio_postgres;

use futures::Future;
use futures_state_stream::StateStream;
use tokio_core::reactor::Core;
use tokio_postgres::{Connection, TlsMode};

struct Person {
    id: i32,
    name: String,
    data: Option<Vec<u8>>
}

fn main() {
    let mut l = Core::new().unwrap();
    let done = Connection::connect("postgresql://postgres@localhost", TlsMode::None, &l.handle())
        .then(|c| {
            c.unwrap()
                .batch_execute("CREATE TABLE person (
                                    id              SERIAL PRIMARY KEY,
                                    name            VARCHAR NOT NULL,
                                    data            BYTEA
                                )")
        })
        .and_then(|c| c.prepare("INSERT INTO person (name, data) VALUES ($1, $2)"))
        .and_then(|(s, c)| c.execute(&s, &[&"Steven", &None::<Vec<u8>>]))
        .and_then(|(_, c)| c.prepare("SELECT id, name, data FROM person"))
        .and_then(|(s, c)| {
            c.query(&s, &[])
                .for_each(|row| {
                    let person = Person {
                        id: row.get(0),
                        name: row.get(1),
                        data: row.get(2),
                    };
                    println!("Found person {}", person.name);
                    Ok(())
                })
        });

    l.run(done).unwrap();
}

Modules

error

Error types.

params

Connection parameters

rows

Postgres rows.

stmt

Prepared statements.

tls

TLS support.

transaction

Transactions.

types

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

Connection

A connection to a Postgres database.

Enums

TlsMode

Specifies the TLS support required for a new connection.

Functions

cancel_query

Attempts to cancel an in-progress query.

Results for Handshake

tokio_postgres::tls::HandshakeA trait implemented by types that can manage TLS encryption for a stream. 
tokio_postgres::tls::Handshake::handshakePerforms a TLS handshake, returning a wrapped stream. 

Help

Keyboard Shortcuts

?
Show this help dialog
S
Focus the search field
⇤
Move up in search results
⇥
Move down in search results
⏎
Go to active search result
+
Collapse/expand all sections

Search Tricks

Prefix searches with a type followed by a colon (e.g. fn:) to restrict the search to a given type.

Accepted types are: fn, mod, struct, enum, trait, type, macro, and const.

Search functions by type signature (e.g. vec -> usize or * -> vec)