MrSwitch / MrSwitch/dare

Conditional OR

Open
#21 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

[zube]: Backlog
Dominant language
TypeScript
Stars
0
Forks
0
Avg merge
28m
Merged PRs (30d)
3

Description

There is no way to conditionally join a value across two fields. Aka search multiple fields for a value, e.g. (title, body):word, to create the sql WHERE (title = 'word' OR body='word') or indeed fields across many tables WHERE (a.title=? OR meta.fulltext = ?).

Proposal
Support additional syntax where the value of a filter prop is an Array of Objects
e.g....

const filter = {
    '$arbitary': [
         // Local Scope
         {
             title: ?
         },
         // Nested...
         {
             meta: {
                  fulltext: ?
             }
         }
    ]
}

In the above case an Array is passed into the filters, in order to create an cond1 [...OR condN] SQL conditions block.

The Array is given an $arbitrary key prop, whose definition has no meaning and would be ignored. It is simply there to mix conditional OR with regular AND.

The parser currently accepts an array to mean a list of possible values e.g. field IN (1,2,3).
The parser would need to be adapted to decide whether any or all of these values are objects and therefore to apply the CONDITIONAL OR rule.

For example in the below the values are a mix...

const filter = {
    'field': [
         'a',
        'b', 
         {
             alternative: {
                  alternativeField: 'c'
             }
         }
    ]
}

The parser would understand the first and second values to be a definition of the field and the third to define it's own table field and value. But the query would return anything that matches any of the three. i.e. WHERE (field IN ('a', 'b') OR alternative.alternativeField = 'c'). Note that the field is redundant in the third option. And the filter could have also have been written...

const filter = {
    '$something': [
         {
              field: ['a', 'b']
         },
         {
             alternative: {
                  alternativeField: 'c'
             }
         }
    ]
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the TypeScript filter parser and the existing array handling for IN conditions. Define how arrays of objects and mixed scalar/object values should map to grouped OR conditions while preserving regular AND filters, then verify the generated SQL for the examples in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql, typescript
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.