-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic model definition classes
- Loading branch information
1 parent
ccc92eb
commit 0955225
Showing
7 changed files
with
117 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace DapperMatic.Models; | ||
|
||
public class Column | ||
{ | ||
public Column(string name, Type dotnetType) | ||
{ | ||
Name = name; | ||
DotnetType = dotnetType; | ||
} | ||
|
||
public string Name { get; set; } | ||
public Type DotnetType { get; set; } | ||
public int? Length { get; set; } | ||
public int? Precision { get; set; } | ||
public int? Scale { get; set; } | ||
public bool Nullable { get; set; } | ||
public string? DefaultValue { get; set; } | ||
public bool AutoIncrement { get; set; } | ||
public bool PrimaryKey { get; set; } | ||
public bool Unique { get; set; } | ||
public bool Indexed { get; set; } | ||
public bool ForeignKey { get; set; } | ||
public string? ReferenceTable { get; set; } | ||
public string? ReferenceColumn { get; set; } | ||
public ReferentialAction? OnDelete { get; set; } | ||
public ReferentialAction? OnUpdate { get; set; } | ||
public string? Comment { get; set; } | ||
} |
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,19 @@ | ||
namespace DapperMatic.Models; | ||
|
||
public class ForeignKey | ||
{ | ||
public ForeignKey(string name, string column, string referenceTable, string referenceColumn) | ||
{ | ||
Name = name; | ||
Column = column; | ||
ReferenceTable = referenceTable; | ||
ReferenceColumn = referenceColumn; | ||
} | ||
|
||
public string Name { get; set; } | ||
public string Column { get; set; } | ||
public string ReferenceTable { get; set; } | ||
public string ReferenceColumn { get; set; } | ||
public ReferentialAction OnDelete { get; set; } = ReferentialAction.NoAction; | ||
public ReferentialAction OnUpdate { get; set; } = ReferentialAction.NoAction; | ||
} |
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,19 @@ | ||
namespace DapperMatic.Models; | ||
|
||
public class Index | ||
{ | ||
public Index(string name, string[] columns, bool unique = false) | ||
{ | ||
Name = name; | ||
Columns = columns; | ||
Unique = unique; | ||
} | ||
|
||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Column names (optionally, appended with ` ASC` or ` DESC`) | ||
/// </summary> | ||
public string[] Columns { get; set; } | ||
public bool Unique { get; set; } | ||
} |
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,7 @@ | ||
namespace DapperMatic.Models; | ||
|
||
public class ModelDefinition | ||
{ | ||
public Type? Type { get; set; } | ||
public Table? Table { get; set; } | ||
} |
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,13 @@ | ||
namespace DapperMatic.Models; | ||
|
||
public class PrimaryKey | ||
{ | ||
public PrimaryKey(string name, string[] columns) | ||
{ | ||
Name = name; | ||
Columns = columns; | ||
} | ||
|
||
public string Name { get; set; } | ||
public string[] Columns { get; set; } | ||
} |
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,18 @@ | ||
namespace DapperMatic.Models; | ||
|
||
public class Table | ||
{ | ||
public Table(string name, string? schema) | ||
{ | ||
Name = name; | ||
Schema = schema; | ||
} | ||
|
||
public string Name { get; set; } | ||
public string? Schema { get; set; } | ||
public PrimaryKey? PrimaryKey { get; set; } | ||
public Column[] Columns { get; set; } = []; | ||
public UniqueConstraint[] UniqueConstraints { get; set; } = []; | ||
public Index[] Indexes { get; set; } = []; | ||
public ForeignKey[] ForeignKeys { get; set; } = []; | ||
} |
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,13 @@ | ||
namespace DapperMatic.Models; | ||
|
||
public class UniqueConstraint | ||
{ | ||
public UniqueConstraint(string name, string[] columns) | ||
{ | ||
Name = name; | ||
Columns = columns; | ||
} | ||
|
||
public string Name { get; set; } | ||
public string[] Columns { get; set; } | ||
} |