{% ckan_extends %}

{% block custom %}
  {{ super() }}

  {% if examples %}
  {% call register_example('powershell', 'request_filter_custom') %}
<pre class="example-powershell"><code class="language-powershell"
>$json = @'
{
  "resource_id": "{{resource_id}}",
  "filters": {{ examples.text_column_filters_object | tojson(indent=2) | indent(2) }}
}
'@
$response = Invoke-RestMethod {{ h.url_for('api.action', logic_function='datastore_search', qualified=True) }}`
  -Method Post -Body $json -Headers @{"Authorization"="$API_TOKEN"}
$response.result.records</code></pre>
  {% endcall %}

  {% call register_example('powershell', 'request_sql_custom') %}
<pre class="example-powershell"><code class="language-powershell"
>$json = @'
{
  "sql": "SELECT * from \"{{resource_id}}\" WHERE {{ examples.text_column_name_sql }} LIKE 'jones'"
}
'@
$response = Invoke-RestMethod {{ h.url_for('api.action', logic_function='datastore_search_sql', qualified=True) }}`
  -Method Post -Body $json -Headers @{"Authorization"="$API_TOKEN"}
$response.result.records</code></pre>
  {% endcall %}

  {% call register_example('powershell', 'request_insert') %}
<pre class="example-powershell"><code class="language-powershell"
>$json = @'
{
  "resource_id": "{{resource_id}}",
  "method": "insert",
  "records": [
    {{ examples.insert_record_object | tojson(indent=2) | indent(4) }}
  ]
}
'@
$response = Invoke-RestMethod {{ h.url_for('api.action', logic_function='datastore_upsert', qualified=True) }}`
  -Method Post -Body $json -Headers @{"Authorization"="$API_TOKEN"}
$response.result.records</code></pre>
  {% endcall %}

  {% call register_example('powershell', 'request_update') %}
<pre class="example-powershell"><code class="language-powershell"
>$json = @'
{
  "resource_id": "{{resource_id}}",
  "method": "update",
  "records": [
    {{ examples.update_record_object | tojson(indent=2) | indent(4) }}
  ]
}
'@
$response = Invoke-RestMethod {{ h.url_for('api.action', logic_function='datastore_upsert', qualified=True) }}`
  -Method Post -Body $json -Headers @{"Authorization"="$API_TOKEN"}
$response.result.records</code></pre>
  {% endcall %}

{% call register_example('powershell', 'request_delete') %}
<pre class="example-powershell"><code class="language-powershell"
>$json = @'
{
  "resource_id": "{{resource_id}}",
  "filters": {{ examples.unique_filter_object | tojson(indent=2) | indent(2) }}
}
'@
$response = Invoke-RestMethod {{ h.url_for('api.action', logic_function='datastore_records_delete', qualified=True) }}`
  -Method Post -Body $json -Headers @{"Authorization"="$API_TOKEN"}
$response.result.records</code></pre>
  {% endcall %}
  {% endif %}
{% endblock %}
