generated from Avanade/avanade-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DataParserArgs.ColumnDefaults. (#30)
Help improvements.
- Loading branch information
Showing
14 changed files
with
252 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx | ||
|
||
using System; | ||
|
||
namespace DbEx.Migration.Data | ||
{ | ||
/// <summary> | ||
/// Provides the <see cref="DataParser"/> <see cref="DataParserArgs.ColumnDefaults"/> configuration. | ||
/// </summary> | ||
public class DataParserColumnDefault | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DataParserColumnDefault"/> class. | ||
/// </summary> | ||
/// <param name="schema">The schema name; a '<c>*</c>' denotes any schema.</param> | ||
/// <param name="table">The table name; a '<c>*</c>' denotes any table.</param> | ||
/// <param name="column">The name of the column to be updated.</param> | ||
/// <param name="default">The function that provides the default value.</param> | ||
public DataParserColumnDefault(string schema, string table, string column, Func<int, object?> @default) | ||
{ | ||
Schema = schema ?? throw new ArgumentNullException(nameof(schema)); | ||
Table = table ?? throw new ArgumentNullException(nameof(table)); | ||
Column = column ?? throw new ArgumentNullException(nameof(column)); | ||
Default = @default ?? throw new ArgumentNullException(nameof(@default)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the schema name; a '<c>*</c>' denotes any schema. | ||
/// </summary> | ||
public string Schema { get; } | ||
|
||
/// <summary> | ||
/// Gets the table name; a '<c>*</c>' denotes any table. | ||
/// </summary> | ||
public string Table { get; } | ||
|
||
/// <summary> | ||
/// Gets the column name. | ||
/// </summary> | ||
public string Column { get; } | ||
|
||
/// <summary> | ||
/// Gets the function that provides the default value. | ||
/// </summary> | ||
public Func<int, object?> Default { get; } | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/DbEx/Migration/Data/DataParserColumnDefaultCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/DbEx | ||
|
||
using DbEx.DbSchema; | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace DbEx.Migration.Data | ||
{ | ||
/// <summary> | ||
/// Provides a <see cref="DataParserColumnDefault"/> keyed collection. | ||
/// </summary> | ||
public class DataParserColumnDefaultCollection : KeyedCollection<(string, string, string), DataParserColumnDefault> | ||
{ | ||
/// <inheritdoc/> | ||
protected override (string, string, string) GetKeyForItem(DataParserColumnDefault item) => (item.Schema, item.Table, item.Column); | ||
|
||
/// <summary> | ||
/// Attempts to get the <paramref name="item"/> for the specified <paramref name="schema"/>, <paramref name="table"/> and <paramref name="column"/> names. | ||
/// </summary> | ||
/// <param name="schema">The schema name.</param> | ||
/// <param name="table">The table name.</param> | ||
/// <param name="column">The column name.</param> | ||
/// <param name="item">The corresponding <see cref="DataParserColumnDefault"/> item where found; otherwise, <c>null</c>.</param> | ||
/// <returns><c>true</c> where found; otherwise, <c>false</c>.</returns> | ||
/// <remarks>Attempts to match as follows: | ||
/// <list type="number"> | ||
/// <item>Schema, table and column names match item exactly;</item> | ||
/// <item>Schema and column names match item exactly, and the underlying default table name is configured with '<c>*</c>';</item> | ||
/// <item>Column names match item exactly, and the underlying default schema and table names are both configured with '<c>*</c>';</item> | ||
/// <item>Item is not found.</item> | ||
/// </list> | ||
/// </remarks> | ||
public bool TryGetValue(string schema, string table, string column, [NotNullWhen(true)] out DataParserColumnDefault? item) | ||
{ | ||
if (schema == null) | ||
throw new ArgumentNullException(nameof(schema)); | ||
|
||
if (table == null) | ||
throw new ArgumentNullException(nameof(table)); | ||
|
||
if (column == null) | ||
throw new ArgumentNullException(nameof(column)); | ||
|
||
if (TryGetValue((schema, table, column), out item)) | ||
return true; | ||
|
||
if (TryGetValue((schema, "*", column), out item)) | ||
return true; | ||
|
||
if (TryGetValue(("*", "*", column), out item)) | ||
return true; | ||
|
||
item = null; | ||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// Get all the configured column defaults for the specified <paramref name="table"/>. | ||
/// </summary> | ||
/// <param name="table">The <see cref="DbTableSchema"/>.</param> | ||
/// <returns>The configured defaults.</returns> | ||
public DataParserColumnDefaultCollection GetDefaultsForTable(DbTableSchema table) | ||
{ | ||
var dc = new DataParserColumnDefaultCollection(); | ||
foreach (var c in (table ?? throw new ArgumentNullException(nameof(table))).Columns) | ||
{ | ||
if (TryGetValue(table.Schema, table.Name, c.Name, out var item)) | ||
dc.Add(item); | ||
} | ||
|
||
return dc; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.