public static void CleanTable <T>() where T : new() { var table = GetTableNameWithQuotes <T>(); var cleanTableQuery = $"TRUNCATE {table}"; DataBaseDataReader.ExecuteNonQuery(new ConfigurationSettings().ConnectionString, cleanTableQuery); }
public static void InsertMultiples <T>(string connectionString, IList <T> entities, bool getLastId = true) where T : new() { var query = new StringBuilder(); entities.ToList().ForEach(entity => { var insertBuilder = new InsertQueryBuilder() .WithFields(EntityFactory.GetFieldsWithValues(entity, true)); query.Append(insertBuilder.Build <T>()); query.Append(";"); }); if (getLastId && KeyAttribute.HasEntityAutoIncremenetalKey <T>()) { query.Append("SELECT LAST_INSERT_ID()"); using var exe = new DataBaseExecuteReader(connectionString, query.ToString()); if (exe.DataReader.Read()) { var keyProperty = KeyAttribute.GetAutoIncrementKeyProperty <T>(); var lastId = (int)exe.DataReader.GetULong(0) - entities.Count(); entities.ToList().ForEach(entity => { keyProperty.SetValue(entity, Convert.ChangeType(++lastId, keyProperty.PropertyType)); }); } } else { DataBaseDataReader.ExecuteNonQuery(connectionString, query.ToString()); } }
public static void Replace <T>(string connectionString, T entity) where T : new() { var replaceBuilder = new ReplaceQueryBuilder() .WithFields(EntityFactory.GetFieldsWithValues(entity, false)); var query = replaceBuilder.Build <T>(); DataBaseDataReader.ExecuteNonQuery(connectionString, query); }
public static void Delete <T>(string connectionString, T entity) where T : new() { var(condition, wheres) = KeyAttribute.GetKeysQueryWhere(entity); var deleteQueryBuilder = new DeleteQueryBuilder() .WithWhere(condition, wheres.ToArray()); var query = deleteQueryBuilder.Build <T>(); DataBaseDataReader.ExecuteNonQuery(connectionString, query); }
private static void Update <T>(string connectionString, T entity, Dictionary <string, object> fieldsWithValues) where T : new() { var(condition, wheres) = KeyAttribute.GetKeysQueryWhere(entity); var updateBuilder = new UpdateQueryBuilder() .WithFields(fieldsWithValues) .WithWhere(condition, wheres.ToArray()); var query = updateBuilder.Build <T>(); DataBaseDataReader.ExecuteNonQuery(connectionString, query); }
public ulong GetLastInsertId() { return(DataBaseDataReader.GetLastInsertId(connectionString)); }
public Result <T> GetSelectValue <T>(string query, List <MySqlParameter> parameters = null) { return(DataBaseDataReader.GetSelectValue <T>(connectionString, query, parameters)); }
public void ExecuteNonQuery(string query, List <MySqlParameter> parameters) { DataBaseDataReader.ExecuteNonQuery(connectionString, query, parameters); }
public void ExecuteNonQuery(string query) { DataBaseDataReader.ExecuteNonQuery(connectionString, query); }