-
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Entity names are pascal cased and singularized
- Loading branch information
Showing
3 changed files
with
92 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,7 +110,7 @@ public string GetDabConfigCmdFile() | |
dbObject.Columns | ||
.Select(c => c.Name).ToList()); | ||
|
||
var type = dbObject.Name.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase); | ||
var type = GenerateEntityName(dbObject.Name.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase)); | ||
|
||
if (dbObject.PrimaryKey != null) | ||
{ | ||
|
@@ -134,7 +134,7 @@ public string GetDabConfigCmdFile() | |
dbObject.Columns | ||
.Select(c => c.Name).ToList()); | ||
|
||
var type = dbObject.Name.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase); | ||
var type = GenerateEntityName(dbObject.Name.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase)); | ||
|
||
if (dbObject.PrimaryKey == null) | ||
{ | ||
|
@@ -165,11 +165,11 @@ public string GetDabConfigCmdFile() | |
continue; | ||
} | ||
|
||
var type = dbObject.Name.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase); | ||
var type = GenerateEntityName(dbObject.Name.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase)); | ||
|
||
foreach (var fk in dbObject.ForeignKeys) | ||
{ | ||
var fkType = fk.PrincipalTable.Name.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase); | ||
var fkType = GenerateEntityName(fk.PrincipalTable.Name.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase)); | ||
Check failure on line 172 in src/Core/RevEng.Core.80/DabBuilder.cs GitHub Actions / build
|
||
sb.AppendLine(CultureInfo.InvariantCulture, $"dab update {type} --relationship {fkType} --target.entity {fkType} --cardinality one"); | ||
sb.AppendLine(CultureInfo.InvariantCulture, $"dab update {fkType} --relationship {type} --target.entity {type} --cardinality many"); | ||
} | ||
|
@@ -183,7 +183,7 @@ public string GetDabConfigCmdFile() | |
|
||
foreach (var procedure in procedures.Routines) | ||
{ | ||
var type = procedure.Name.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase); | ||
var type = GenerateEntityName(procedure.Name.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase)); | ||
|
||
sb.AppendLine(CultureInfo.InvariantCulture, $"dab add \"{type}\" --source \"[{procedure.Schema}].[{procedure.Name}]\" --source.type \"stored-procedure\" --permissions \"anonymous:execute\" --rest.methods \"get\" --graphql.operation \"query\" "); | ||
} | ||
|
@@ -205,6 +205,41 @@ private static bool BreaksOn(DatabaseTable dbObject) | |
|| !dbObject.Columns.Any(); | ||
} | ||
|
||
private static string GenerateEntityName(string value) | ||
{ | ||
var candidateStringBuilder = new StringBuilder(); | ||
var previousLetterCharInWordIsLowerCase = false; | ||
var isFirstCharacterInWord = true; | ||
|
||
foreach (var c in value) | ||
{ | ||
var isNotLetterOrDigit = !char.IsLetterOrDigit(c); | ||
if (isNotLetterOrDigit | ||
|| (previousLetterCharInWordIsLowerCase && char.IsUpper(c))) | ||
{ | ||
isFirstCharacterInWord = true; | ||
previousLetterCharInWordIsLowerCase = false; | ||
if (isNotLetterOrDigit) | ||
{ | ||
continue; | ||
} | ||
} | ||
|
||
candidateStringBuilder.Append( | ||
isFirstCharacterInWord ? char.ToUpperInvariant(c) : char.ToLowerInvariant(c)); | ||
isFirstCharacterInWord = false; | ||
if (char.IsLower(c)) | ||
{ | ||
previousLetterCharInWordIsLowerCase = true; | ||
} | ||
} | ||
|
||
var pluralizer = new HumanizerPluralizer(); | ||
var candidate = candidateStringBuilder.ToString(); | ||
|
||
return pluralizer.Singularize(candidate); | ||
} | ||
|
||
private void RemoveExcludedColumns(DatabaseTable dbObject) | ||
{ | ||
var excludedColumns = options.Tables.Find(t => t.Name == $"[{dbObject.Schema}].[{dbObject.Name}]")?.ExcludedColumns; | ||
|
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.