def test_customsql(self, tables): tables.set('t') tables.join('u').on('col', sqlpuzzle.customsql('x')) assert str(tables) == '"t" JOIN "u" ON "col" = x'
def test_custom_more_tables(tables): customsql = sqlpuzzle.customsql('"custom" JOIN "sql"') tables.set(customsql, 'id') assert str(tables) == '"custom" JOIN "sql", "id"'
def setUp(self): super(CustomSqlTest, self).setUp() self.customsql = sqlpuzzle.customsql('"age" = "age" + 1')
def setUp(self): super(CustomSqlTest, self).setUp() self.customsql = sqlpuzzle.customsql('"custom" JOIN "sql"')
def test_custom_more_columns(columns): customsql = sqlpuzzle.customsql('AVG("custom") AS "x"') columns.columns(customsql, 'id') assert str(columns) == 'AVG("custom") AS "x", "id"'
def test_custom_in_column_with_as(self): self.columns.columns({sqlpuzzle.customsql('AVG("custom")'): 'x'}) self.assertEqual(str(self.columns), 'AVG("custom") AS "x"')
def test_copy_with_custom(): query1 = sqlpuzzle.select_from('t').where(sqlpuzzle.customsql('x')) query2 = query1.copy() assert str(query1) == str(query2)
def test_custom_one_table(tables): customsql = sqlpuzzle.customsql('"custom" JOIN "sql"') tables.set(customsql) assert str(tables) == '"custom" JOIN "sql"'
def test_customsql(self): self.tables.set('t') self.tables.join('u').on('col', sqlpuzzle.customsql('x')) self.assertEqual(str(self.tables), '"t" JOIN "u" ON "col" = x')
def test_custom_in_column_with_as(self): self.tables.set({sqlpuzzle.customsql('"custom"'): 'x'}) self.assertEqual(str(self.tables), '"custom" AS "x"')
def setUp(self): super(CustomSqlTest, self).setUp() self.customsql = sqlpuzzle.customsql('AVG("custom") AS "x"')
def test_custom_in_column_with_as(columns): columns.columns({sqlpuzzle.customsql('AVG("custom")'): 'x'}) assert str(columns) == 'AVG("custom") AS "x"'
def test_copy_with_custom(self): query1 = sqlpuzzle.select_from('t').where(sqlpuzzle.customsql('x')) query2 = query1.copy() self.assertEquals(str(query1), str(query2))
def test_compare_column_with_custom(): custom = sqlpuzzle.customsql('custom') column = Column('column') assert column != custom # Do not throw exception.
def test_custom_sql(self): # Do not throw exception InvalidArgumentException. sqlpuzzle.relations.EQ(sqlpuzzle.customsql('custom')) sqlpuzzle.relations.NE(sqlpuzzle.customsql('custom')) sqlpuzzle.relations.GT(sqlpuzzle.customsql('custom')) sqlpuzzle.relations.GE(sqlpuzzle.customsql('custom')) sqlpuzzle.relations.LT(sqlpuzzle.customsql('custom')) sqlpuzzle.relations.LE(sqlpuzzle.customsql('custom')) sqlpuzzle.relations.LIKE(sqlpuzzle.customsql('custom')) sqlpuzzle.relations.REGEXP(sqlpuzzle.customsql('custom')) sqlpuzzle.relations.IN(sqlpuzzle.customsql('custom')) sqlpuzzle.relations.NOT_IN(sqlpuzzle.customsql('custom')) sqlpuzzle.relations.IS(sqlpuzzle.customsql('custom')) sqlpuzzle.relations.IS_NOT(sqlpuzzle.customsql('custom'))
def test_custom_simple(values): customsql = sqlpuzzle.customsql('"age" = "age" + 1') values.set(customsql) assert str(values) == '"age" = "age" + 1'
def test_custom_in_column_with_as(tables): tables.set({sqlpuzzle.customsql('"custom"'): 'x'}) assert str(tables) == '"custom" AS "x"'
def test_custom_simple(where): customsql = sqlpuzzle.customsql('"custom" = "sql" OR "sql" = "custom"') where.where(customsql) assert str(where) == 'WHERE "custom" = "sql" OR "sql" = "custom"'
#!/usr/bin/env python # -*- coding: utf-8 -*- import sqlpuzzle avg = sqlpuzzle.customsql('AVG(`age`) AS "avgAge"') table = sqlpuzzle.customsql('`user` LEFT JOIN `country` ON `user`.`country_id`=`country`.`id`') where = sqlpuzzle.customsql('(`enable` = 1 OR `vip` = 1)') sql = sqlpuzzle.select('country.name', avg).from_(table) sql.where(where).where(planet='Earth') sql.group_by('user.country_id') print(sql) # # output: # (for better reading splited to more lines) # # SELECT `country`.`name`, AVG(`age`) AS "avgAge" # FROM `user` LEFT JOIN `country` ON `user`.`country_id`=`country`.`id` # WHERE (`enable` = 1 OR `vip` = 1) AND `planet` = 'Earth' # GROUP BY `user`.`country_id` # table = sqlpuzzle.customsql('`user`') set_ = sqlpuzzle.customsql('`age` = `age` + 1') sql = sqlpuzzle.update(table).set(set_).where(where) print(sql)
def test_compare_column_with_custom(self): custom = sqlpuzzle.customsql('custom') column = Column('column') self.assertFalse(column == custom) # Do not throw exception.
def setUp(self): super(CustomSqlTest, self).setUp() self.customsql = sqlpuzzle.customsql('"custom" = "sql" OR "sql" = "custom"')
def test_customsql_compare_to_str(): assert sqlpuzzle.customsql('avg(col)') == 'avg(col)' assert sqlpuzzle.customsql('avg(col)') == sqlpuzzle.customsql('avg(col)') assert sqlpuzzle.customsql('avg(col)') != 'foo'
def test_customsql_as_key_in_dict(): custom = sqlpuzzle.customsql('avg(col)') sql = sqlpuzzle.select({ custom: 'acol', }).from_('table') assert str(sql) == 'SELECT avg(col) AS "acol" FROM "table"'
#!/usr/bin/env python # -*- coding: utf-8 -*- import sqlpuzzle avg = sqlpuzzle.customsql('AVG(`age`) AS "avgAge"') table = sqlpuzzle.customsql( '`user` LEFT JOIN `country` ON `user`.`country_id`=`country`.`id`') where = sqlpuzzle.customsql('(`enable` = 1 OR `vip` = 1)') sql = sqlpuzzle.select('country.name', avg).from_(table) sql.where(where).where(planet='Earth') sql.group_by('user.country_id') print(sql) # # output: # (for better reading splited to more lines) # # SELECT `country`.`name`, AVG(`age`) AS "avgAge" # FROM `user` LEFT JOIN `country` ON `user`.`country_id`=`country`.`id` # WHERE (`enable` = 1 OR `vip` = 1) AND `planet` = 'Earth' # GROUP BY `user`.`country_id` # table = sqlpuzzle.customsql('`user`') set_ = sqlpuzzle.customsql('`age` = `age` + 1') sql = sqlpuzzle.update(table).set(set_).where(where) print(sql) # output:
def test_custom_one_column(columns): customsql = sqlpuzzle.customsql('AVG("custom") AS "x"') columns.columns(customsql) assert str(columns) == 'AVG("custom") AS "x"'