Skip to content

Commit

Permalink
Added basic model definition classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjcowan committed Aug 27, 2024
1 parent ccc92eb commit 0955225
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/DapperMatic/Models/Column.cs
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; }
}
19 changes: 19 additions & 0 deletions src/DapperMatic/Models/ForeignKey.cs
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;
}
19 changes: 19 additions & 0 deletions src/DapperMatic/Models/Index.cs
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; }
}
7 changes: 7 additions & 0 deletions src/DapperMatic/Models/ModelDefinition.cs
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; }
}
13 changes: 13 additions & 0 deletions src/DapperMatic/Models/PrimaryKey.cs
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; }
}
18 changes: 18 additions & 0 deletions src/DapperMatic/Models/Table.cs
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; } = [];
}
13 changes: 13 additions & 0 deletions src/DapperMatic/Models/UniqueConstraint.cs
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; }
}

0 comments on commit 0955225

Please sign in to comment.