Skip to content

Commit

Permalink
feat: add @cache-discard-empty
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Apr 25, 2023
1 parent 8ae0e6b commit 6c89b2d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ const pool = await createPool('postgres://', {
}),
]
});
```

These are example queries:

```ts
// Caches the query results based on a combination of the query hash and the parameter value hash.
await connection.any(sql`
-- @cache-ttl 60
Expand All @@ -92,6 +96,18 @@ await connection.any(sql`
code_alpha_2 = ${countryCode}
`);

// Does not cache the result when query produces no results.
await connection.any(sql`
-- @cache-ttl 60
-- @cache-discard-empty true
SELECT
id,
code_alpha_2
FROM country
WHERE
code_alpha_2 = ${countryCode}
`);

// Caches the query results based only on the parameter value hash.
await connection.any(sql`
-- @cache-ttl 60
Expand Down

0 comments on commit 6c89b2d

Please sign in to comment.