public static void OwnershipToTable(this IDDLRunner runner, StoreOptions options, TableName table) { if (options.OwnerName.IsNotEmpty()) { runner.Apply(table, $"ALTER TABLE {table.QualifiedName} OWNER TO {options.OwnerName};"); } }
public void DeleteWhere(TableName table, IWhereFragment @where) { if (table == null) throw new ArgumentNullException(nameof(table)); if (@where == null) throw new ArgumentNullException(nameof(@where)); Current().DeleteWhere(table, @where); }
public ComputedIndex(DocumentMapping mapping, MemberInfo[] members) { _members = members; var field = mapping.FieldFor(members); _locator = field.SqlLocator.Replace("d.", ""); _table = mapping.Table; }
public UpsertFunction(DocumentMapping mapping) { if (mapping == null) throw new ArgumentNullException(nameof(mapping)); _functionName = mapping.UpsertFunction; _tableName = mapping.Table; _primaryKeyConstraintName = "pk_" + mapping.Table.Name; var idType = mapping.IdMember.GetMemberType(); var pgIdType = TypeMappings.GetPgType(idType); Arguments.Add(new UpsertArgument { Arg = "docId", PostgresType = pgIdType, Column = "id", Members = new[] {mapping.IdMember} }); Arguments.Add(new UpsertArgument { Arg = "doc", PostgresType = "JSONB", DbType = NpgsqlDbType.Jsonb, Column = "data", BulkInsertPattern = "writer.Write(serializer.ToJson(x), NpgsqlDbType.Jsonb);", BatchUpdatePattern = "*" }); }
public TableDefinition(TableName table, TableColumn primaryKey) { if (table == null) throw new ArgumentNullException(nameof(table)); if (primaryKey == null) throw new ArgumentNullException(nameof(primaryKey)); Table = table; PrimaryKey = primaryKey; }
public void DeleteWhere(TableName table, IWhereFragment @where) { if (table == null) throw new ArgumentNullException(nameof(table)); if (@where == null) throw new ArgumentNullException(nameof(@where)); var whereClause = @where.ToSql(_command); var call = new DeleteWhereCall(table, whereClause); _calls.Add(call); }
public TableDiff(TableDefinition expected, TableDefinition actual) { Missing = expected.Columns.Where(x => actual.Columns.All(_ => _.Name != x.Name)).ToArray(); Extras = actual.Columns.Where(x => expected.Columns.All(_ => _.Name != x.Name)).ToArray(); Matched = expected.Columns.Intersect(actual.Columns).ToArray(); Different = expected.Columns.Where(x => actual.HasColumn(x.Name) && !x.Equals(actual.Column(x.Name))).ToArray(); _tableName = expected.Table; }
public EventQueryMapping(StoreOptions storeOptions) : base(typeof(IEvent), storeOptions) { Selector = new EventSelector(storeOptions.Events, storeOptions.Serializer()); DatabaseSchemaName = storeOptions.Events.DatabaseSchemaName; Table = new TableName(DatabaseSchemaName, "mt_events"); duplicateField(x => x.Sequence, "seq_id"); duplicateField(x => x.StreamId, "stream_id"); duplicateField(x => x.Version, "version"); duplicateField(x => x.Timestamp, "timestamp"); }
public TableDefinition(TableName table, string pkName, IEnumerable<TableColumn> columns) { if (table == null) throw new ArgumentNullException(nameof(table)); if (string.IsNullOrEmpty(pkName)) throw new ArgumentOutOfRangeException(nameof(pkName)); Table = table; Columns.AddRange(columns); var primaryKey = Column(pkName); if (primaryKey == null) throw new InvalidOperationException($"Primary key {pkName} not found in columns."); PrimaryKey = primaryKey; }
public UpsertFunction(DocumentMapping mapping) { if (mapping == null) throw new ArgumentNullException(nameof(mapping)); _functionName = mapping.UpsertFunction; _tableName = mapping.Table; _primaryKeyConstraintName = "pk_" + mapping.Table.Name; var idType = mapping.IdMember.GetMemberType(); var pgIdType = TypeMappings.GetPgType(idType); Arguments.Add(new UpsertArgument { Arg = "docId", PostgresType = pgIdType, Column = "id", Members = new[] {mapping.IdMember} }); Arguments.Add(new DocJsonBodyArgument()); Arguments.AddRange(mapping.DuplicatedFields.Select(x => x.UpsertArgument)); Arguments.Add(new VersionArgument()); Arguments.Add(new DotNetTypeArgument()); if (mapping.IsHierarchy()) { Arguments.Add(new DocTypeArgument()); } if (mapping.UseOptimisticConcurrency) { Arguments.Add(new CurrentVersionArgument()); } }
public static void RemoveColumn(this IDDLRunner runner, object subject, TableName table, string columnName) { var sql = $"alter table if exists {table.QualifiedName} drop column if exists {columnName};"; runner.Apply(subject, sql); }
public static void Drop(this IDDLRunner runner, object subject, TableName table) { var sql = $"drop table if exists {table.QualifiedName} cascade;"; runner.Apply(subject, sql); }
public bool TableExists(TableName table) { var schemaTables = SchemaTables(); return schemaTables.Contains(table); }
public IEnumerable<ActualIndex> IndexesFor(TableName table) { return AllIndexes().Where(x => x.Table.Equals(table)).ToArray(); }
public IEnumerable <ActualIndex> IndexesFor(TableName table) { return(AllIndexes().Where(x => x.Table.Equals(table)).ToArray()); }
public void Delete(TableName table, object id, NpgsqlDbType dbType) { if (table == null) throw new ArgumentNullException(nameof(table)); Current().Delete(table, id, dbType); }
public void owner_name_has_no_schema_if_schema_is_public() { var table = new TableName("public", "mt_doc_user"); table.OwnerName.ShouldBe("mt_doc_user"); }
public bool TableExists(TableName table) { var schemaTables = SchemaTables(); return(schemaTables.Contains(table)); }
public void Delete(TableName table, object id, NpgsqlDbType dbType) { var param = addParameter(id, dbType); var call = new DeleteCall(table, param.ParameterName); _calls.Add(call); }
public DeleteWhereCall(TableName table, string whereClause) { if (table == null) throw new ArgumentNullException(nameof(table)); _table = table; _whereClause = whereClause; }
public DeleteCall(TableName table, string idParam) { if (table == null) throw new ArgumentNullException(nameof(table)); _table = table; _idParam = idParam; }
public string ToComputedIndex(TableName tableName) { return($"CREATE INDEX {tableName.Name}_{MemberName.ToTableAlias()} ON {tableName.QualifiedName} (({SqlLocator}));"); }
public void owner_name_has_schema_if_not_in_public() { var table = new TableName("other", "mt_doc_user"); table.OwnerName.ShouldBe("other.mt_doc_user"); }