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