Example #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 builds_schema_objects_on_the_fly_as_needed()
        {
            _schema.StorageFor(typeof (User)).ShouldNotBeNull();
            _schema.StorageFor(typeof (Issue)).ShouldNotBeNull();
            _schema.StorageFor(typeof (Company)).ShouldNotBeNull();

            using (var runner = new CommandRunner(ConnectionSource.ConnectionString))
            {
                var tables = runner.SchemaTableNames();
                tables.ShouldContain(SchemaBuilder.TableNameFor(typeof(User)).ToLower());
                tables.ShouldContain(SchemaBuilder.TableNameFor(typeof(Issue)).ToLower());
                tables.ShouldContain(SchemaBuilder.TableNameFor(typeof(Company)).ToLower());

                var functions = runner.SchemaFunctionNames();
                functions.ShouldContain(SchemaBuilder.UpsertNameFor(typeof(User)).ToLower());
                functions.ShouldContain(SchemaBuilder.UpsertNameFor(typeof(Issue)).ToLower());
                functions.ShouldContain(SchemaBuilder.UpsertNameFor(typeof(Company)).ToLower());
            }
        }