pgcopy 0.0.2

PostgreSQL binary COPY format generator
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#[cfg(feature = "with-chrono")]
mod with_chrono {
    use std::io;

    use chrono::Datelike;
    use byteorder::{WriteBytesExt, NetworkEndian};

    use crate::types::Date;

    impl<T> Date for T where T: Datelike {
        fn to_writer<W: io::Write>(&self, writer: &mut W) -> io::Result<()> {
            // TODO: Move this big number to constant with an adequate name
            let days = self.num_days_from_ce() - 730_120;
            writer.write_i32::<NetworkEndian>(4)?;
            writer.write_i32::<NetworkEndian>(days)
        }
    }
}