def test_append_two_items(self):
     builder = QueryBuilder()
     builder.set_schema.add("SET search_path TO %s,public;", ["hg38"])
     builder.query.add("select 1 from table where value = %s;", [5])
     query, params = builder.get_query_and_params()
     expected_sql = "SET search_path TO %s,public;\nselect 1 from table where value = %s;"
     expected_params = ["hg38", 5]
     self.assertEqual(expected_sql, query)
     self.assertEqual(expected_params, params)
 def test_append_two_items(self):
     builder = QueryBuilder()
     builder.set_schema.add("SET search_path TO %s,public;", ["hg38"])
     builder.query.add("select 1 from table where value = %s;", [5])
     query, params = builder.get_query_and_params()
     expected_sql = "SET search_path TO %s,public;\nselect 1 from table where value = %s;"
     expected_params = ["hg38", 5]
     self.assertEqual(expected_sql, query)
     self.assertEqual(expected_params, params)
Пример #3
0
 def get_query_and_params(self):
     builder = QueryBuilder()
     builder.set_schema.add_part(set_search_path(self.schema))
     if self.count:
         builder.query.add_part(begin_count())
     builder.query.add_parts(self.main_query_parts())
     if self.count:
         builder.query.add_part(end_count())
     return builder.get_query_and_params()
 def get_query_and_params(self):
     builder = QueryBuilder()
     builder.set_schema.add_part(set_search_path(self.schema))
     if self.count:
         builder.query.add_part(begin_count())
     builder.query.add_parts(self.main_query_parts())
     if self.count:
         builder.query.add_part(end_count())
     return builder.get_query_and_params()
 def get_query_and_params(self):
     builder = QueryBuilder()
     builder.set_schema.add_part(set_search_path(self.schema))
     builder.query.add_parts([
         items_not_in_gene_list(self.custom_list_id,
                                self.custom_list_filter,
                                self.custom_gene_name_type)
     ])
     return builder.get_query_and_params()
    def test_all_items(self):
        builder = QueryBuilder()
        builder.set_schema.add_part(set_search_path("hg38"))
        builder.with_clause.add("WITH regional_sales AS (SELECT amount AS total_sales FROM orders)", [])
        builder.query.add("SELECT * from orders where total_sales > %s;", [200])
        query, params = builder.get_query_and_params()
        expected_sql = """SET search_path TO %s,public;
WITH regional_sales AS (SELECT amount AS total_sales FROM orders)
SELECT * from orders where total_sales > %s;"""
        expected_params = ["hg38", 200]
        self.assertEqual(expected_sql, query)
        self.assertEqual(expected_params, params)
    def test_all_items(self):
        builder = QueryBuilder()
        builder.set_schema.add_part(set_search_path("hg38"))
        builder.with_clause.add(
            "WITH regional_sales AS (SELECT amount AS total_sales FROM orders)",
            [])
        builder.query.add("SELECT * from orders where total_sales > %s;",
                          [200])
        query, params = builder.get_query_and_params()
        expected_sql = """SET search_path TO %s,public;
WITH regional_sales AS (SELECT amount AS total_sales FROM orders)
SELECT * from orders where total_sales > %s;"""
        expected_params = ["hg38", 200]
        self.assertEqual(expected_sql, query)
        self.assertEqual(expected_params, params)
 def test_starts_blank(self):
     builder = QueryBuilder()
     query, params = builder.get_query_and_params()
     self.assertEqual("", query)
     self.assertEqual([], params)
 def test_simple_query(self):
     builder = QueryBuilder()
     builder.query.add("select 1 from table where value = %s;", [5])
     query, params = builder.get_query_and_params()
     self.assertEqual("select 1 from table where value = %s;", query)
     self.assertEqual([5], params)
 def test_starts_blank(self):
     builder = QueryBuilder()
     query, params = builder.get_query_and_params()
     self.assertEqual("", query)
     self.assertEqual([], params)
 def test_simple_query(self):
     builder = QueryBuilder()
     builder.query.add("select 1 from table where value = %s;", [5])
     query, params = builder.get_query_and_params()
     self.assertEqual("select 1 from table where value = %s;", query)
     self.assertEqual([5], params)