diesel_pg_hstore

Crates.iodiesel_pg_hstore
lib.rsdiesel_pg_hstore
version0.2.0
sourcesrc
created_at2017-12-12 19:28:50.78792
updated_at2017-12-12 20:57:54.561009
descriptionPostgres Hstore support for Diesel
homepage
repositoryhttps://github.com/lholden/diesel_pg_hstore
max_upload_size
id42875
size34,744
Lori Holden (lholden)

documentation

https://docs.rs/diesel_pg_hstore/

README

Postgres Hstore for Diesel

This crate provides an Hstore type for use with Diesel and Postgres.

Currently only serializing to and from hstore columns is supported. If someone would be interested in building out support for the Postgres hstore query syntax, help would be appreciated!

Usage

Please see the Documentation for more details.

Add diesel_pg_hstore to your Cargo.toml:

[dependencies]
diesel_pg_hstore = "*"

Bring the crate into your project. (For example, from your lib.rs file)

extern diesel_pg_hstore;

Using the Hstore type with Diesel

The type must be present in the table! definition for your schema. There is currently no easy way to provide this without explicitly adding it to each table! requiring the type manually.

Once Diesel 1.0 is out of beta, Diesel will be providing the ability for both the diesel print-schema command and the infer_schema! macro to bring external types into scope. For now, I recommend not using the infer_schema! macro.

If you are using the diesel print-schema command to regenerate your schema, you might consider creating a .patch file that contains the required use diesel_pg_hstore::Hstore; statements for bringing the Hstore type into scope as needed.

Using the Hstore

#[macro_use] extern crate diesel;
extern crate diesel_pg_hstore;

use std::collections::HashMap;
use diesel::prelude::*;
use diesel_pg_hstore::Hstore;

table! {
    use diesel::types::*;
    use diesel_pg_hstore::Hstore;

    user_profile {
        id -> Integer,
        settings -> Hstore,
    }
}

#[derive(Insertable, Debug, PartialEq)]
#[table_name="user_profile"]
struct NewUserProfile {
    settings: Hstore,
}

fn main() {
    let mut settings = HashMap::new();
    settings.insert("Hello".to_string(), "World".to_string());

    let profile = NewUserProfile { settings: Hstore::from_hashmap(settings) };
}

For your convenience, the Hstore type also provides proxy methods to the standard HashMap functions.

License

diesel_pg_hstore is licensed under either of

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Please see the CONTRIBUTING file for more information.

Commit count: 15

cargo fmt