1 /**
2 Constants of various nature.
3 
4 Copyright: Copyright Boris-Barboris 2017-2018.
5 License: MIT
6 Authors: Boris-Barboris
7 */
8 
9 module dpeq.constants;
10 
11 
12 /// oid. Unique identifier of a Psql object. Mostly used to identify a type in dpeq.
13 alias ObjectID = int;
14 
15 /// Format of a marshalled value.
16 enum FormatCode: short
17 {
18     Text = 0,
19     Binary = 1,
20 }
21 
22 /** Small portion of statically known ids of Psql types, wich is enough
23 * to start connection and request full type list. */
24 enum StaticPgTypes: ObjectID
25 {
26     NULL = 0,
27     BOOLEAN = 16,
28     BYTEA = 17,
29     CHARACTER = 18,
30     NAME = 19,
31     BIGINT = 20,    /// int8
32     SMALLINT = 21,  /// int2
33     INT = 23,       /// int4
34     TEXT = 25,
35     OID = 26,
36     TID = 27,
37     XID = 28,
38     CID = 29,
39     PG_TYPE = 71,
40     JSON = 114,
41     XML = 142,
42     POINT = 600,
43     PATH = 602,
44     BOX = 603,
45     POLYGON = 604,
46     LINE = 628,
47     CIDR = 650,
48     REAL = 700,     /// 32-bit float
49     DOUBLE = 701,   /// 64-bit double, is actually called 'double precision'
50     ABSTIME = 702,
51     UNKNOWN = 705,
52     CIRCLE = 718,
53     MONEY = 790,
54     INET = 869,
55     VARCHAR = 1043,
56     DATE = 1082,
57     TIME = 1083,
58     TIMESTAMP = 1114,
59     INTERVAL = 1186,
60     TIMETZ = 1266,
61     BIT = 1560,
62     VARBIT = 1562,
63     NUMERIC = 1700,
64     /**
65     "Another special case is that a parameter's type can be specified as void
66     (that is, the OID of the void pseudo-type). This is meant to allow
67     parameter symbols to be used for function parameters that are actually OUT
68     parameters. Ordinarily there is no context in which a void parameter could
69     be used, but if such a parameter symbol appears in a function's parameter
70     list, it is effectively ignored. For example, a function call such as
71     foo($1,$2,$3,$4) could match a function with two IN and two OUT arguments,
72     if $3 and $4 are specified as having type void."
73     */
74     VOID = 2278,
75     UUID = 2950,
76     JSONB = 3802
77 }
78 
79 alias PgType = StaticPgTypes;
80 
81 /// Returns postgress-compatible name of the type. Throws if type OID is
82 /// unknown.
83 string pgTypeName(ObjectID pgt)
84 {
85     import std.conv: to;
86     StaticPgTypes spgt = pgt.to!StaticPgTypes;
87     switch (spgt)
88     {
89         case (StaticPgTypes.DOUBLE):
90             return "double precision";
91         default:
92             return spgt.to!string;
93     }
94 }
95 
96 /// https://www.postgresql.org/docs/9.5/static/protocol-message-formats.html
97 enum FrontMessageType: char
98 {
99     Bind = 'B',
100     Close = 'C',
101     CopyData = 'd',
102     CopyDone = 'c',
103     CopyFail = 'f',
104     Describe = 'D',
105     Execute = 'E',
106     Flush = 'H',
107     FunctionCall = 'F',
108     Parse = 'P',
109     PasswordMessage = 'p',
110     Query = 'Q',
111     Sync = 'S',
112     Terminate = 'T'
113 }
114 
115 /// https://www.postgresql.org/docs/9.5/static/protocol-message-formats.html
116 enum BackendMessageType: char
117 {
118     Authentication = 'R',
119     BackendKeyData = 'K',
120     BindComplete = '2',
121     CloseComplete = '3',
122     CommandComplete = 'C',
123     CopyData = 'd',
124     CopyDone = 'c',
125     CopyInResponse = 'G',
126     CopyOutResponse = 'H',
127     CopyBothResponse = 'W',
128     DataRow = 'D',
129     EmptyQueryResponse = 'I',
130     ErrorResponse = 'E',
131     FunctionCallResponse = 'V',
132     NoData = 'n',
133     NoticeResponse = 'N',
134     NotificationResponse = 'A',
135     ParameterDescription = 't',
136     ParameterStatus = 'S',
137     ParseComplete = '1',
138     PortalSuspended = 's',
139     ReadyForQuery = 'Z',
140     RowDescription = 'T'
141 }
142 
143 /** Content of the ReadyForQuery response message, indicating backend
144 transaction status. */
145 enum TransactionStatus: char
146 {
147     IDLE = 'I',     /// idle (not in transaction block)
148     TBLOCK = 'T',   /// in transaction block
149     /// in failed transaction block (queries will be rejected until block is ended)
150     FAILEDBLOCK = 'E'
151 }