# Rust-Postgres
A native PostgreSQL driver for Rust.
Documentation is available at https://sfackler.github.io/rust-postgres/doc/v0.8.9/postgres
[](https://travis-ci.org/sfackler/rust-postgres) [](https://crates.io/crates/postgres)
You can integrate Rust-Postgres into your project through the [releases on crates.io](https://crates.io/crates/postgres):
```toml
# Cargo.toml
[dependencies]
postgres = "0.8"
```
## Overview
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.
```rust
extern crate postgres;
use postgres::{Connection, SslMode};
struct Person {
id: i32,
name: String,
data: Option
More conversions can be defined by implementing the `ToSql` and `FromSql`
traits.
Support for Postgres arrays is located in the
[postgres-array](https://github.com/sfackler/rust-postgres-array) crate.
Support for Postgres ranges is located in the
[postgres-range](https://github.com/sfackler/rust-postgres-range) crate.
Support for Postgres large objects is located in the
[postgres-large-object](https://github.com/sfackler/rust-postgres-large-object) crate.
## Optional features
### Unix socket connections
Support for connections through Unix domain sockets is provided optionally by
the `unix_socket` feature. It is only available on "unixy" platforms such as
OSX, BSD and Linux.
### UUID type
[UUID](http://www.postgresql.org/docs/9.4/static/datatype-uuid.html) support is
provided optionally by the `uuid` feature, which adds `ToSql` and `FromSql`
implementations for `uuid`'s `Uuid` type.
### JSON/JSONB types
[JSON and JSONB](http://www.postgresql.org/docs/9.4/static/datatype-json.html)
support is provided optionally by the `rustc-serialize` feature, which adds
`ToSql` and `FromSql` implementations for `rustc-serialize`'s `Json` type, and
the `serde` feature, which adds implementations for `serde`'s `json::Value`
type.
### TIMESTAMP/TIMESTAMPTZ/DATE/TIME types
[Date and Time](http://www.postgresql.org/docs/9.1/static/datatype-datetime.html)
support is provided optionally by the `time` feature, which adds `ToSql` and
`FromSql` implementations for `time`'s `Timespec` type, or the `chrono`
feature, which adds `ToSql` and `FromSql` implementations for `chrono`'s
`DateTime`, `NaiveDateTime`, `NaiveDate` and `NaiveTime` types.
Rust Type
Postgres Type
bool
BOOL
i8
"char"
i16
SMALLINT, SMALLSERIAL
i32
INT, SERIAL
u32
OID
i64
BIGINT, BIGSERIAL
f32
REAL
f64
DOUBLE PRECISION
str/String
VARCHAR, CHAR(n), TEXT, CITEXT
[u8]/Vec<u8>
BYTEA
serialize::json::Json
and
serde::json::Value
(optional)
JSON, JSONB
time::Timespec
and
chrono::NaiveDateTime
(optional)
TIMESTAMP
time::Timespec
and
chrono::DateTime<UTC>
(optional)
TIMESTAMP WITH TIME ZONE
chrono::NaiveDate
(optional)
DATE
chrono::NaiveTime
(optional)
TIME
uuid::Uuid
(optional)
UUID
HashMap<String, Option<String>>
HSTORE