コード例 #1
0
 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};");
     }
 }
コード例 #2
0
ファイル: UpdateBatch.cs プロジェクト: Xamarui/marten
        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);
        }
コード例 #3
0
 public ComputedIndex(DocumentMapping mapping, MemberInfo[] members)
 {
     _members = members;
     var field = mapping.FieldFor(members);
     _locator = field.SqlLocator.Replace("d.", "");
     _table = mapping.Table;
 }
コード例 #4
0
        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 = "*"
            });
        }
コード例 #5
0
        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;
        }
コード例 #6
0
ファイル: BatchCommand.cs プロジェクト: Xamarui/marten
        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);
        }
コード例 #7
0
ファイル: TableDiff.cs プロジェクト: danielmarbach/marten
        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;
        }
コード例 #8
0
        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");
        }
コード例 #9
0
        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;
        }
コード例 #10
0
        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());
            }

        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        public static void Drop(this IDDLRunner runner, object subject, TableName table)
        {
            var sql = $"drop table if exists {table.QualifiedName} cascade;";

            runner.Apply(subject, sql);
        }
コード例 #14
0
ファイル: DbObjects.cs プロジェクト: phillip-haydon/marten
 public bool TableExists(TableName table)
 {
     var schemaTables = SchemaTables();
     return schemaTables.Contains(table);
 }
コード例 #15
0
ファイル: DbObjects.cs プロジェクト: phillip-haydon/marten
 public IEnumerable<ActualIndex> IndexesFor(TableName table)
 {
     return AllIndexes().Where(x => x.Table.Equals(table)).ToArray();
 }
コード例 #16
0
ファイル: DbObjects.cs プロジェクト: stush/marten
 public IEnumerable <ActualIndex> IndexesFor(TableName table)
 {
     return(AllIndexes().Where(x => x.Table.Equals(table)).ToArray());
 }
コード例 #17
0
ファイル: UpdateBatch.cs プロジェクト: Xamarui/marten
        public void Delete(TableName table, object id, NpgsqlDbType dbType)
        {
            if (table == null) throw new ArgumentNullException(nameof(table));

            Current().Delete(table, id, dbType);
        }
コード例 #18
0
 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");
 }
コード例 #19
0
ファイル: DbObjects.cs プロジェクト: stush/marten
        public bool TableExists(TableName table)
        {
            var schemaTables = SchemaTables();

            return(schemaTables.Contains(table));
        }
コード例 #20
0
ファイル: BatchCommand.cs プロジェクト: Xamarui/marten
 public void Delete(TableName table, object id, NpgsqlDbType dbType)
 {
     var param = addParameter(id, dbType);
     var call = new DeleteCall(table, param.ParameterName);
     _calls.Add(call);
 }
コード例 #21
0
ファイル: BatchCommand.cs プロジェクト: Xamarui/marten
            public DeleteWhereCall(TableName table, string whereClause)
            {
                if (table == null) throw new ArgumentNullException(nameof(table));

                _table = table;
                _whereClause = whereClause;
            }
コード例 #22
0
ファイル: BatchCommand.cs プロジェクト: Xamarui/marten
            public DeleteCall(TableName table, string idParam)
            {
                if (table == null) throw new ArgumentNullException(nameof(table));

                _table = table;
                _idParam = idParam;
            }
コード例 #23
0
 public string ToComputedIndex(TableName tableName)
 {
     return($"CREATE INDEX {tableName.Name}_{MemberName.ToTableAlias()} ON {tableName.QualifiedName} (({SqlLocator}));");
 }
コード例 #24
0
 public static void Drop(this IDDLRunner runner, object subject, TableName table)
 {
     var sql = $"drop table if exists {table.QualifiedName} cascade;";
     runner.Apply(subject, sql);
 }
コード例 #25
0
 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");
 }