public void Insert(NpgsqlConnection connection, User[] users, string[] passwords) { var columns = new[] { DbStr.Id, DbStr.Name, DbStr.Description, DbStr.Photo, DbStr.Password, DbStr.Enabled, DbStr.CanChange, DbStr.Privilege }; var values = users.Select((u, i) => new object[] { u.Id, u.Name, u.Description, u.Photo, passwords[i], u.Enabled, u.CanChange, u.Privilege }).ToArray(); _npgHelper.ExecuteNonQuery(connection, _npgQueryHelper.Insert(DbStr.Users, columns, values)); }
private void EnsureTable(int ordinal, IEnumerable <string> tables) { var tableName = GetTableName(ordinal); if (!tables.Contains(tableName)) { var tb = new NpgTableInfoBuilder(tableName); tb.AddColumn(DbStr.Time, NpgDataType.Int8, true); tb.AddPrimaryKey(DbStr.Time); var createTableQuery = _npgQueryHelper.CreateTable(tb.Build()); _npgHelper.ExecuteScript(_connection, new[] { createTableQuery }); } var columns = _npgHelper.GetColumns(_connection, tableName); foreach (var trendTagId in _trendTagIds) { var column = GetColumnName(trendTagId); if (columns.Contains(column)) { continue; } var createColumnQuery = _npgQueryHelper.CreateColumn( tableName, new NpgColumnInfo { Name = column, DataType = NpgDataType.Float8, NotNull = false }); _npgHelper.ExecuteNonQuery(_connection, createColumnQuery); } }
public bool Update(NpgsqlConnection connection, LogItem item) { var query = _npgQueryHelper.UpdateWhere( _tableName, new Eq(DbStr.Time, item.Time.Ticks), new[] { DbStr.Text, DbStr.Bytes }, new object[] { item.Text, item.Bytes }); return(_npgHelper.ExecuteNonQuery(connection, query) == 1); }
public void Insert(NpgsqlConnection connection, Tuple <DateTime, int, DateTime?>[] newAlarms) { var columns = new[] { DbStr.StartTime, DbStr.AlarmId, DbStr.AcknowledgeTime }; var values = newAlarms.Select(a => new object[] { a.Item1.Ticks, a.Item2, a.Item3.ToNullableTicks() }).ToArray(); _npgHelper.ExecuteNonQuery(connection, _npgQueryHelper.Insert(_tableName, columns, values)); }