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

Add examples #18

Open
2 of 3 tasks
orangemug opened this issue Jul 5, 2016 · 4 comments
Open
2 of 3 tasks

Add examples #18

orangemug opened this issue Jul 5, 2016 · 4 comments
Assignees
Milestone

Comments

@orangemug
Copy link
Owner

orangemug commented Jul 5, 2016

Our only examples currently live in ./test and README.md we should put some more complete examples into an ./examples directory

These would show our current use cases, especially with regard to

  • Composing SQL via CTE
  • Toggling of features via the ternary switch
  • Example of a parse error

I suggest we also make a sqlite database in order to properly show these in operation via knex.

@orangemug
Copy link
Owner Author

@oliverbrooks this might help with use cases for #13

@orangemug orangemug added this to the v0.9.0 milestone Jul 6, 2016
@orangemug orangemug self-assigned this Jul 6, 2016
@oliverbrooks
Copy link
Contributor

One example of a conditional join hack

  {?disablefishFilter, "LEFT JOIN", "INNER JOIN"}
    "fish" ON
      (
        {?disablefishFilter} = false
        AND
        "fish"."foodId" = "food"."id"
      )

This will inner join and filter if disableFishFilter is false.
It will left join nothing if disableFishFilter is true.

This is useful if you need to do a join to filter down results but you don't want the weight of the join all the time.

@orangemug
Copy link
Owner Author

@oliverbrooks so I thought I'd have a go at getting a pattern working for the above.

So I think you're trying to always join to a table and then switch to only return rows which join to that table.

I believe the below does this, also it's ANSI SQL (at least I think) and can be prepared and hence optimised ahead of time

SELECT
  *
FROM
  "users"
  LEFT OUTER JOIN "friends" ON (
    "friends"."fromId" = "users"."id"
  )
WHERE
  COALESCE("friends"."id", {?filterOnFriends})

@orangemug
Copy link
Owner Author

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

No branches or pull requests

2 participants