Skip to content

Instantly share code, notes, and snippets.

@muratgozel
Last active October 6, 2021 23:02
Show Gist options
  • Save muratgozel/d764bab633bd1a77d8a499c91af2690e to your computer and use it in GitHub Desktop.
Save muratgozel/d764bab633bd1a77d8a499c91af2690e to your computer and use it in GitHub Desktop.
// filtering something by its lifetime with slonik
const filterByLifetimeQuery = sql`
select id
from eventlog
where
code=${code} and
payload=${sql.json(payload)} and
created_at + interval '1 second' * ${parseInt(ctx.threshold)} > now()
`
// remove properties from jsonb field
const updateFieldQuery = sql`
update methods
set
credentials = credentials - '{password,salt}'::text[],
status='ACTIVE'
where id=${method.id}
`
// get timestamp for a future date
const tokenLife = '3 hours'
const willExpireAtQuery = sql`
SELECT to_timestamp(${Date.now()/1000}) + ${tokenLife}::interval as date;
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment