Ejemplo n.º 1
0
        public void TestDropTable()
        {
            Db.CreateTable("newtable", Pairing.Of("name", "text"), Pairing.Of("number", "int")).Execute();
            Db.DropTable("newtable").Execute();

            var table = Db.Take("information_schema.tables").Where(Pairing.Of("table_name", "newtable")).Execute();

            Assert.AreEqual(0, table[0].Count);
        }
Ejemplo n.º 2
0
        void CreateTestTable()
        {
            Db.CreateTable("test", Pairing.Of("name", "text"), Pairing.Of("age", "int")).Execute();

            Db.Insert("test", Pairing.Of("name", "Marla"), Pairing.Of("age", 36)).Execute();
            Db.Insert("test", Pairing.Of("name", "Susan"), Pairing.Of("age", 100)).Execute();
            Db.Insert("test", Pairing.Of("name", "John"), Pairing.Of("age", 67)).Execute();
            Db.Insert("test", Pairing.Of("name", "Jenna"), Pairing.Of("age", 34)).Execute();
            Db.Insert("test", Pairing.Of("name", "RJ"), Pairing.Of("age", 29)).Execute();
        }
Ejemplo n.º 3
0
        public void TestInsert()
        {
            Db.Insert("test", Pairing.Of("name", "Bob")).Execute();

            var results = Db.Take("test").Where(Pairing.Of("name", "Bob")).Execute();

            Assert.IsNotNull(results);
            Assert.AreEqual("Bob", results[1][0]);
            Assert.AreEqual(1, results[0].Count);

            Db.Delete("test").Where(Pairing.Of("name", "Bob")).Execute();
        }
Ejemplo n.º 4
0
        public void TestDelete()
        {
            Db.Insert("test", Pairing.Of("name", "Bob")).Execute();
            Db.Delete("test").Where(Pairing.Of("name", "Bob")).Execute();

            var results1 = Db.Take("test").Where(Pairing.Of("name", "Bob")).Execute();
            var results2 = Db.Take("test").Execute();

            Assert.AreEqual(0, results1[0].Count);
            Assert.AreEqual(5, results2[0].Count);
            Assert.AreEqual("Marla", results2[1].Find(name => name == "Marla"));
            Assert.AreEqual(-1, results2[1].FindIndex(name => name == "Bob"));
        }
Ejemplo n.º 5
0
        // Starting place
        public PostgreSQLConnection DropTable(string table)
        {
            var result = Take("information_schema.tables").Where(Pairing.Of("table_name", $"{table}")).Execute();

            // Table is in the database so we can delete it
            if (result[0].Count > 0)
            {
                SQL     = $"drop table {table}";
                IsQuery = false;
            }

            return(this);
        }
Ejemplo n.º 6
0
        public void TestWhere()
        {
            var results = Db.Take("test").Where(Pairing.Of("name", "Susan"), Pairing.Of("id", 2)).Execute();

            Assert.IsNotNull(results);
            Assert.AreEqual(1, results[0].Count);
            Assert.AreEqual("Susan", results[1][0]);

            results = Db.Take("test").Where(Pairing.Of("age", 100)).Execute();

            Assert.IsNotNull(results);
            Assert.AreEqual(1, results[0].Count);
            Assert.AreEqual("Susan", results[1][0]);
        }
Ejemplo n.º 7
0
        // Starting place
        public PostgreSQLConnection CreateTable(string table, params KeyValuePair <string, object>[] columnTypes)
        {
            var result = Take("information_schema.tables").Where(Pairing.Of("table_name", $"{table}")).Execute();

            if (result[0].Count == 0)
            {
                SQL = $"create table {table}();" +
                      $" alter table {table} add column id bigserial primary key;";

                foreach (var columnType in columnTypes)
                {
                    SQL = SQL + $" alter table {table} add column {columnType.Key} {columnType.Value.ToString()};";
                }
            }

            return(this);
        }