```rust extern crate chrono;
use chrono::{DateTime, NaiveDate, TimeZone, Utc}; use impltable::{impltable, Table};
// Optionally generate an id column and two timestamp columns: createdat and // updatedat.
struct Book { #[column] pub name: String, #[column] publishedat: NaiveDate, #[column(name = "authorname")] author: String, }
let book = Book { id: 1, name: "The Man in the High Castle".into(), publishedat: NaiveDate::fromymd(1962, 10, 1), author: "Philip K. Dick".into(),
created_at: Utc.ymd(2019, 5, 22).and_hms(8, 0, 0),
updated_at: Utc.ymd(2019, 5, 22).and_hms(8, 0, 0),
}; ```
The above code generates an implementation like the following:
```rust extern crate chrono;
use chrono::{DateTime, NaiveDate, TimeZone, Utc};
struct Book { id: i64, pub name: String, published_at: NaiveDate, author: i64,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
}
impl Book { pub const TABLENAME: &'static str = "books"; pub const ADAPTORNAME: &'static str = "rusqlite";
fn table_name() -> &'static str {
Self::TABLE_NAME
}
fn all_columns() -> &'static [&'static str] {
&["id", "name", "published_at", "author_name", "created_at", "updated_at"]
}
fn from_row(row: &rusqlite::Row) -> rusqlite::Result<Self> {
Ok(Self {
id: row.get(0)?,
name: row.get(1)?,
published_at: row.get(2)?,
author: row.get(3)?,
created_at: row.get(4)?,
updated_at: row.get(5)?,
})
}
} ```
For more examples see test/sample.rs
.