question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to support dynamic queries?

i.e.

Given type Read = SQL<"""Select * from MyTable"""> and let query = ["Id", 5L; "Scope", "Demo"]

Is there a way to intercept Read and “add or update the where clause” instead of having to create a different type for each scenario - type ReadById, type ReadByScope, type ReadByIdAndScope?

I’m work a large number of fields and currently experimenting with how to make the queries with large optional fields a bit dynamic.

Any tips, tricks, workaround?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
piastecommented, Aug 3, 2017

This is a classic question that comes up when you start using parameterized queries, with a classic answer to go with it.

select *
from MyTable
where
    (@id    is null or @id    = id)
and (@scope is null or @scope = scope)
-- etc.

I haven’t tried it yet, but apparently Rezoom.SQL is smart enough to figure out if you care about nullability or not, so the above query will take in an int option and a string option parameters, becaus it compares them with null. Simply pass in None for every parameter that isn’t used in the query.

0reactions
rkosafocommented, Aug 4, 2017

Tried it and it works as expected. Will push it a bit more through various scenarios. Closing this in favour of #7.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introduction to dynamic queries
Dynamic queries refer to queries that are built dynamically by Drupal rather than provided as an explicit query string.
Read more >
Dynamic Queries | Database API
Dynamic queries in Drupal 8 Database API. ... Conditions filter the query result to matching records (WHERE clause).
Read more >
mysql - What is dynamic SQL?
To most databases, every SQL query is "dynamic" meaning that it is a program that is interpreted by the query optimiser given the...
Read more >
Dynamic SQL in SQL Server
Dynamic SQL is the SQL statement that is constructed and executed at runtime based on input parameters passed. Let us go through some...
Read more >
Dynamic SQL
Dynamic SQL is a programming technique that could be used to write SQL queries during runtime. Dynamic SQL could be used to create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found