public (string typeName, string[] attributes) Convert(MySqlColumnDataDefinition data) => data.IsNullable
private (string typeName, string[] attributes) NonNullableConverter(MySqlColumnDataDefinition data) { switch (data.DataType) { // sbyte/byte case "TINYINT" when data.IsUnsigned && data.Length == 4: return("byte", none); case "TINYINT" when data.Length == 4: return("sbyte", none); case "TINYINT": return("byte", none); // short/ushort case "SMALLINT" when data.IsUnsigned && data.Length == 6: return("ushort", none); case "SMALLINT" when data.Length == 6: return("short", none); case "SMALLINT": return("short", none); // int/uint case "INT" when data.IsUnsigned: return("uint", none); case "INT": return("int", none); // long/ulong case "BIGINT" when data.IsUnsigned: return("ulong", none); case "BIGINT": return("long", none); // float/double case "FLOAT": return("float", none); case "DOUBLE": return("double", none); // decimal case "DECIMAL": return("decimal", none); // bool case "BIT": return("bool", none); // clr char: no hanlding // string case "TINYTEXT": // fallthrough case "TEXT": // fallthrough case "MEDIUMTEXT": // fallthrough case "LONGTEXT": // fallthrough case "VARCHAR": return("string", StringLength(data) is string sl ? new[] { Required, sl } : new[] { Required }); // byte[] case "TINYBLOB": // fallthrough case "BLOB": // fallthrough case "MEDIUMBLOB": // fallthrough case "LONGBLOB": // fallthrough case "BINARY": // fallthrough case "VARBINARY": return("byte[]", ArrayLength(data) is string al ? new[] { Required, al } : new[] { Required }); // DateTimeOffset case "DATETIME": return("DateTimeOffset", none); // byte[] // mysql TIMESTAMP should handle as RowVersion in MSSQL, means CLR byte[] and [Timestamp] attribute case "TIMESTAMP": return("byte[]", new[] { Timestamp }); default: throw new NotSupportedException(data.DataType); } }
private static string ArrayLength(MySqlColumnDataDefinition data) => data.Length.HasValue && data.Length != 0 ? $"MaxLength({data.Length})" : null;