diff options
author | vnugent <public@vaughnnugent.com> | 2024-02-21 21:44:56 -0500 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-02-21 21:44:56 -0500 |
commit | 5d8614d205b7bdca56684a3cc5a08db90e3804b6 (patch) | |
tree | 3c148616c67ebd42cb1a1753c4cc6121df279d96 /lib/VNLib.Plugins.Extensions.Loading.Sql | |
parent | b73f0fdd70d8b560422c80a6ab9bfe96f97db3b3 (diff) |
user-creation api update, and fix user-privilege missing update
Diffstat (limited to 'lib/VNLib.Plugins.Extensions.Loading.Sql')
-rw-r--r-- | lib/VNLib.Plugins.Extensions.Loading.Sql/src/DbBuilder.cs | 57 | ||||
-rw-r--r-- | lib/VNLib.Plugins.Extensions.Loading.Sql/src/SqlDbConnectionLoader.cs | 2 |
2 files changed, 17 insertions, 42 deletions
diff --git a/lib/VNLib.Plugins.Extensions.Loading.Sql/src/DbBuilder.cs b/lib/VNLib.Plugins.Extensions.Loading.Sql/src/DbBuilder.cs index 7eb3e66..44d4670 100644 --- a/lib/VNLib.Plugins.Extensions.Loading.Sql/src/DbBuilder.cs +++ b/lib/VNLib.Plugins.Extensions.Loading.Sql/src/DbBuilder.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Extensions.Loading.Sql @@ -84,7 +84,7 @@ namespace VNLib.Plugins.Extensions.Loading.Sql return tableCommands.ToArray(); } - private record class TableBuilder<T>(DataTable Table, Type RuntimeType) : IDbTable, IDbTableBuilder<T> + private class TableBuilder<T>(DataTable Table, Type RuntimeType) : IDbTable, IDbTableBuilder<T> { ///<inheritdoc/> public IDbColumnBuilder<T> WithColumn<TCol>(Expression<Func<T, TCol>> selector) @@ -132,15 +132,13 @@ namespace VNLib.Plugins.Extensions.Loading.Sql Table.Columns.Add(col); //See if key is found, then add the colum to the primary key table - bool? isKey = GetPropertyIsKey(selectorData.Key); - if (isKey.HasValue && isKey.Value) + if (GetPropertyIsKey(selectorData.Key)) { col.AddToPrimaryKeys(); } //Set the colum as timestamp - bool? isRowVersion = GetPropertyIsRowVersion(selectorData.Key); - if (isRowVersion.HasValue && isRowVersion.Value) + if (GetPropertyIsRowVersion(selectorData.Key)) { col.SetTimeStamp(); } @@ -153,52 +151,29 @@ namespace VNLib.Plugins.Extensions.Loading.Sql public void WriteCommand(StringBuilder sb, IDBCommandGenerator commandBuilder) => commandBuilder.BuildCreateStatment(sb, Table); - private int? GetPropertyMaxLen(string propertyName) - { - PropertyInfo? property = RuntimeType.GetProperties() - .Where(p => propertyName.Equals(p.Name, StringComparison.OrdinalIgnoreCase)) - .FirstOrDefault(); + private int? GetPropertyMaxLen(string propertyName) + => GetAttributePropertyName<MaxLengthAttribute>(propertyName)?.Length; - //Get the max-length attribute - MaxLengthAttribute? mla = property?.GetCustomAttribute<MaxLengthAttribute>(); + private string? GetPropertyColumnName(string propertyName) + => GetAttributePropertyName<ColumnAttribute>(propertyName)?.Name; - return mla?.Length; - } - private string? GetPropertyColumnName(string propertyName) - { - PropertyInfo? property = RuntimeType.GetProperties() - .Where(p => propertyName.Equals(p.Name, StringComparison.OrdinalIgnoreCase)) - .FirstOrDefault(); + private bool GetPropertyIsKey(string propertyName) + => GetAttributePropertyName<KeyAttribute>(propertyName) is not null; - ColumnAttribute? mla = property?.GetCustomAttribute<ColumnAttribute>(); + //Get the properties' timestamp attribute + private bool GetPropertyIsRowVersion(string propertyName) + => GetAttributePropertyName<TimestampAttribute>(propertyName) is not null; - return mla?.Name; - } - private bool? GetPropertyIsKey(string propertyName) + private TA? GetAttributePropertyName<TA>(string propertyName) where TA : Attribute { PropertyInfo? property = RuntimeType.GetProperties() .Where(p => propertyName.Equals(p.Name, StringComparison.OrdinalIgnoreCase)) .FirstOrDefault(); - //Get the propertie's key attribute - KeyAttribute? ka = property?.GetCustomAttribute<KeyAttribute>(); - - return ka == null ? null : true; - } - - private bool? GetPropertyIsRowVersion(string propertyName) - { - PropertyInfo? property = RuntimeType.GetProperties() - .Where(p => propertyName.Equals(p.Name, StringComparison.OrdinalIgnoreCase)) - .FirstOrDefault(); - - //Get the properties' timestamp attribute - TimestampAttribute? ts = property?.GetCustomAttribute<TimestampAttribute>(); - - return ts == null ? null : true; + return property?.GetCustomAttribute<TA>(); } - private record class ColumnBuilder(DataColumn Column, IDbTableBuilder<T> Table) : IDbColumnBuilder<T> + private class ColumnBuilder(DataColumn Column, IDbTableBuilder<T> Table) : IDbColumnBuilder<T> { public IDbTableBuilder<T> Next() => Table; diff --git a/lib/VNLib.Plugins.Extensions.Loading.Sql/src/SqlDbConnectionLoader.cs b/lib/VNLib.Plugins.Extensions.Loading.Sql/src/SqlDbConnectionLoader.cs index 58ca934..b48ddd1 100644 --- a/lib/VNLib.Plugins.Extensions.Loading.Sql/src/SqlDbConnectionLoader.cs +++ b/lib/VNLib.Plugins.Extensions.Loading.Sql/src/SqlDbConnectionLoader.cs @@ -163,7 +163,7 @@ namespace VNLib.Plugins.Extensions.Loading.Sql DbBuilder builder = new(); - //Invoke ontbCreating to setup the dbBuilder + //Invoke onDbCreating to setup the dbBuilder and table's for the context dbCreator.OnDatabaseCreating(builder, state); //Get the abstract database from the connection type |