Skip to content

Instantly share code, notes, and snippets.

@acro5piano
Created November 15, 2024 10:04
Show Gist options
  • Save acro5piano/d3d540d286a0e5d02dd462cbccea023f to your computer and use it in GitHub Desktop.
Save acro5piano/d3d540d286a0e5d02dd462cbccea023f to your computer and use it in GitHub Desktop.
Bringing PRQL into TypeScript
prql
.query()
.from('invoices')
.derive({
transaction_fee: 0.8,
income: 'total - transaction_fee',
})
.filter('income', '>', 5)
.filter('invoice_date', '>=', '@2010-01-16')
.group('customer_id', {
aggregate: {
sum_income: 'sum income',
ct: 'count customer_id',
},
})
.join('c', 'customers (==customer_id)')
.derive('name', f`{c.last_name}, {c.first_name}`)
.derive('db_version', s`version()`)
.select('c.customer_id', 'name', 'sum_income', 'ct', 'db_version')
.sort('-sum_income')
.take(1, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment