From 5d8614d205b7bdca56684a3cc5a08db90e3804b6 Mon Sep 17 00:00:00 2001 From: vnugent Date: Wed, 21 Feb 2024 21:44:56 -0500 Subject: user-creation api update, and fix user-privilege missing update --- .../src/DbBuilder.cs | 57 ++++++---------------- .../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(DataTable Table, Type RuntimeType) : IDbTable, IDbTableBuilder + private class TableBuilder(DataTable Table, Type RuntimeType) : IDbTable, IDbTableBuilder { /// public IDbColumnBuilder WithColumn(Expression> 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(propertyName)?.Length; - //Get the max-length attribute - MaxLengthAttribute? mla = property?.GetCustomAttribute(); + private string? GetPropertyColumnName(string propertyName) + => GetAttributePropertyName(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(propertyName) is not null; - ColumnAttribute? mla = property?.GetCustomAttribute(); + //Get the properties' timestamp attribute + private bool GetPropertyIsRowVersion(string propertyName) + => GetAttributePropertyName(propertyName) is not null; - return mla?.Name; - } - private bool? GetPropertyIsKey(string propertyName) + private TA? GetAttributePropertyName(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(); - - 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(); - - return ts == null ? null : true; + return property?.GetCustomAttribute(); } - private record class ColumnBuilder(DataColumn Column, IDbTableBuilder Table) : IDbColumnBuilder + private class ColumnBuilder(DataColumn Column, IDbTableBuilder Table) : IDbColumnBuilder { public IDbTableBuilder 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 -- cgit