BaseDBProvider.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //using Dapper;
  2. //using MySql.Data.MySqlClient;
  3. //using System;
  4. //using System.Collections.Generic;
  5. //using System.Data;
  6. //using System.Linq;
  7. //using System.Text;
  8. //using System.Threading.Tasks;
  9. //namespace Winsoft.GOV.XF.WebApi.WXCore.DBProvider
  10. //{
  11. // public class DBConfig
  12. // {
  13. // public static string DefaultConnectionString { get; set; }
  14. // }
  15. // public class BaseDBProvider<T>
  16. // {
  17. // #region instance
  18. // private static object lockObj = new object();
  19. // private static string createWXUser = "CREATE TABLE IF NOT EXISTS `wxuser` (" +
  20. // " `id` INT GENERATED ALWAYS AS(0)," +
  21. // " `openid` VARCHAR(64) NOT NULL," +
  22. // " `mobile` VARCHAR(11) NULL," +
  23. // " `email` VARCHAR(100) NULL," +
  24. // " UNIQUE INDEX `openid_UNIQUE` (`openid` ASC)," +
  25. // " PRIMARY KEY(`id`));";
  26. // private static string createWXBatch = "CREATE TABLE IF NOT EXISTS `wxbatch` (" +
  27. // " `id` VARCHAR(64) NOT NULL," +
  28. // " `decribe` VARCHAR(500) NULL," +
  29. // " PRIMARY KEY(`id`));";
  30. // private static string createWXResource = "CREATE TABLE IF NOT EXISTS `wxresource` (" +
  31. // " `id` VARCHAR(64) NOT NULL," +
  32. // " `batchId` VARCHAR(64) NOT NULL," +
  33. // " `url` VARCHAR(500) NULL," +
  34. // " PRIMARY KEY(`id`));";
  35. // protected static void CreateInstance<K>(ref K singleInstance) where K : BaseDBProvider<T>, new()
  36. // {
  37. // if (singleInstance == null)
  38. // {
  39. // lock (lockObj)
  40. // {
  41. // if (singleInstance == null)
  42. // {
  43. // singleInstance = new K();
  44. // }
  45. // }
  46. // }
  47. // }
  48. // #endregion
  49. // #region connection
  50. // public BaseDBProvider()
  51. // {
  52. // }
  53. // /// <summary>
  54. // /// </summary>
  55. // /// <param name="connectionStr"></param>
  56. // /// <returns></returns>
  57. // protected IDbConnection GetDbConnection()
  58. // {
  59. // var connection = new MySqlConnection
  60. // {
  61. // ConnectionString = DBConfig.DefaultConnectionString
  62. // };
  63. // connection.Open();
  64. // return connection;
  65. // }
  66. // protected string BuildTotalSQL(string sql)
  67. // {
  68. // var selectCount = new StringBuilder("SELECT COUNT(1) from (");
  69. // return
  70. // selectCount.Append(sql + ") as t")
  71. // .ToString();
  72. // }
  73. // /// <summary>
  74. // /// </summary>
  75. // /// <param name="total"></param>
  76. // /// <param name="sql"></param>
  77. // /// <param name="pageIndex">内部索引从0开始,页码从1开始</param>
  78. // /// <code>
  79. // /// if (pageIndex - 1 >= 0)
  80. // /// {
  81. // /// pageIndex = pageIndex - 1;
  82. // /// }
  83. // /// </code>
  84. // /// <param name="pageSize"></param>
  85. // /// <param name="param"></param>
  86. // /// <param name="areaCode"></param>
  87. // /// <returns></returns>
  88. // //protected PagedResult<T> GetPagedList(string sql, int pageIndex, int pageSize, object param)
  89. // //{
  90. // // long total = 0;
  91. // // pageIndex -= 1;
  92. // // if (pageIndex < 0)
  93. // // {
  94. // // pageIndex = 0;
  95. // // }
  96. // // if (pageSize <= 0)
  97. // // {
  98. // // pageSize = 20;
  99. // // }
  100. // // using (IDbConnection connection = GetDbConnection())
  101. // // {
  102. // // string totalSql = BuildTotalSQL(sql);
  103. // // total = connection.Query<long>(totalSql, param).FirstOrDefault();
  104. // // var list = connection.Query<T>(String.Format(sql + " limit {0},{1}", pageIndex * pageSize, pageSize), param);
  105. // // return new PagedResult<T>(list, pageIndex + 1, pageSize, total);
  106. // // }
  107. // //}
  108. // protected IEnumerable<T> GetItemList(string sql, int itemIndex, int pageSize, object param)
  109. // {
  110. // if (itemIndex < 0)
  111. // {
  112. // itemIndex = 0;
  113. // }
  114. // if (pageSize <= 0)
  115. // {
  116. // pageSize = 20;
  117. // }
  118. // using (IDbConnection connection = GetDbConnection())
  119. // {
  120. // var list = connection.Query<T>(String.Format(sql + " limit {0},{1}", itemIndex, pageSize), param);
  121. // return list;
  122. // }
  123. // }
  124. // #endregion
  125. // }
  126. //}