public void CommonTypes() { var translator = new TypeTranslator(); Assert.Equal(DbType.Integer, translator.StringToType("integer")); Assert.Equal(DbType.Bool, translator.StringToType("boolean")); Assert.Equal(DbType.String, translator.StringToType("varchar")); Assert.Equal(DbType.Date, translator.StringToType("date")); Assert.Throws <ArgumentException>(() => translator.StringToType("custom type")); }
public async Task <List <Tooltip> > GetTooltips() { var results = new List <Tooltip>(); await using var metadataConnection = _factory.OpenMetadataDbConnection(); await using var subjectConnection = _factory.OpenSubjectDbConnection(); var fields = metadataConnection .Query <(string TableName, string FieldName, string FriendlyName)>(@" select table_name as TableName, field_name as FieldName, friendly_name as FriendlyName from fields where friendly_name is not null"); foreach (var(tableName, fieldName, friendlyName) in fields) { var type = await subjectConnection.QueryFirstAsync <string>(@" select data_type from information_schema.columns where table_name = @TableName and column_name = @ColumnName and table_schema = 'public'", new { TableName = tableName, ColumnName = fieldName }); var translatedType = _typeTranslator.StringToType(type); if (translatedType == DbType.Bool) { continue; } var result = await GetValues(tableName, fieldName, translatedType, subjectConnection); var values = result.ToList(); if (values.Count > 0) { var tooltip = new Tooltip { FieldName = friendlyName, Type = translatedType, Items = values }; results.Add(tooltip); } } return(results); }