Skip to content

Commit d5786d9

Browse files
authored
feat(cli): setup live-queries (#1208)
Adds CLI command `yarn cedar setup live-queries` to configure Postgres LISTEN/NOTIFY-based live query invalidation. Creates database triggers that send notifications on table changes, and a Node.js listener that invalidates live query cache keys.
1 parent 265a232 commit d5786d9

File tree

5 files changed

+630
-0
lines changed

5 files changed

+630
-0
lines changed

packages/cli/src/commands/setup.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import * as setupI18n from './setup/i18n/i18n.js'
1919
// @ts-expect-error - Types not available for JS files
2020
import * as setupJobs from './setup/jobs/jobs.js'
2121
// @ts-expect-error - Types not available for JS files
22+
import * as setupLiveQueries from './setup/live-queries/liveQueries.js'
23+
// @ts-expect-error - Types not available for JS files
2224
import * as setupMailer from './setup/mailer/mailer.js'
2325
import * as setupMiddleware from './setup/middleware/middleware.js'
2426
import * as setupMonitoring from './setup/monitoring/monitoring.js'
@@ -50,6 +52,7 @@ export const builder = (yargs: Argv) =>
5052
.command(setupGraphql)
5153
.command(setupI18n)
5254
.command(setupJobs)
55+
.command(setupLiveQueries)
5356
.command(setupMailer)
5457
// @ts-expect-error - Yargs TS types aren't very good
5558
.command(setupMiddleware)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { recordTelemetryAttributes } from '@cedarjs/cli-helpers'
2+
3+
export const command = 'live-queries'
4+
5+
export const description =
6+
'Setup live query invalidation with Postgres notifications'
7+
8+
export function builder(yargs) {
9+
yargs
10+
.option('force', {
11+
alias: 'f',
12+
default: false,
13+
description: 'Overwrite existing configuration',
14+
type: 'boolean',
15+
})
16+
.option('verbose', {
17+
alias: 'v',
18+
default: false,
19+
description: 'Print more logs',
20+
type: 'boolean',
21+
})
22+
}
23+
24+
export async function handler(options) {
25+
recordTelemetryAttributes({
26+
command: 'setup live-queries',
27+
force: options.force,
28+
verbose: options.verbose,
29+
})
30+
31+
const { handler } = await import('./liveQueriesHandler.js')
32+
return handler(options)
33+
}

0 commit comments

Comments
 (0)