using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq.Expressions; using System.Threading.Tasks; using Dapper; namespace Tiobon.Core.Common.DB.Dapper; public interface ISqlDapper { /// /// var p = new object(); // p.Add("@a", 11); //p.Add("@b", dbType: DbType.Int32, direction: ParameterDirection.Output); //p.Add("@c", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue); // /// IDbConnection Connection { get; } /// /// /// /// /// List QueryList(string cmd, object param = null, CommandType? commandType = null, bool beginTransaction = false) where T : class; Task> QueryListAsync(string cmd, object param = null, CommandType? commandType = null, bool beginTransaction = false, int? commandTimeout = null) where T : class; T QueryFirst(string cmd, object param = null, CommandType? commandType = null, bool beginTransaction = false) where T : class; Task QueryFirstAsync(string cmd, object param = null, CommandType? commandType = null, bool beginTransaction = false, int? commandTimeout = null) where T : class; object ExecuteScalar(string cmd, object param = null, CommandType? commandType = null, bool beginTransaction = false); Task ExecuteScalarAsync(string cmd, object param = null, CommandType? commandType = null, bool beginTransaction = false); int ExcuteNonQuery(string cmd, object param = null, CommandType? commandType = null, bool beginTransaction = false); IDataReader ExecuteReader(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false); SqlMapper.GridReader QueryMultiple(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false); (List, List) QueryMultiple(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false); (List, List, List) QueryMultiple(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false); DataTable GetDataTable(string cmd, object param = null, CommandType? commandType = null, bool beginTransaction = false); Task GetDataTableAsync(string cmd, object param = null, IDbTransaction transaction = null, CommandType? commandType = null, int? commandTimeout = null); /// /// /// /// /// /// 指定插入的字段 /// 是否开启事务 /// int Add(T entity, Expression> updateFileds = null, bool beginTransaction = false); /// /// /// /// /// /// 指定插入的字段 /// 是否开启事务 /// int AddRange(IEnumerable entities, Expression> updateFileds = null, bool beginTransaction = false); /// /// sqlserver使用的临时表参数化批量更新,mysql批量更新待发开 /// /// /// 实体必须带主键 /// 指定更新的字段x=new {x.a,x.b} /// 是否开启事务 /// int Update(T entity, Expression> updateFileds = null, bool beginTransaction = false); /// /// sqlserver使用的临时表参数化批量更新,mysql批量更新待发开 /// /// /// 实体必须带主键 /// 指定更新的字段x=new {x.a,x.b} /// 是否开启事务 /// int UpdateRange(IEnumerable entities, Expression> updateFileds = null, bool beginTransaction = false); int DelWithKey(object[] keys); int DelWithKey(object[] keys, bool beginTransaction = false); /// /// sqlserver批量写入 /// 使用时DataTable table表字段顺序要和数据库字段顺序一致 /// /// mysql批量写入 /// /// /// /// 默认当前下载路径 /// 默认$"{DateTime.Now.ToString("yyyyMMddHHmmss")}.csv" /// int BulkInsert(DataTable table, string tableName, SqlBulkCopyOptions? sqlBulkCopyOptions = null, string fileName = null, string tmpPath = null); /// /// /// /// /// /// /// 所包含的列 /// /// /// /// int BulkInsert(List entities, string tableName = null, Expression> columns = null, SqlBulkCopyOptions? sqlBulkCopyOptions = null); T Execute(Func func, bool beginTransaction = false, bool disposeConn = true); int ExecuteDML(string cmd, object param = null, CommandType? commandType = null, IDbTransaction dbTransaction = null); Task ExecuteDMLAsync(string cmd, object param = null, CommandType? commandType = null, IDbTransaction dbTransaction = null); IDbTransaction GetNewTransaction(); void CommitTransaction(IDbTransaction dbTransaction); void RollbackTransaction(IDbTransaction dbTransaction); DataTable GetTransDataTable(string cmd, object param = null, CommandType? commandType = null, IDbTransaction dbTransaction = null); T QueryTransFirst(string cmd, object param = null, CommandType? commandType = null, IDbTransaction dbTransaction = null) where T : class; }