# Rust-Postgres
A native PostgreSQL driver for Rust.
[Documentation](https://sfackler.github.io/rust-postgres/doc/v0.10.2/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.10"
```
## 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 array types is located in the
[postgres-array](https://github.com/sfackler/rust-postgres-array) crate.
Support for range types is located in the
[postgres-range](https://github.com/sfackler/rust-postgres-range) crate.
Support for the large object API 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_json` feature, which adds implementations for `serde_json`'s `Value`
type. The `serde` feature provides implementations for the older
`serde::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.
### BIT/VARBIT types
[BIT and VARBIT](http://www.postgresql.org/docs/9.4/static/datatype-bit.html)
support is provided optionally by the `bit-vec` feature, which adds `ToSql` and
`FromSql` implementations for `bit-vec`'s `BitVec` type.
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,
chrono::DateTime<UTC>,
chrono::DateTime<Local>,
and
chrono::DateTime<FixedOffset>
(optional)
TIMESTAMP WITH TIME ZONE
chrono::NaiveDate
(optional)
DATE
chrono::NaiveTime
(optional)
TIME
uuid::Uuid
(optional)
UUID
bit_vec::BitVec
(optional)
BIT, VARBIT
HashMap<String, Option<String>>
HSTORE