Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make key scopes visible to SQL #440

Merged
merged 2 commits into from
Jun 12, 2024
Merged

Make key scopes visible to SQL #440

merged 2 commits into from
Jun 12, 2024

Conversation

bgaidioz
Copy link
Collaborator

@bgaidioz bgaidioz commented Jun 6, 2024

This is implemented using a postgres temporary table that is created/cleaned at startup of each query, and filled when scopes are provided. An example query that is then possible:

SELECT
    CASE WHEN 'dev' IN (SELECT * FROM scopes) THEN trip_id END AS trip_id,
    departure_date,
    arrival_date
FROM example.trips

When "dev" is in the scopes:

[
  {
    "trip_id": 0,
    "departure_date": "2016-02-27",
    "arrival_date": "2016-03-06"
  },
  {
    "trip_id": 1,
    "departure_date": "2016-04-10",
    "arrival_date": "2016-04-17"
  },
  {
    "trip_id": 2,
    "departure_date": "2016-05-22",
    "arrival_date": "2016-05-29"
  },
  {
    "trip_id": 3,
    "departure_date": "2023-01-01",
    "arrival_date": "2023-01-01"
  }
]

When it's not:

[
  {
    "trip_id": null,
    "departure_date": "2016-02-27",
    "arrival_date": "2016-03-06"
  },
  {
    "trip_id": null,
    "departure_date": "2016-04-10",
    "arrival_date": "2016-04-17"
  },
  {
    "trip_id": null,
    "departure_date": "2016-05-22",
    "arrival_date": "2016-05-29"
  },
  {
    "trip_id": null,
    "departure_date": "2023-01-01",
    "arrival_date": "2023-01-01"
  }
]

Another one:

SELECT 'DEV' IN (SELECT * FROM scopes) AS isDev,
       'ADMIN' IN (SELECT token FROM scopes) AS isAdmin

when only ADMIN is listed:

[{"isdev":false,"isadmin":true}]

Copy link
Contributor

@torcato torcato left a comment

Choose a reason for hiding this comment

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

LGTM

@bgaidioz bgaidioz merged commit a57eb5c into main Jun 12, 2024
7 checks passed
@bgaidioz bgaidioz deleted the sql-scopes branch June 12, 2024 07:19
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.

2 participants