1 module pgsql.protocol; 2 3 //https://www.postgresql.org/docs/10/static/protocol-message-formats.html 4 enum OutputMessageType : ubyte { 5 Bind = 'B', 6 Close = 'C', 7 CopyData = 'd', 8 CopyDone = 'c', 9 CopyFail = 'f', 10 Describe = 'D', 11 Execute = 'E', 12 Flush = 'H', 13 FunctionCall = 'F', 14 Parse = 'P', 15 PasswordMessage = 'p', 16 Query = 'Q', 17 Sync = 'S', 18 Terminate = 'T' 19 } 20 21 22 enum InputMessageType : ubyte { 23 Authentication = 'R', 24 BackendKeyData = 'K', 25 BindComplete = '2', 26 CloseComplete = '3', 27 CommandComplete = 'C', 28 CopyData = 'd', 29 CopyDone = 'c', 30 CopyInResponse = 'G', 31 CopyOutResponse = 'H', 32 CopyBothResponse = 'W', 33 DataRow = 'D', 34 EmptyQueryResponse = 'I', 35 ErrorResponse = 'E', 36 FunctionCallResponse= 'V', 37 NoData = 'n', 38 NoticeResponse = 'N', 39 NotificationResponse= 'A', 40 ParameterDescription= 't', 41 ParameterStatus = 'S', 42 ParseComplete = '1', 43 PortalSuspended = 's', 44 ReadyForQuery = 'Z', 45 RowDescription = 'T' 46 } 47 48 49 enum TransactionStatus : ubyte { 50 Idle = 'I', 51 Inside = 'T', 52 Error = 'E', 53 } 54 55 56 enum FormatCode : ubyte { 57 Text = 0, 58 Binary = 1, 59 } 60 61 62 enum NoticeMessageField : ubyte { 63 SeverityLocal = 'S', 64 Severity = 'V', 65 Code = 'C', 66 Message = 'M', 67 Detail = 'D', 68 Hint = 'H', 69 Position = 'P', 70 InternalPosition = 'p', 71 InternalQuery = 'q', 72 Where = 'W', 73 Schema = 's', 74 Table = 't', 75 Column = 'c', 76 DataType = 'd', 77 Constraint = 'n', 78 File = 'F', 79 Line = 'L', 80 Routine = 'R', 81 } 82 83 // https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat 84 enum PgColumnTypes : uint { 85 NULL = 0, 86 BOOL = 16, 87 BYTEA = 17, 88 CHAR = 18, 89 NAME = 19, 90 INT8 = 20, 91 INT2 = 21, 92 // INTVEC2 = 22, 93 INT4 = 23, 94 //REGPROC = 24, 95 TEXT = 25, 96 // OID = 26, 97 // TID = 27, 98 // XID = 28, 99 // CID = 29, 100 // OIDARRAY = 30, 101 102 // PG_TYPE = 71, 103 // PG_ATTRIBUTE= 75, 104 // PG_PROC = 81, 105 // PG_CLASS = 83, 106 107 JSON = 114, 108 XML = 142, 109 110 POINT = 600, 111 LSEG = 601, 112 PATH = 602, 113 BOX = 603, 114 POLYGON = 604, 115 LINE = 628, 116 117 REAL = 700, 118 DOUBLE = 701, 119 // ABSTIME = 702, 120 // RELTIME = 703, 121 TINTERVAL = 704, 122 UNKNOWN = 705, 123 CIRCLE = 718, 124 MONEY = 790, 125 126 MACADDR = 829, 127 INET = 869, 128 CIDR = 650, 129 MACADDR8 = 774, 130 131 CHARA = 1042, 132 VARCHAR = 1043, 133 DATE = 1082, 134 TIME = 1083, 135 136 TIMESTAMP = 1114, 137 TIMESTAMPTZ = 1184, 138 INTERVAL = 1186, 139 140 TIMETZ = 1266, 141 142 BIT = 1560, 143 VARBIT = 1562, 144 145 NUMERIC = 1700, 146 // REFCURSOR = 1790, 147 148 // REGPROCEDURE= 2202, 149 // REGOPER = 2203, 150 // REGOPERATOR = 2204, 151 // REGCLASS = 2205, 152 // REGTYPE = 2206, 153 // REGROLE = 4096, 154 // REGNAMESPACE= 4089, 155 156 UUID = 2950, 157 JSONB = 3802 158 } 159 160 161 auto columnTypeName(PgColumnTypes type) { 162 final switch (type) with (PgColumnTypes) { 163 case NULL: return "null"; 164 case BOOL: return "bool"; 165 case BYTEA: return "bytea"; 166 case CHAR: return "char"; 167 case NAME: return "name"; 168 case INT8: return "int8"; 169 case INT2: return "int2"; 170 case INT4: return "int4"; 171 case TEXT: return "text"; 172 case JSON: return "json"; 173 case XML: return "xml"; 174 case POINT: return "point"; 175 case LSEG: return "lseg"; 176 case PATH: return "path"; 177 case BOX: return "box"; 178 case POLYGON: return "polygon"; 179 case LINE: return "line"; 180 case REAL: return "real"; 181 case DOUBLE: return "double precision"; 182 case TINTERVAL: return "tinterval"; 183 case UNKNOWN: return "unknown"; 184 case CIRCLE: return "circle"; 185 case MONEY: return "money"; 186 case MACADDR: return "macaddr"; 187 case INET: return "inet"; 188 case CIDR: return "cidr"; 189 case MACADDR8: return "macaddr8"; 190 case CHARA: return "char(n)"; 191 case VARCHAR: return "varchar"; 192 case DATE: return "date"; 193 case TIME: return "time"; 194 case TIMESTAMP: return "timestamp"; 195 case TIMESTAMPTZ: return "timestamptz"; 196 case INTERVAL: return "interval"; 197 case TIMETZ: return "timetz"; 198 case BIT: return "bit"; 199 case VARBIT: return "varbit"; 200 case NUMERIC: return "numeric"; 201 case UUID: return "uuid"; 202 case JSONB: return "jsonb"; 203 } 204 }