IORM.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System.Linq.Expressions;
  2. namespace ORM;
  3. public interface IORM : IDisposable
  4. {
  5. bool Initialize(IOrmProvider? notify = null);
  6. bool Open(string connectionString, DbType dbType, bool isAutoConnection = true);
  7. bool CreateDataBase(string dbName);
  8. bool CreateTable<T>(string? tableName = null) where T : class, new();
  9. /// <summary>
  10. /// this Insert Function can insert a single class or IList<T> class
  11. /// </summary>
  12. /// <typeparam name="T"></typeparam>
  13. /// <param name="data"></param>
  14. /// <returns></returns>
  15. bool Insert<T>(T data) where T : class, new();
  16. /// <summary>
  17. /// this Insert Function can insert a single class or IList<T> class
  18. /// </summary>
  19. /// <typeparam name="T"></typeparam>
  20. /// <param name="data"></param>
  21. /// <returns></returns>
  22. bool Insert<T>(string tablename, T data) where T : class, new();
  23. Task<bool> Query<T>(Action<List<T>> results) where T : class, new();
  24. Task<bool> Query<T>(string tableName, Action<List<T>> results) where T : class, new();
  25. Task<bool> Query<T>(Expression<Func<T, bool>> expression, Action<List<T>> results) where T : class, new();
  26. Task<bool> Query<T>(string tableName, Expression<Func<T, bool>> expression, Action<List<T>> results) where T : class, new();
  27. bool Query<T>(out List<T>? results);
  28. bool Query<T>(string tableName, out List<T>? results);
  29. bool Query<T>(string tableName, Expression<Func<T, bool>> expression, out List<T>? results);
  30. bool AddOrUpdate<T>(string tableName, T data, Expression<Func<T, bool>> expression) where T : class, new();
  31. bool Delete<T>(string tableName, Expression<Func<T, bool>> expression) where T : class, new();
  32. }
  33. public interface IOrmProvider
  34. {
  35. void Log(string log, DateTime dateTime, LogLevel logLevel);
  36. }
  37. public enum LogLevel
  38. {
  39. Info,
  40. Warning,
  41. Error,
  42. Fatal,
  43. Original
  44. }
  45. //Copy from SqlSugar def
  46. public enum DbType
  47. {
  48. MySql = 0,
  49. SqlServer = 1,
  50. Sqlite = 2,
  51. Oracle = 3,
  52. PostgreSQL = 4,
  53. Dm = 5,
  54. Kdbndp = 6,
  55. Oscar = 7,
  56. MySqlConnector = 8,
  57. Access = 9,
  58. OpenGauss = 10,
  59. QuestDB = 11,
  60. HG = 12,
  61. ClickHouse = 13,
  62. GBase = 14,
  63. Odbc = 15,
  64. OceanBaseForOracle = 16,
  65. TDengine = 17,
  66. GaussDB = 18,
  67. OceanBase = 19,
  68. Tidb = 20,
  69. Vastbase = 21,
  70. PolarDB = 22,
  71. Doris = 23,
  72. Xugu = 24,
  73. GoldenDB = 25,
  74. TDSQLForPGODBC = 26,
  75. TDSQL = 27,
  76. HANA = 28,
  77. DB2 = 29,
  78. Custom = 900
  79. }