Conversation
Adds `paragraph analytics query` and `paragraph analytics schema` so users can run read-only SQL against their publication's analytics (open rates, CTR, subscriber counts, post views, engagement, etc.) from the terminal. The query command accepts SQL via positional, --sql, --file, or piped stdin; renders results as a table with dynamic headers matching the SQL projection order, or returns the raw SDK response shape in --json mode for jq pipelines. Schema lists available tables and columns sorted by table_name + column_name. Both commands use the existing `handleError` / `requireApiKey` helpers, and go through @paragraph-com/sdk v2.0.2 (bumped from 2.0.1).
There was a problem hiding this comment.
Code Review
This pull request introduces a new analytics command to the CLI, enabling users to execute read-only SQL queries against their publication's analytics and inspect the available schema. The changes include a dependency update for the @paragraph-com/sdk, new service and command implementations, and corresponding test coverage. One improvement was suggested to use asynchronous file reading within the resolveSql function to ensure the event loop remains unblocked during execution.
| `File not found: "${opts.file}". Check the path, or pass the SQL inline via --sql or as a positional argument.` | ||
| ); | ||
| } | ||
| return fs.readFileSync(opts.file, "utf-8"); |
There was a problem hiding this comment.
Since resolveSql is an async function and already awaits readStdin(), it is better to use the promise-based fs.promises.readFile instead of the synchronous fs.readFileSync. This maintains consistency and avoids blocking the event loop in an asynchronous context.
| return fs.readFileSync(opts.file, "utf-8"); | |
| return await fs.promises.readFile(opts.file, "utf-8"); |
Adds
paragraph analytics queryandparagraph analytics schemaso users can run read-only SQL against their publication's analytics (open rates, CTR, subscriber counts, post views, engagement, etc.) from the terminal.The query command accepts SQL via positional, --sql, --file, or piped stdin; renders results as a table with dynamic headers matching the SQL projection order, or returns the raw SDK response shape in --json mode for jq pipelines. Schema lists available tables and columns sorted by table_name + column_name.
Both commands use the existing
handleError/requireApiKeyhelpers, and go through @paragraph-com/sdk v2.0.2 (bumped from 2.0.1).