1 //! The PostgreSQL backend
2 
3 use byteorder::NetworkEndian;
4 
5 use super::query_builder::PgQueryBuilder;
6 use super::PgMetadataLookup;
7 use backend::*;
8 use prelude::Queryable;
9 use query_builder::bind_collector::RawBytesBindCollector;
10 use sql_types::{Oid, TypeMetadata};
11 
12 /// The PostgreSQL backend
13 #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
14 pub struct Pg;
15 
16 /// The [OIDs] for a SQL type
17 ///
18 /// [OIDs]: https://www.postgresql.org/docs/current/static/datatype-oid.html
19 #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Default)]
20 pub struct PgTypeMetadata {
21     /// The [OID] of `T`
22     ///
23     /// [OID]: https://www.postgresql.org/docs/current/static/datatype-oid.html
24     pub oid: u32,
25     /// The [OID] of `T[]`
26     ///
27     /// [OID]: https://www.postgresql.org/docs/current/static/datatype-oid.html
28     pub array_oid: u32,
29 }
30 
31 impl Queryable<(Oid, Oid), Pg> for PgTypeMetadata {
32     type Row = (u32, u32);
33 
build((oid, array_oid): Self::Row) -> Self34     fn build((oid, array_oid): Self::Row) -> Self {
35         PgTypeMetadata { oid, array_oid }
36     }
37 }
38 
39 impl Backend for Pg {
40     type QueryBuilder = PgQueryBuilder;
41     type BindCollector = RawBytesBindCollector<Pg>;
42     type RawValue = [u8];
43     type ByteOrder = NetworkEndian;
44 }
45 
46 impl TypeMetadata for Pg {
47     type TypeMetadata = PgTypeMetadata;
48     type MetadataLookup = PgMetadataLookup;
49 }
50 
51 impl SupportsReturningClause for Pg {}
52 impl SupportsDefaultKeyword for Pg {}
53 impl UsesAnsiSavepointSyntax for Pg {}
54