AnalyzeRepository.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using AutoMapper;
  4. using Datory;
  5. using GxPress.Common.AppOptions;
  6. using GxPress.Common.Tools;
  7. using GxPress.Repository.Interface.Analyze;
  8. using Microsoft.Extensions.Options;
  9. using SqlKata;
  10. namespace GxPress.Repository.Implement.Analyze
  11. {
  12. /// <summary>
  13. /// 分析
  14. /// </summary>
  15. public class AnalyzeRepository : IAnalyzeRepository
  16. {
  17. private readonly Repository<Entity.Analyze.Analyze> _repository;
  18. private readonly IMapper _mapper;
  19. public AnalyzeRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
  20. {
  21. var databaseType = StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
  22. var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
  23. _repository = new Repository<Entity.Analyze.Analyze>(database);
  24. _mapper = mapper;
  25. }
  26. public IDatabase Database => _repository.Database;
  27. public string TableName => _repository.TableName;
  28. public List<TableColumn> TableColumns => _repository.TableColumns;
  29. public async Task<Entity.Analyze.Analyze> GetAsync(Query query)
  30. {
  31. return await _repository.GetAsync(query);
  32. }
  33. public async Task<bool> DeleteAsync(int id)
  34. {
  35. return await _repository.DeleteAsync(id);
  36. }
  37. public async Task<int> CountAsync(Query query)
  38. {
  39. return await _repository.CountAsync(query);
  40. }
  41. public async Task<int> UpdateAsync(Query query)
  42. {
  43. return await _repository.UpdateAsync(query);
  44. }
  45. public async Task<bool> DeleteAsync(SqlKata.Query query)
  46. {
  47. return await _repository.DeleteAsync(query) > 0;
  48. }
  49. public async Task<int> InsertAsync(Entity.Analyze.Analyze analyze)
  50. {
  51. return await _repository.InsertAsync(analyze);
  52. }
  53. public async Task<IEnumerable<Entity.Analyze.Analyze>> GetAllAsync(Query query)
  54. {
  55. return await _repository.GetAllAsync(query);
  56. }
  57. public async Task<bool> ExistsAsync(Query query)
  58. {
  59. return await _repository.ExistsAsync(query);
  60. }
  61. }
  62. }