string GetTableName <TEntity>(KeyTypeStore keyStore) { var tableInfo = Reflector.GetTableInfo <TEntity>(); var schema = tableInfo.schema.IsEmpty() ? string.Empty : $"{tableInfo.schema}."; var table = keyStore.Container.OtherIfThisEmpty(tableInfo.tableName.OtherIfThisEmpty(typeof(TEntity).Name)); return($"{schema}{table}"); }
string ColumnScript(string name, PropertyInfo propertyInfo, KeyTypeStore keyStore, ColumnSchema schema, char comma) { var type = Type.GetTypeCode(propertyInfo.PropertyType); var typeStatement = dataTypes.ContainsKey(type) ? dataTypes[type] : dataTypes[TypeCode.String]; var maxLen = Reflector.GetCustomAttribute <MaxLengthAttribute>(propertyInfo); var maxLenStatement = maxLen != null ? $" ({maxLen.Length})" : string.Empty; var required = Reflector.GetCustomAttribute <RequiredAttribute>(propertyInfo); var primaryKey = !keyStore.Keys.Exists(propertyInfo.Name) ? string.Empty : PrimaryKey; return($"[{name}] {typeStatement}{maxLenStatement}{(required == null ? string.Empty : NotNull)}{primaryKey}{comma}"); }
DeleteItemRequest CreateDeleteRequest <TEntity>(string container, KeyTypeStore keyStore, TEntity entity) { var propInfo = Reflector.GetPropertyInfoValue(entity); var keys = keyStore.SpecialKeys.SelectMany(l => l.Value); return(new DeleteItemRequest { TableName = container, Key = keys.ToDictionary(k => k, v => CreateAttributeValue(propInfo[v].info, propInfo[v].value)) }); }
CreateTableRequest CreateSchemaCreateRequest <TEntity>(string container, KeyTypeStore keyStore) where TEntity : class { var propInfo = Reflector.GetPropertyInfo <TEntity>(); var attributes = new List <AttributeDefinition>(); var keys = new List <KeySchemaElement>(); foreach (var key in keyStore.SpecialKeys) { var name = key.Value[0]; attributes.Add(CreateAttributeDefinition(name, propInfo[name])); keys.Add(CreateKeySchemaElement(key.Key, name)); } return(new CreateTableRequest { TableName = container, AttributeDefinitions = attributes, KeySchema = keys, ProvisionedThroughput = new ProvisionedThroughput(1, 1) /* Default */ }); }
void GenerateAddSql(KeyTypeStore keyStore, string table, List <(string Name, PropertyInfo Info)> add, List <string> result)
void GenerateColumnScript(StringBuilder builder, string name, PropertyInfo propertyInfo, KeyTypeStore keyStore, char comma) => builder.AppendLine(ColumnScript(name, propertyInfo, keyStore, null, comma));