Docs + example of canned SQL query using || concatenation

Closes #321
This commit is contained in:
Simon Willison 2018-06-20 21:54:36 -07:00
commit 3683a6b626
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
3 changed files with 55 additions and 4 deletions

View file

@ -143,7 +143,14 @@ METADATA = {
},
},
'queries': {
'pragma_cache_size': 'PRAGMA cache_size;'
'pragma_cache_size': 'PRAGMA cache_size;',
'neighborhood_search': '''
select neighborhood, facet_cities.name, state
from facetable
join facet_cities on facetable.city_id = facet_cities.id
where neighborhood like '%' || :text || '%'
order by neighborhood;
'''
}
},
}

View file

@ -330,6 +330,20 @@ def test_custom_sql(app_client):
assert not data['truncated']
def test_canned_query_with_named_parameter(app_client):
response = app_client.get(
"/fixtures/neighborhood_search.json?text=town"
)
assert [
["Corktown", "Detroit", "MI"],
["Downtown", "Los Angeles", "CA"],
["Downtown", "Detroit", "MI"],
["Greektown", "Detroit", "MI"],
["Koreatown", "Los Angeles", "CA"],
["Mexicantown", "Detroit", "MI"],
] == response.json["rows"]
def test_sql_time_limit(app_client_shorter_time_limit):
response = app_client_shorter_time_limit.get(
'/fixtures.json?sql=select+sleep(0.5)'