private IIdGeneration defineIdStrategy(Type documentType, StoreOptions options) { if (!idMemberIsSettable()) { return(new NoOpIdGeneration()); } var strategy = options.DefaultIdStrategy?.Invoke(this, options); if (strategy != null) { return(strategy); } var idType = IdMember.GetMemberType(); if (idType == typeof(string)) { return(new StringIdGeneration()); } if (idType == typeof(Guid)) { return(new CombGuidIdGeneration()); } if (idType == typeof(int) || idType == typeof(long)) { return(new HiloIdGeneration(documentType, options.HiloSequenceDefaults)); } throw new ArgumentOutOfRangeException(nameof(documentType), $"Marten cannot use the type {idType.FullName} as the Id for a persisted document. Use int, long, Guid, or string"); }
public IdAssignment <T> ToIdAssignment <T>(ITenant tenant) { var idType = IdMember.GetMemberType(); var assignerType = typeof(IdAssigner <,>).MakeGenericType(typeof(T), idType); return((IdAssignment <T>)Activator.CreateInstance(assignerType, IdMember, IdStrategy, tenant)); }
public IActionResult MemberAdd(IdMember mem) { var addMember = new IdMember() { Id = mem.Id, Username = mem.Username, Password = mem.Password, Email = mem.Email, FullName = mem.FullName, Popularity = mem.Popularity }; Members.Add(addMember); return(Ok(new { status = "success", message = "success add Data", data = Members })); }
public TableDefinition ToTable(IDocumentSchema schema) // take in schema so that you // can do foreign keys { // TODO -- blow up if no IdMember or no TableName var pgIdType = TypeMappings.PgTypes[IdMember.GetMemberType()]; var table = new TableDefinition(TableName, new TableColumn("id", pgIdType)); table.Columns.Add(new TableColumn("data", "jsonb NOT NULL")); return(table); }
public void Load(XDocument stbDoc) { int index = 0; var stbNodes = stbDoc.Root.Descendants("StbNode"); foreach (var stbNode in stbNodes) { // 必須コード Id.Add((int)stbNode.Attribute("id")); X.Add((float)stbNode.Attribute("x") / 1000f); Y.Add((float)stbNode.Attribute("z") / 1000f); // Y-Up対応 Z.Add((float)stbNode.Attribute("y") / 1000f); // 必須ではないコード if (stbNode.Attribute("id_member") != null) { IdMember.Add((int)stbNode.Attribute("id_member")); } else { IdMember.Add(-1); } switch ((string)stbNode.Attribute("kind")) { case "ON_BEAM": Kind.Add(KindsNode.ON_BEAM); break; case "ON_COLUMN": Kind.Add(KindsNode.ON_COLUMN); break; case "ON_GRID": Kind.Add(KindsNode.ON_GRID); break; case "ON_CANTI": Kind.Add(KindsNode.ON_CANTI); break; case "ON_SLAB": Kind.Add(KindsNode.ON_SLAB); break; case "OTHER": Kind.Add(KindsNode.OTHER); break; default: break; } // StbNodeにはない追加した属性 Vertex.Add(new Vector3((float)X[index], (float)Y[index], (float)Z[index])); index++; } }
public TableDefinition ToTable(IDocumentSchema schema) // take in schema so that you // can do foreign keys { // TODO -- blow up if no IdMember or no TableName var pgIdType = TypeMappings.PgTypes[IdMember.GetMemberType()]; var table = new TableDefinition(TableName, new TableColumn("id", pgIdType)); table.Columns.Add(new TableColumn("data", "jsonb NOT NULL")); _fields.Values.OfType <DuplicatedField>().Select(x => x.ToColumn(schema)).Each(x => table.Columns.Add(x)); return(table); }
public void WriteSchemaObjects(IDocumentSchema schema, StringWriter writer) { var table = ToTable(schema); table.Write(writer); writer.WriteLine(); writer.WriteLine(); var pgIdType = TypeMappings.PgTypes[IdMember.GetMemberType()]; var args = new List <UpsertArgument> { new UpsertArgument { Arg = "docId", PostgresType = pgIdType }, new UpsertArgument { Arg = "doc", PostgresType = "JSON" } }; var duplicates = DuplicatedFields.Select(x => x.UpsertArgument).ToArray(); args.AddRange(duplicates); var argList = args.Select(x => x.ArgumentDeclaration()).Join(", "); var valueList = args.Select(x => x.Arg).Join(", "); var updates = "data = doc"; if (duplicates.Any()) { updates += ", " + duplicates.Select(x => $"{x.Column} = {x.Arg}").Join(", "); } writer.WriteLine($"CREATE OR REPLACE FUNCTION {UpsertName}({argList}) RETURNS VOID AS"); writer.WriteLine("$$"); writer.WriteLine("BEGIN"); writer.WriteLine($"INSERT INTO {TableName} VALUES ({valueList})"); writer.WriteLine($" ON CONFLICT ON CONSTRAINT pk_{TableName}"); writer.WriteLine($" DO UPDATE SET {updates};"); writer.WriteLine("END;"); writer.WriteLine("$$ LANGUAGE plpgsql;"); writer.WriteLine(); writer.WriteLine(); }
public void WriteSchemaObjects(IDocumentSchema schema, StringWriter writer) { var table = ToTable(schema); table.Write(writer); writer.WriteLine(); writer.WriteLine(); var pgIdType = TypeMappings.PgTypes[IdMember.GetMemberType()]; var sql = TemplateSource.UpsertDocument() .Replace("%TABLE_NAME%", TableName) .Replace("%SPROC_NAME%", UpsertName) .Replace("%ID_TYPE%", pgIdType); writer.WriteLine(sql); writer.WriteLine(); writer.WriteLine(); }
public virtual TableDefinition ToTable(IDocumentSchema schema) // take in schema so that you // can do foreign keys { var pgIdType = TypeMappings.GetPgType(IdMember.GetMemberType()); var table = new TableDefinition(TableName, new TableColumn("id", pgIdType)); table.Columns.Add(new TableColumn("data", "jsonb") { Directive = "NOT NULL" }); _fields.Values.OfType <DuplicatedField>().Select(x => x.ToColumn(schema)).Each(x => table.Columns.Add(x)); if (IsHierarchy()) { table.Columns.Add(new TableColumn(DocumentTypeColumn, "varchar")); } return(table); }
private void assignIdStrategy(Type documentType, StoreOptions options) { var idType = IdMember.GetMemberType(); if (idType == typeof(string)) { IdStrategy = new StringIdGeneration(); } else if (idType == typeof(Guid)) { IdStrategy = new GuidIdGeneration(); } else if (idType == typeof(int) || idType == typeof(long)) { IdStrategy = new HiloIdGeneration(documentType, options.HiloSequenceDefaults); } else { throw new ArgumentOutOfRangeException(nameof(documentType), $"Marten cannot use the type {idType.FullName} as the Id for a persisted document. Use int, long, Guid, or string"); } }