@@ -36,7 +36,7 @@ In this example, we use the complex form of the function to make an
3636authenticated POST request, with custom request headers and a custom request body.
3737
3838We use SQLite' ' s json functions to build the request body.
39- See [the list of SQL databases and their JSON functions](/blog.sql?post=JSON%20in%20SQL%3A%20A%20Comprehensive%20Guide) for
39+ See [the list of SQL databases and their JSON functions](/blog.sql?post=JSON%20in%20SQL%3A%20A%20Comprehensive%20Guide) for
4040more information on how to build JSON objects in your database.
4141
4242```sql
@@ -94,7 +94,22 @@ The fetch function accepts either a URL string, or a JSON object with the follow
9494If the request fails, this function throws an error, that will be displayed to the user.
9595The response headers are not available for inspection.
9696
97- If you need to handle errors or inspect the response headers, use [`sqlpage.fetch_with_meta`](?function=fetch_with_meta).
97+ ## Conditional data fetching
98+
99+ Since v0.40, `sqlpage.fetch(null)` returns null instead of throwing an error.
100+ This makes it easier to conditionnally query an API:
101+
102+ ```sql
103+ set current_field_value = (select field from my_table where id = 1);
104+ set target_url = nullif(' ' http://example.com/api/field/1' ' , null); -- null if the field is currently null in the db
105+ set api_value = sqlpage.fetch($target_url); -- no http request made if the field is not null in the db
106+ update my_table set field = $api_value where id = 1 and $api_value is not null; -- update the field only if it was not present before
107+ ```
108+
109+ ## Advanced usage
110+
111+ If you need to handle errors or inspect the response headers or the status code,
112+ use [`sqlpage.fetch_with_meta`](?function=fetch_with_meta).
98113'
99114 );
100115INSERT INTO sqlpage_function_parameters (
0 commit comments