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

Immutable queries? #71

Open
cassiozen opened this issue Jan 10, 2018 · 5 comments
Open

Immutable queries? #71

cassiozen opened this issue Jan 10, 2018 · 5 comments

Comments

@cassiozen
Copy link

Currently query.append mutates the original query, which makes cumbersome to reuse a base query in multiple places.

For example, this will not work - Every time the route handler gets called, a new WHERE segment will be appended to the original baseQuery:

const baseQuery = SQL`SELECT * FROM books`;

app.get("/", (req, res) => {
  const query = baseQuery.append(SQL` WHERE id = ${req.params.id}`);
  // Some response
});

Is there any immutable way of appending?

@felixfbecker
Copy link
Owner

No, the idea was to always use queries inline for readability.

@cassiozen
Copy link
Author

cassiozen commented Jan 10, 2018

Would you consider adding such a feature, under a different method name? (PR #72)

@slavik-m
Copy link

slavik-m commented Mar 18, 2018

@cassiozen +1
I need it!

@migueloller
Copy link

No, the idea was to always use queries inline for readability.

That seems like a very bad excuse. When building a data access layer it is very common to share queries, especially CTEs. Adding something like #72 also doesn't remove the ability to use queries inline.

@samholmes
Copy link

I suggest .concat() as a method name.

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

5 participants