Example #1
0
    def test_build_no_join(self):
        builder = SelectBuilder() \
            .table("B") \
            .where("id", Integer(), 1) \
            .add("B", "a") \
            .add("B", "b")

        self.assertEqual(
            builder.build(),
            ('SELECT "B"."a", "B"."b" FROM "B"  WHERE "B"."id" = 1', [
                ('B', 'a'), ('B', 'b')
            ]))
Example #2
0
    def test_override_where(self):
        builder = SelectBuilder() \
            .table("B") \
            .where("id", Integer(), 1) \
            .join("C", "id", "B", "id") \
            .add("B", "a") \
            .add("B", "b") \
            .add("C", "c") \
            .where("id", Integer(), 2)

        self.assertEqual(builder.build(), (
            'SELECT "B"."a", "B"."b", "C"."c" FROM "B" JOIN "C" ON ("C"."id" = "B"."id") WHERE "B"."id" = 2',
            [('B', 'a'), ('B', 'b'), ('C', 'c')]))
Example #3
0
    def test_build(self):
        builder = SelectBuilder() \
            .table("B") \
            .where("id", Integer(), 1) \
            .join("C", "id", "B", "id") \
            .join("D", "id", "C", "id") \
            .add("B", "a") \
            .add("B", "b") \
            .add("C", "c") \
            .add("D", "d")

        self.assertEqual(builder.build(), (
            'SELECT "B"."a", "B"."b", "C"."c", "D"."d" FROM "B" JOIN "C" ON ("C"."id" = "B"."id") JOIN "D" ON ("D"."id" = "C"."id") WHERE "B"."id" = 1',
            [('B', 'a'), ('B', 'b'), ('C', 'c'), ('D', 'd')]))
Example #4
0
    def test_empty(self):
        builder = SelectBuilder() \
            .table("B") \
            .where("id", Integer(), 1) \
            .join("C", "id", "B", "id")

        self.assertRaises(AssertionError, builder.build)
Example #5
0
    def test_is_empty(self):
        builder = SelectBuilder()

        self.assertTrue(builder.is_empty())

        builder.add("B", "a")

        self.assertFalse(builder.is_empty())

        builder.add("B", "b") \
            .add("C", "c")

        self.assertFalse(builder.is_empty())
Example #6
0
    def test_no_table(self):
        builder = SelectBuilder() \
            .where("id", Integer(), 1) \
            .join("C", "id", "B", "id") \
            .add("B", "a") \
            .add("B", "b") \
            .add("C", "c")

        self.assertRaises(AssertionError, builder.build)
Example #7
0
 def __build_regular(self, table_name, types, names, key_name, key_value):
     builder = SelectBuilder().table(table_name)
     for field_name in types.keys():
         builder.add(table_name, names[field_name])
     builder.where(names[key_name], types[key_name], key_value)
     return builder