Skip to content

[8559] Add analytics commands#1

Open
fred-paragraph wants to merge 1 commit intomainfrom
par-8559-analytics
Open

[8559] Add analytics commands#1
fred-paragraph wants to merge 1 commit intomainfrom
par-8559-analytics

Conversation

@fred-paragraph
Copy link
Copy Markdown

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).

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).
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
return fs.readFileSync(opts.file, "utf-8");
return await fs.promises.readFile(opts.file, "utf-8");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant