Config.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Uninpho.DBOperation
  8. {
  9. /// <summary>
  10. /// Setting up the database name does not require you to create the database
  11. /// 设置好数据库名不需要你去手动建库
  12. /// </summary>
  13. public class Config
  14. {
  15. /// <summary>
  16. /// 自动化打印,true选择打印
  17. /// </summary>
  18. public static bool zdhjc = true;
  19. public static SqlSugarClient GetPgClient()
  20. {
  21. return new SqlSugarClient(new ConnectionConfig()
  22. {
  23. DbType = DbType.PostgreSQL,
  24. ConnectionString = System.Configuration.ConfigurationManager.AppSettings["dbConnection"] as string,
  25. InitKeyType = InitKeyType.Attribute,
  26. IsAutoCloseConnection = true,
  27. AopEvents = new AopEvents
  28. {
  29. OnLogExecuting = (sql, p) =>
  30. {
  31. if (zdhjc)
  32. {
  33. Console.WriteLine(sql);
  34. Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
  35. }
  36. }
  37. }
  38. });
  39. }
  40. }
  41. }