Esempio n. 1
0
def test_construct_query():
    """Test converter construct query."""
    new_query, params_order_list = query.construct_asyncpg_query(
        '''SELECT * FROM some_table WHERE id=:id AND some_field_1=:some_field_1 AND some_field_2=:some_field_2;'''
    )

    expected_new_query = '''SELECT * FROM some_table WHERE id=$1 AND some_field_1=$2 AND some_field_2=$3;'''
    assert new_query == expected_new_query
    assert params_order_list == ['id', 'some_field_1', 'some_field_2']
Esempio n. 2
0
 def _prepare_asyncpg_parameters(
     self, query: str, args: typing.Any,
     converter: query_module.QueryParamsConverter
 ) -> typing.Tuple[str, typing.List]:
     """Prepare high-level query and arguments to underlying asyncpg
     backend."""
     converted_query, params_order_list = query_module.construct_asyncpg_query(
         query)
     return converted_query, converter.prepare_asyncpg_args(
         args, params_order_list)
Esempio n. 3
0
 async def named_prepare(
     self,
     query: str,
     *,
     timeout: typing.Optional[float] = None
 ) -> prepared_statement.PreparedStatementX:
     """Extended version of `prepare` with support of the named
     parameters."""
     converted_query, params_order_list = query_module.construct_asyncpg_query(
         query)
     self._check_open()
     stmt = await self._get_statement(converted_query,
                                      timeout,
                                      named=True,
                                      use_cache=False)
     return prepared_statement.PreparedStatementX(self, converted_query,
                                                  stmt, query,
                                                  params_order_list)