From 40c634b0f37ce9922dbc32c86e26d5a771daeca3 Mon Sep 17 00:00:00 2001 From: vnugent Date: Sat, 30 Mar 2024 22:22:43 -0400 Subject: feat: Update modern SQLServer, add some DBBuilder extensions --- .../src/DbBuilder.cs | 2 +- .../src/SqlDbConnectionLoader.cs | 35 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) (limited to 'lib/VNLib.Plugins.Extensions.Loading.Sql/src') diff --git a/lib/VNLib.Plugins.Extensions.Loading.Sql/src/DbBuilder.cs b/lib/VNLib.Plugins.Extensions.Loading.Sql/src/DbBuilder.cs index 44d4670..a82fdfa 100644 --- a/lib/VNLib.Plugins.Extensions.Loading.Sql/src/DbBuilder.cs +++ b/lib/VNLib.Plugins.Extensions.Loading.Sql/src/DbBuilder.cs @@ -125,7 +125,7 @@ namespace VNLib.Plugins.Extensions.Loading.Sql if (maxLen.HasValue) { - col.MaxLength = maxLen.Value; + col.MaxLength(maxLen.Value); } //Store the column diff --git a/lib/VNLib.Plugins.Extensions.Loading.Sql/src/SqlDbConnectionLoader.cs b/lib/VNLib.Plugins.Extensions.Loading.Sql/src/SqlDbConnectionLoader.cs index b48ddd1..6f150c8 100644 --- a/lib/VNLib.Plugins.Extensions.Loading.Sql/src/SqlDbConnectionLoader.cs +++ b/lib/VNLib.Plugins.Extensions.Loading.Sql/src/SqlDbConnectionLoader.cs @@ -210,5 +210,40 @@ namespace VNLib.Plugins.Extensions.Loading.Sql //All done! plugin.Log.Debug("Successfully created tables for {type}", typeof(T).Name); } + + /// + /// A helper method to define a table for a + /// + /// + /// + /// The optional name of the table to create + /// The table creation callback function + /// The original context builder instance + /// + public static IDbContextBuilder DefineTable(this IDbContextBuilder builder, string tableName, Action> callback) + { + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(callback); + + callback(builder.DefineTable(tableName)); + return builder; + } + + /// + /// A helper method to define a table for a + /// + /// + /// + /// The table creation callback function + /// The original context builder instance + /// + public static IDbContextBuilder DefineTable(this IDbContextBuilder builder, Action> callback) + { + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(callback); + + callback(builder.DefineTable()); + return builder; + } } } -- cgit