public TableDefinition StorageTable() { var pgIdType = TypeMappings.GetPgType(_mapping.IdMember.GetMemberType()); var table = new TableDefinition(_mapping.Table, new TableColumn("id", pgIdType)); table.Columns.Add(new TableColumn("data", "jsonb") { Directive = "NOT NULL" }); table.Columns.Add(new TableColumn(DocumentMapping.LastModifiedColumn, "timestamp with time zone") { Directive = "DEFAULT transaction_timestamp()" }); table.Columns.Add(new TableColumn(DocumentMapping.VersionColumn, "uuid") { Directive = "NOT NULL default(md5(random()::text || clock_timestamp()::text)::uuid)" }); table.Columns.Add(new TableColumn(DocumentMapping.DotNetTypeColumn, "varchar")); _mapping.DuplicatedFields.Select(x => x.ToColumn()).Each(x => table.Columns.Add(x)); if (_mapping.IsHierarchy()) { table.Columns.Add(new TableColumn(DocumentMapping.DocumentTypeColumn, "varchar") { Directive = $"DEFAULT '{_mapping.AliasFor(_mapping.DocumentType)}'" }); } if (_mapping.DeleteStyle == DeleteStyle.SoftDelete) { table.Columns.Add(new TableColumn(DocumentMapping.DeletedColumn, "boolean") { Directive = "DEFAULT FALSE" }); table.Columns.Add(new TableColumn(DocumentMapping.DeletedAtColumn, "timestamp with time zone") { Directive = "NULL" }); } return(table); }
public void RegisterUpdate(UpdateBatch batch, object entity, string json) { var call = batch.Sproc(_upsertName); _sprocWriter(call, (T)entity, json, _mapping, _mapping.AliasFor(entity.GetType())); }