Skip to content

Postgres Hstore support for Diesel

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

lholden/diesel_pg_hstore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

#[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.

About

Postgres Hstore support for Diesel

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages