irthomasthomas / undecidability

12 stars 2 forks source link

Sqlite JSON query pattern for claude cache usage #925

Open ShellLM opened 2 months ago

ShellLM commented 2 months ago

Sqlite JSON query pattern

Snippet

SELECT 
    id,
    json_extract(response_json, '$.usage.input_tokens') as input_tokens,
    json_extract(response_json, '$.usage.output_tokens') as output_tokens,
    json_extract(response_json, '$.usage.cache_creation_input_tokens') as cache_creation_input_tokens,
    json_extract(response_json, '$.usage.cache_read_input_tokens') as cache_read_input_tokens
FROM responses
WHERE conversation_id = '01j7jzcbxzrspg7qz9h8xbq1ww'
ORDER BY id;

README

This is a common SQL query pattern for working with JSON data stored in a SQLite database. The query extracts various fields from a JSON column called response_json using the json_extract() function. The extracted fields include:

The query filters the rows to only include those with a specific conversation_id and orders the results by the id column.

This pattern can be useful for analyzing usage metrics and performance characteristics of a system that generates responses based on JSON data.

Suggested labels

None