Beispiel #1
0
        private static void RunMappingEngineNestedResultsBenchmark()
        {
            var mapping = JsonMappingBuilder.Root()
                          .Property("Version", "2.0")
                          .QueryWithNesting("Results",
                                            @"select c.id as cid, c.sname,'2017-03-01' as LastUpdate, c.fname, c.BDAY, c.ADR_STREET, c.ADR_CITY, i.id as iid, i.inv_date, i.amount, o.article, o.id as oid, oi.item_name,oi.price, oi.id as oiid
                                    from customer c
                                    left join invoices i on c.id = i.customer_id
                                    left join orders o on c.id = o.customer_id
                                    left join order_items oi on o.id = oi.order_id
                                    ", //where amount>${context:min_amount:Int32}
                                       // Id Column
                                            "cid"
                                            , cfg1 => cfg1
                                            .Column("Id", "cid")
                                            .Column("SName")
                                            .Column("LastUpdate")
                                            .Column("Birthday", "BDAY")
                                            .Object("Address", cfg2 => cfg2
                                                    .Column("Street", "ADR_STREET")
                                                    .Column("City", "ADR_CITY")
                                                    )
                                            .NestedResults("Invoices", "iid", cfg2 => cfg2
                                                           .Column("InvoiceId", "iid")
                                                           .Column("Inv_Date")
                                                           .Column("TotalAmount", "amount")
                                                           )
                                            .NestedResults("Orders", "oid", cfg2 => cfg2
                                                           .Column("OrderId", "oid")
                                                           .Column("ArticleName", "article")
                                                           .NestedResults("Items", "oiid", cfg3 => cfg3
                                                                          .Column("id", "oiid")
                                                                          .Column("Item_Name")
                                                                          .Column("Price")
                                                                          )
                                                           )
                                            )
                          //.Property("Last-Update", "2010-10-10")
                          .Result;


            var sw = new Stopwatch();

            sw.Start();

            using (var engine = new MappingEngine(() => new NpgsqlConnection("Server=localhost;User Id=postgres;" +
                                                                             "Password=admin;Database=test;"), mapping))
            {
                using (var ms = new FileStream("out-sql2json-nested.json", FileMode.Create))
                {
                    var context = new Dictionary <string, object>();
                    //      context.Add("min_amount", 10);
                    engine.ExecuteMapping(ms, context, false);
                }
            }

            sw.Stop();
            Console.WriteLine("RunMappingEngineNestedResultsBenchmark time elapsed: " + sw.ElapsedMilliseconds);
        }
Beispiel #2
0
        public void TestMappingBuilderObjectAsRoot()
        {
            var mapping = JsonMappingBuilder.Root()
                          .Property("Version", "2.0")
                          .QueryWithNesting("Results",
                                            @"select c.id as cid, sname,'2017-03-01' as LastUpdate, fname, BDAY, ADR_STREET, ADR_CITY, i.id as iid, i.inv_date, i.amount, o.article, o.id as oid
                        from customer c
                        left join orders o on c.id = o.customer_id
                        left join invoices i on c.id = i.customer_id
                        where i.amount > ${context:min_amount}",
                                            // Id Column
                                            "cid"
                                            , cfg1 => cfg1
                                            .Column("Id", "cid")
                                            .Column("SName")
                                            .Column("LastUpdate")
                                            .Column("Birthday", "BDAY")
                                            .Object("Address", cfg2 => cfg2
                                                    .Column("Street", "ADR_STREET")
                                                    .Column("City", "ADR_CITY")
                                                    )
                                            .NestedResults("Invoices", "iid", cfg2 => cfg2
                                                           .Column("InvoiceId", "iid")
                                                           .Column("Inv_Date")
                                                           .Column("TotalAmount", "amount")
                                                           )
                                            .NestedResults("Orders", "oid", cfg2 => cfg2
                                                           .Column("OrderId", "oid")
                                                           .Column("ArticleName", "article")
                                                           )
                                            )
                          //.Property("Last-Update", "2010-10-10")
                          .Result;

            using (var engine = new MappingEngine(() => new SqliteConnection("Data Source=Test.db"), mapping))
            {
                using (var ms = new MemoryStream())
                {
                    var context = new Dictionary <string, object>();
                    context.Add("min_amount", 100);
                    engine.ExecuteMapping(ms, context, false);
                    var json = System.Text.Encoding.UTF8.GetString(ms.ToArray());
                    Assert.Equal(nestedResultsGeneratedJson, json);
                }
            }
        }
Beispiel #3
0
 public MappingBuilderTests()
 {
     builder = JsonMappingBuilder.Root();
 }