Add doctest for `pg::sql_types::Money`.
@@ -217,6 +217,64 @@ pub mod sql_types {
/// - [`PgCents`][PgCents]
///
/// [PgCents]: /diesel/pg/data_types/struct.PgCents.html
- #[derive(Debug, Clone, Copy, Default)]
- pub struct Money;
+ ///
+ /// # Examples
+ ///
+ /// ```rust
+ /// # #![allow(dead_code)]
+ /// # #[macro_use] extern crate diesel_codegen;
+ /// # #[macro_use] extern crate diesel;
+ /// # include!("src/doctest_setup.rs");
+ /// #
+ /// # table! {
+ /// # users {
+ /// # id -> Serial,
+ /// # name -> VarChar,
+ /// # }
+ /// # }
+ /// #
+ ///
+ /// use diesel::data_types::Cents;
+ ///
+ /// #[derive(Queryable)]
+ /// struct Item {
+ /// id: i32,
+ /// name: String,
+ /// price: Cents,
+ /// }
+ ///
+ /// #[derive(Insertable)]
+ /// #[table_name="items"]
+ /// struct NewItem {
+ /// name: String,
+ /// price: Cents,
+ /// }
+ ///
+ /// table! {
+ /// items {
+ /// id -> Integer,
+ /// name -> VarChar,
+ /// price -> Money,
+ /// }
+ /// }
+ ///
+ /// # fn main() {
+ /// # use self::diesel::insert;
+ /// # use self::items::dsl::*;
+ /// # let connection = connection_no_data();
+ /// # connection.execute("CREATE TABLE items (
+ /// # id SERIAL PRIMARY KEY,
+ /// # name VARCHAR NOT NULL,
+ /// # price MONEY NOT NULL
+ /// # )").unwrap();
+ /// let new_item = NewItem {
+ /// name: "Shiny Thing".into(),
+ /// price: Cents(123456),
+ /// };
+ /// let inserted_item = insert(&new_item).into(items)
+ /// .get_result::<Item>(&connection).unwrap();
+ /// assert_eq!(Cents(123456), inserted_item.price);
+ /// # }
+ /// ```
+ #[derive(Debug, Clone, Copy, Default)] pub struct Money;
}
