1 module hunt.database.driver.mysql.impl.codec.DataTypeDesc; 2 3 import hunt.database.driver.mysql.impl.codec.DataType; 4 5 import hunt.util.ObjectUtils; 6 import std.format; 7 8 /** 9 * 10 */ 11 struct DataTypeDesc { 12 int id; 13 string[] binaryType; 14 string[] textType; 15 16 this(int id, string[] types) { 17 this.id = id; 18 this.binaryType = types; 19 this.textType = types; 20 } 21 22 this(int id, string[] binaryType, string[] textType) { 23 this.id = id; 24 this.binaryType = binaryType; 25 this.textType = textType; 26 } 27 28 string toString() { 29 return format("DataType=%s(%d)", cast(DataType)id, id); 30 } 31 } 32 33 34 struct DataTypes { 35 enum DataTypeDesc INT1 = DataTypeDesc(ColumnType.MYSQL_TYPE_TINY, [byte.stringof, ubyte.stringof]); // Byte.class, Byte.class 36 enum DataTypeDesc INT2 = DataTypeDesc(ColumnType.MYSQL_TYPE_SHORT, [short.stringof, ushort.stringof]); // Short.class, Short.class 37 enum DataTypeDesc INT3 = DataTypeDesc(ColumnType.MYSQL_TYPE_INT24, [int.stringof, uint.stringof]); // Integer.class, Integer.class 38 enum DataTypeDesc INT4 = DataTypeDesc(ColumnType.MYSQL_TYPE_LONG, [int.stringof, uint.stringof]); // Integer.class, Integer.class 39 enum DataTypeDesc INT8 = DataTypeDesc(ColumnType.MYSQL_TYPE_LONGLONG, [long.stringof, ulong.stringof]); // Long.class, Long.class 40 enum DataTypeDesc DOUBLE = DataTypeDesc(ColumnType.MYSQL_TYPE_DOUBLE, [double.stringof]); // Double.class, Double.class 41 enum DataTypeDesc FLOAT = DataTypeDesc(ColumnType.MYSQL_TYPE_FLOAT, [float.stringof]); // Float.class, Float.class 42 enum DataTypeDesc NUMERIC = DataTypeDesc(ColumnType.MYSQL_TYPE_NEWDECIMAL, null); // Numeric.class, Numeric.class DECIMAL 43 enum DataTypeDesc STRING = DataTypeDesc(ColumnType.MYSQL_TYPE_STRING, ["string", "immutable(char)[]"]); // Buffer.class, String.class, CHAR, BINARY 44 enum DataTypeDesc VARSTRING = DataTypeDesc(ColumnType.MYSQL_TYPE_VAR_STRING, ["string", "immutable(char)[]"]); // Buffer.class, String.class, VARCHAR, VARBINARY 45 enum DataTypeDesc TINYBLOB = DataTypeDesc(ColumnType.MYSQL_TYPE_TINY_BLOB, ["string", "immutable(char)[]"]); // Buffer.class, String.class 46 enum DataTypeDesc BLOB = DataTypeDesc(ColumnType.MYSQL_TYPE_BLOB, ["string", "immutable(char)[]"]); // Buffer.class, String.class 47 enum DataTypeDesc MEDIUMBLOB = DataTypeDesc(ColumnType.MYSQL_TYPE_MEDIUM_BLOB, ["string", "immutable(char)[]"]); // Buffer.class, String.class 48 enum DataTypeDesc LONGBLOB = DataTypeDesc(ColumnType.MYSQL_TYPE_LONG_BLOB, ["string", "immutable(char)[]"]); // Buffer.class, String.class 49 enum DataTypeDesc DATE = DataTypeDesc(ColumnType.MYSQL_TYPE_DATE, null); // LocalDate.class, LocalDate.class 50 enum DataTypeDesc TIME = DataTypeDesc(ColumnType.MYSQL_TYPE_TIME, null); // Duration.class, Duration.class 51 enum DataTypeDesc DATETIME = DataTypeDesc(ColumnType.MYSQL_TYPE_DATETIME, null); // LocalDateTime.class, LocalDateTime.class 52 enum DataTypeDesc YEAR = DataTypeDesc(ColumnType.MYSQL_TYPE_YEAR, [short.stringof, ushort.stringof]); // Short.class, Short.class 53 enum DataTypeDesc TIMESTAMP = DataTypeDesc(ColumnType.MYSQL_TYPE_TIMESTAMP, null); // LocalDateTime.class, LocalDateTime.class 54 enum DataTypeDesc NULL = DataTypeDesc(ColumnType.MYSQL_TYPE_NULL, null, null); 55 56 mixin ValuesMemberTempate!DataTypeDesc; 57 58 static DataTypeDesc valueOf(int value) { 59 foreach(ref DataTypeDesc d; values()) { 60 if(d.id == value) 61 return d; 62 } 63 64 version(HUNT_DEBUG) { 65 import hunt.logging; 66 warningf("MySQL type = %d not handled - using unknown type instead", value); 67 } 68 //TODO need better handling 69 return NULL; 70 } 71 }