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

Have the database return JSON directly(?) #3

Open
patdx opened this issue Dec 29, 2022 · 2 comments
Open

Have the database return JSON directly(?) #3

patdx opened this issue Dec 29, 2022 · 2 comments

Comments

@patdx
Copy link
Owner

patdx commented Dec 29, 2022

Probably we can do something like this:

https://www.freecodecamp.org/news/stop-calling-postgrest-magic-8f3e1d5e5dd1/amp/

@patdx patdx changed the title get the db to return json directly Have the database return JSON directly(?) Jan 23, 2023
@patdx
Copy link
Owner Author

patdx commented Apr 11, 2023

Here is a more complicated example of json query + nesting in postgres: https://twitter.com/dosco/status/1250886122974130182?s=20

Also here is my attempt at multiple unrelated subqueries with one json query:

https://sqlime.org/#deta:y08kvtwlu1h2

select
  json_object(
    'expenses',
    (
      select
        json_group_array(json_object('year', year, 'month', month, 'income', income))
      from
        (
          select
            *
          from
            expenses
          limit
            3
        )
    ),
    'employees',
    (
      select
        json_group_array(json_object('name', name, 'city', city))
      from
        (
          select
            *
          from
            employees
          limit
            2
        )
    )
  ) as json_result

@patdx
Copy link
Owner Author

patdx commented Apr 11, 2023

I created a mini online tool to help generate/experiment with these kinds of queries:

https://github.com/patdx/sqlite-query-tool
https://sqlite-query-tool.pages.dev/

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

No branches or pull requests

1 participant