Skip to content

Conversation

@EspressoTrip-v2
Copy link
Contributor

@EspressoTrip-v2 EspressoTrip-v2 commented Nov 11, 2025

Added general connection analytics query for Mongo and Postgres report storage.

Query will return a paginated list of connections which can be filtered by:

  • user_id
  • client_id
  • date_range

Purpose: Ability to get more granular user/client specific connection data.

Bugfix:
report update UTC time for PostgresReportStorage

@changeset-bot
Copy link

changeset-bot bot commented Nov 11, 2025

🦋 Changeset detected

Latest commit: 05e1832

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@powersync/service-module-postgres-storage Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-core-tests Patch
@powersync/service-core Patch
@powersync/service-types Patch
@powersync/service-schema Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres Patch
@powersync/service-image Patch
@powersync/service-module-core Patch
test-client Patch
@powersync/lib-service-postgres Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@EspressoTrip-v2 EspressoTrip-v2 marked this pull request as ready for review November 11, 2025 11:55
Comment on lines +143 to +146
intermediateQuery +=
queryParams.length === 0
? ` WHERE connected_at >= $1 AND connected_at <= $2`
: ` AND connected_at >= $${queryParams.length + 1} AND connected_at <= $${queryParams.length + 2}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

This appears to add multiple WHERE clauses if both date_range and client_id/user_id is specified - will this work? Same for cursor below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It builds up the query based on the query parameter legth and the adds a and or where, I have added some tests to validate functionality. The query looks like this:
SELECT id, user_id, client_id, user_agent, sdk, jwt_exp::text AS jwt_exp, disconnected_at, connected_at::text AS connected_at, disconnected_at::text AS disconnected_at FROM connection_report_events WHERE client_id = $1 AND user_id = $2 AND connected_at >= $3 AND connected_at <= $4 ORDER BY connected_at DESC

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.

3 participants