public void SetUp() { builder = new SqlBuilder(); date = "2020-01-01"; columnValueDictionary = ColumnValueDictionary.Create( new ColumnValue("id", 2), new ColumnValue("name", "test"), new ColumnValue("date", date), new ColumnValue("money", 1.5)); }
public ISqlBuilder Update(string table, ColumnValueDictionary columnValues, ColumnValue idColumnValue) { query = $"UPDATE {table} SET "; foreach (var key in columnValues.Keys) { query += $"{key}={(columnValues[key] != null ? $"'{columnValues[key]}'" : "NULL")},"; } query = query.RemoveLastCharacter(); query += " "; Where(idColumnValue.Column).Equals.Append($"'{idColumnValue.Value}'"); return(this); }
public async Task <bool> Insert <T>(T entity, bool autoPrimaryKey = true) { var entityProperties = entity.GetPropertiesWithAttribute(typeof(ColumnAttribute)) .Where(ep => !ep.GetCustomAttributes().OfType <ColumnAttribute>().FirstOrDefault().CustomProperty); var columnValues = ColumnValueDictionary.Create(entity, entityProperties, autoPrimaryKey); using (var connection = connectionFactory.Connection) { var insertQuery = new SqlBuilder() .InsertInto(Table, columnValues) .Build(); return(await connection.ExecuteAsync(insertQuery.Query, commandTimeout : SqlConstants.CommandTimeout) > 0); } }
public ISqlBuilder InsertInto(string table, ColumnValueDictionary columnValues) { query = $"INSERT INTO {table} ({string.Join(",", columnValues.Keys)})"; query = query.RemoveLastCharacter(); query += ") VALUES ("; foreach (var key in columnValues.Keys) { query += $"{(columnValues[key] != null ? $"'{columnValues[key]}'" : "NULL")},"; } query = query.RemoveLastCharacter(); query += ")"; return(this); }
private static SqlQuery BuildRevokeQuery(int id, string column) => new SqlBuilder() .Update(userTable, ColumnValueDictionary.Create(RoleDictionary.DefaultRoleColumnValue(column)), IdColumnValue(id)) .Build();
private static SqlQuery BuildAdmitQuery(int id, ColumnValue columnValue) => new SqlBuilder() .Update(userTable, ColumnValueDictionary.Create(columnValue), IdColumnValue(id)) .Build();