private static GeneratedType buildInsertStream(GeneratedType builderType, GeneratedAssembly generatedAssembly,
                                                       EventGraph graph)
        {
            var operationType = generatedAssembly.AddType(InsertStreamOperationName, typeof(InsertStreamBase));

            var columns = new StreamsTable(graph)
                          .Columns
                          .OfType <IStreamTableColumn>()
                          .Where(x => x.Writes)
                          .ToArray();

            var sql = $"insert into {graph.DatabaseSchemaName}.mt_streams ({columns.Select(x => x.Name).Join(", ")}) values ({columns.Select(_ => "?").Join(", ")})";
            var configureCommand = operationType.MethodFor("ConfigureCommand");

            configureCommand.DerivedVariables.Add(new Variable(typeof(StreamAction), nameof(InsertStreamBase.Stream)));

            configureCommand.Frames.Code($"var parameters = {{0}}.{nameof(CommandBuilder.AppendWithParameters)}(\"{sql}\");",
                                         Use.Type <CommandBuilder>());

            for (var i = 0; i < columns.Length; i++)
            {
                columns[i].GenerateAppendCode(configureCommand, i);
            }

            builderType.MethodFor(nameof(EventDocumentStorage.InsertStream))
            .Frames.Code($"return new Marten.Generated.{InsertStreamOperationName}(stream);");

            return(operationType);
        }
Beispiel #2
0
        public void use_string_id_if_as_string_identifiers()
        {
            var events = new EventGraph(new StoreOptions())
            {
                StreamIdentity = StreamIdentity.AsString
            };

            var table = new StreamsTable(events);

            table.PrimaryKey.Type.ShouldBe("varchar");
            table.First().Name.ShouldBe("id");
        }