示例#1
0
        public void try_command_runner()
        {
            var builder = new SchemaBuilder();
            builder.CreateTable(typeof(SchemaBuilderTests.MySpecialDocument), typeof(Guid));
            builder.DefineUpsert(typeof (SchemaBuilderTests.MySpecialDocument), typeof(Guid));

            var id = Guid.NewGuid();

            using (var runner = new CommandRunner(ConnectionSource.ConnectionString))
            {
                runner.Execute(builder.ToSql());
                /*
                runner.Execute("mt_upsert_myspecialdocument", command =>
                {
                    command.Parameters.Add("docId", NpgsqlDbType.Uuid).Value = id;
                    command.Parameters.Add("doc", NpgsqlDbType.Json).Value = "{\"id\":\"1\"}";
                });

                runner.Execute("mt_upsert_myspecialdocument", command =>
                {
                    command.Parameters.Add("docId", NpgsqlDbType.Uuid).Value = id;
                    command.Parameters.Add("doc", NpgsqlDbType.Json).Value = "{\"id\":\"2\"}";
                });
                 * */
                //runner.DescribeSchema();
                runner.SchemaFunctionNames().Each(x => Debug.WriteLine(x));
            }
        }
        public void write_upsert_sql()
        {
            var builder = new SchemaBuilder();
            builder.DefineUpsert(typeof(MySpecialDocument));

            var sql = builder.ToSql();

            sql.ShouldContain("INSERT INTO mt_doc_MySpecialDocument");
            sql.ShouldContain("CREATE OR REPLACE FUNCTION mt_upsert_MySpecialDocument");
        }