From 6cf59c41cc059bd6135491bdd75268859afba1db Mon Sep 17 00:00:00 2001 From: Ryan Palmer Date: Fri, 30 Jul 2021 07:58:07 +1000 Subject: [PATCH] Created Model Base Class Created the base class for all models and started on attributes --- Articulate/Articulate.csproj | 7 ++++++ Articulate/Attributes/Column.cs | 11 +++++++++ Articulate/DBConnection.cs | 44 +++++++++++++++++++++++++++++++++ Articulate/Model.cs | 28 +++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 Articulate/Articulate.csproj create mode 100644 Articulate/Attributes/Column.cs create mode 100644 Articulate/DBConnection.cs create mode 100644 Articulate/Model.cs diff --git a/Articulate/Articulate.csproj b/Articulate/Articulate.csproj new file mode 100644 index 0000000..9f5c4f4 --- /dev/null +++ b/Articulate/Articulate.csproj @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git a/Articulate/Attributes/Column.cs b/Articulate/Attributes/Column.cs new file mode 100644 index 0000000..21d3182 --- /dev/null +++ b/Articulate/Attributes/Column.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Articulate.Attributes +{ + public class Column : Attribute + { + public string Type { get; set; } + } +} diff --git a/Articulate/DBConnection.cs b/Articulate/DBConnection.cs new file mode 100644 index 0000000..9457451 --- /dev/null +++ b/Articulate/DBConnection.cs @@ -0,0 +1,44 @@ +using MySql.Data.MySqlClient; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Articulate +{ + public class DBConnection + { + public string Server { get; set; } + public string DatabaseName { get; set; } + public string UserName { get; set; } + public string Password { get; set; } + + private MySqlConnection Connection { get; set; } + + private static DBConnection _instance = null; + public static DBConnection Instance() + { + if (_instance == null) + _instance = new DBConnection(); + return _instance; + } + + public bool IsConnect() + { + if (Connection == null) + { + if (String.IsNullOrEmpty(DatabaseName)) + return false; + string connstring = string.Format("Server={0}; database={1}; UID={2}; password={3}", Server, DatabaseName, UserName, Password); + Connection = new MySqlConnection(connstring); + Connection.Open(); + } + + return true; + } + + public void Close() + { + Connection.Close(); + } + } +} diff --git a/Articulate/Model.cs b/Articulate/Model.cs new file mode 100644 index 0000000..5ee2cc7 --- /dev/null +++ b/Articulate/Model.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Articulate +{ + public class Model + { + protected string Table = string.Empty; + + protected string PrimaryKey = "id"; + protected string KeyType = "integer"; + + protected bool Incrementing = true; + + protected bool Timestamps = false; + + public bool Insert() + { + return false; + } + + public static void Get() + { + + } + } +}