Пример #1
0
 def test_no_queryexception_if_returning_used_on_valid_query_type(self):
     # No exceptions for insert, update and delete queries
     with self.subTest('DELETE'):
         PostgreSQLQuery.from_(self.table_abc).where(self.table_abc.foo == self.table_abc.bar).delete().returning(
             "id"
         )
     with self.subTest('UPDATE'):
         PostgreSQLQuery.update(self.table_abc).where(self.table_abc.foo == 0).set("foo", "bar").returning("id")
     with self.subTest('INSERT'):
         PostgreSQLQuery.into(self.table_abc).insert('abc').returning('abc')
Пример #2
0
 def test_upsert(self):
     q = (
         PostgreSQLQuery.into("abc")
         .insert(1, "b", False)
         .as_("aaa")
         .on_conflict(self.table_abc.id)
         .do_update("abc")
     )
     self.assertEqual(
         'INSERT INTO "abc" VALUES (1,\'b\',false) ON CONFLICT ("id") DO UPDATE SET "abc"=EXCLUDED."abc"',
         str(q),
     )
Пример #3
0
    def test_array_keyword(self):
        q = PostgreSQLQuery.into(self.table_abc).insert(1, [1, "a", True])

        self.assertEqual("INSERT INTO \"abc\" VALUES (1,ARRAY[1,'a',true])",
                         str(q))
Пример #4
0
    def test_array_keyword(self):
        q = PostgreSQLQuery.into(self.table_abc).insert(1, [1, "a", True])

        self.assertEqual('INSERT INTO "abc" VALUES (1,ARRAY[1,\'a\',true])',
                         str(q))
Пример #5
0
 def test_insert_ignore(self):
     q = PostgreSQLQuery.into("abc").insert((1, "a", True)).on_conflict().do_nothing()
     self.assertEqual("INSERT INTO \"abc\" VALUES (1,'a',true) ON CONFLICT DO NOTHING", str(q))
Пример #6
0
 def insert(self):
     return Query_.into(self.table)