You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
5.8 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Text;
  5. namespace Apewer.Source
  6. {
  7. /// <summary>数据库客户端。</summary>
  8. public interface IDbOrm
  9. {
  10. #region object
  11. /// <summary>初始化指定类型,以创建表或增加字段。</summary>
  12. /// <param name="model">要初始化的类型。</param>
  13. /// <param name="table">指定新的表名。</param>
  14. /// <returns>错误信息。当成功时候返回空字符串。</returns>
  15. public string Initialize(Type model, string table = null);
  16. /// <summary>初始化指定类型,以创建表或增加字段。</summary>
  17. /// <param name="table">指定新的表名。</param>
  18. /// <returns>错误信息。当成功时候返回空字符串。</returns>
  19. public string Initialize<T>(string table = null) where T : class, new();
  20. /// <summary>插入记录。</summary>
  21. /// <param name="record">要插入的记录实体。</param>
  22. /// <param name="table">插入到指定表。当不指定时,由 record 类型决定。</param>
  23. /// <param name="adjust">调整数据模型,补充缺少的属性。</param>
  24. /// <returns>错误信息。当成功时候返回空字符串。</returns>
  25. public string Insert(object record, string table = null, bool adjust = true);
  26. /// <summary>使用指定语句查询,获取查询结果。</summary>
  27. /// <param name="model">目标记录的类型。</param>
  28. /// <param name="sql">要执行的 SQL 语句。</param>
  29. /// <param name="parameters">为 SQL 命令提供参数。</param>
  30. /// <exception cref="ArgumentNullException"></exception>
  31. /// <exception cref="ArgumentException"></exception>
  32. /// <exception cref="ModelException"></exception>
  33. /// <exception cref="SqlException"></exception>
  34. public object[] Query(Type model, string sql, IEnumerable<IDataParameter> parameters = null);
  35. /// <summary>使用指定语句查询,获取查询结果。</summary>
  36. /// <param name="sql">要执行的 SQL 语句。</param>
  37. /// <param name="parameters">为 SQL 命令提供参数。</param>
  38. /// <exception cref="ArgumentNullException"></exception>
  39. /// <exception cref="ArgumentException"></exception>
  40. /// <exception cref="ModelException"></exception>
  41. /// <exception cref="SqlException"></exception>
  42. public T[] Query<T>(string sql, IEnumerable<IDataParameter> parameters = null) where T : class, new();
  43. #endregion
  44. #region record
  45. /// <summary>更新记录。</summary>
  46. /// <param name="record">要插入的记录实体。</param>
  47. /// <param name="table">插入到指定表。当不指定时,由 record 类型决定。</param>
  48. /// <param name="adjust">调整数据模型,补充缺少的属性。</param>
  49. /// <returns>错误信息。当成功时候返回空字符串。</returns>
  50. public string Update(IRecord record, string table = null, bool adjust = true);
  51. /// <summary>获取指定类型的主键,按 Flag 属性筛选。</summary>
  52. /// <param name="model">要查询的类型。</param>
  53. /// <param name="flag">要求目标记录具有的 Flag 属性,当指定 0 时忽略此要求。</param>
  54. /// <exception cref="ArgumentNullException"></exception>
  55. /// <exception cref="ModelException"></exception>
  56. /// <exception cref="SqlException"></exception>
  57. public string[] Keys(Type model, long flag = 0);
  58. /// <summary>获取指定类型的主键,按 Flag 属性筛选。</summary>
  59. /// <param name="flag">要求目标记录具有的 Flag 属性,当指定 0 时忽略此要求。</param>
  60. /// <exception cref="ModelException"></exception>
  61. /// <exception cref="SqlException"></exception>
  62. public string[] Keys<T>(long flag = 0) where T : class, IRecord, new();
  63. /// <summary>获取具有指定 Key 的记录,并要求记录具有指定的 Flag 属性。</summary>
  64. /// <param name="model">目标记录的类型。</param>
  65. /// <param name="key">目标记录的主键。</param>
  66. /// <param name="flag">要求目标记录具有的 Flag 属性,当指定 0 时忽略此要求。</param>
  67. /// <exception cref="ArgumentNullException"></exception>
  68. /// <exception cref="ModelException"></exception>
  69. /// <exception cref="SqlException"></exception>
  70. public object Get(Type model, string key, long flag = 0);
  71. /// <summary>获取具有指定 Key 的记录,并要求记录具有指定的 Flag 属性。</summary>
  72. /// <param name="key">目标记录的主键。</param>
  73. /// <param name="flag">要求目标记录具有的 Flag 属性,当指定 0 时忽略此要求。</param>
  74. /// <exception cref="ModelException"></exception>
  75. /// <exception cref="SqlException"></exception>
  76. public T Get<T>(string key, long flag = 0) where T : class, IRecord, new();
  77. /// <summary>查询所有记录。</summary>
  78. /// <param name="model">目标记录的类型。</param>
  79. /// <param name="flag">要求目标记录具有的 Flag 属性,当指定 0 时忽略此要求。</param>
  80. /// <exception cref="ArgumentNullException"></exception>
  81. /// <exception cref="ModelException"></exception>
  82. /// <exception cref="SqlException"></exception>
  83. public object[] List(Type model, long flag = 0);
  84. /// <summary>查询所有记录。</summary>
  85. /// <param name="flag">要求目标记录具有的 Flag 属性,当指定 0 时忽略此要求。</param>
  86. /// <exception cref="ModelException"></exception>
  87. /// <exception cref="SqlException"></exception>
  88. public T[] List<T>(long flag = 0) where T : class, IRecord, new();
  89. #endregion
  90. }
  91. }