def test_join_table_on_update_query(self): a, b = Tables('a', 'b') q = Query.update(a) \ .join(b).on(a.fkey_id == b.id) \ .where(b.foo == 1) \ .set('adwords_batch_job_id', 1) self.assertEqual('UPDATE "a" ' 'JOIN "b" ' 'ON "a"."fkey_id"="b"."id" ' 'SET "adwords_batch_job_id"=1 ' 'WHERE "b"."foo"=1', str(q))
def test_update_with_none(self): q = Query.update('abc').set('foo', None) self.assertEqual('UPDATE "abc" SET "foo"=null', str(q))
def test_update__table_schema(self): table = Table('abc', 'schema1') q = Query.update(table).set(table.foo, 1).where(table.foo == 0) self.assertEqual('UPDATE "schema1"."abc" SET "foo"=1 WHERE "foo"=0', str(q))
def test_single_quote_escape_in_set(self): q = Query.update(self.table_abc).set('foo', "bar'foo") self.assertEqual('UPDATE "abc" SET "foo"=\'bar\'\'foo\'', str(q))
def test_omit_where(self): q = Query.update(self.table_abc).set('foo', 'bar') self.assertEqual('UPDATE "abc" SET "foo"=\'bar\'', str(q))
def test_empty_query(self): q = Query.update('abc') self.assertEqual('', str(q))
def test_replace_update_table(self): query = Query.update(self.table_a).set('foo', 'bar') query = query.replace_table(self.table_a, self.table_b) self.assertEqual('UPDATE "b" SET "foo"=\'bar\'', str(query))
def test_single_quote_escape_in_set(self): q = Query.update(self.table_abc).set('foo', "bar'foo") self.assertEqual('UPDATE "abc" SET "foo"=\'bar\'\'foo\'', str(q))
def test_update__table_schema(self): table = Table("abc", "schema1") q = Query.update(table).set(table.foo, 1).where(table.foo == 0) self.assertEqual('UPDATE "schema1"."abc" SET "foo"=1 WHERE "foo"=0', str(q))
def test_single_quote_escape_in_set(self): q = Query.update(self.table_abc).set("foo", "bar'foo") self.assertEqual("UPDATE \"abc\" SET \"foo\"='bar''foo'", str(q))
def test_omit_where(self): q = Query.update(self.table_abc).set("foo", "bar") self.assertEqual('UPDATE "abc" SET "foo"=\'bar\'', str(q))
def test_empty_query(self): q = Query.update("abc") self.assertEqual("", str(q))
async def delete(cls, client_id): query = Query.update(client).set('is_remove', True).where(client.id == client_id) await cls.db.execute(query.get_sql())
def test_update_from(self): from_table = Table('from_table') q = Query.update(self.table_abc).set(self.table_abc.lname, from_table.long_name).from_(from_table) self.assertEqual('UPDATE "abc" SET "lname"="from_table"."long_name" FROM "from_table"', str(q))
def test_update_with_limit(self): q = Query.update(self.table_abc).set(self.table_abc.lname, "test").limit(1) self.assertEqual('UPDATE "abc" SET "lname"=\'test\' LIMIT 1', str(q))
def test_update_with_join(self): q = Query.update(self.table_abc).join(self.table_def).on(self.table_def.abc_id == self.table_abc.id).set(self.table_abc.lname, self.table_def.lname) self.assertEqual('UPDATE "abc" JOIN "def" ON "def"."abc_id"="abc"."id" SET "abc"."lname"="def"."lname"', str(q))
def test_update_with_none(self): q = Query.update("abc").set("foo", None) self.assertEqual('UPDATE "abc" SET "foo"=null', str(q))
def test_empty_query(self): q = Query.update('abc') self.assertEqual('', str(q))