Skip to content

FEATURE | Add support for LIKE operator in WHERE dicts #39

@raindrum

Description

@raindrum

✅ Describe your idea or issue

SQLite allows for a LIKE operator that performs wildcard searches, but as far as I can tell, it's not accessible in SQLLEX, at least not when criteria are given as a dict, like this:

jerrys = db['users'].select(ALL, WHERE={'name': ['LIKE', 'Jerry%']})

or this:

jerrys = db['users'].select(ALL, WHERE={'name': ['%', 'Jerry%']})

Would you be willing to add support for this?

✅ Additional context

It's possible to enable support, at least in this specific use-case, by adding "LIKE" to the recognized operators listed here, and patching it to add spaces when necessary, like so:

                    if len(values) > 1 and values[0] in [
                        "<", "<<", "<=",
                        ">=", ">>", ">",
                        "=", "==", "!=",
                        "<>", "LIKE",
                    ]:
                        operator = values.pop(0)
                        if operator == 'LIKE':
                           operator = ' LIKE '

But that's a pretty hacky solution, and I don't know how it interacts with the other ways to write WHERE statements, so I figured I would file an issue instead of a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions