Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Full support for query parameters #45

Merged
merged 2 commits into from
Jan 18, 2023
Merged

Full support for query parameters #45

merged 2 commits into from
Jan 18, 2023

Conversation

MarinPostma
Copy link
Collaborator

@MarinPostma MarinPostma commented Jan 17, 2023

This PR introduces full support for query parameters. Both positional and named parameters are supported.

The supported syntax is the same as the one described in https://www.sqlite.org/c3ref/bind_blob.html.
Unbound parameters are interpreted as NULL.

HTTP query parameters

Parameters can also be bound in http request. The syntax is quite flexible:

  • Request without params:
{
    "statements": ["select * from users where name = 'adhoc'"]
}

or (syntaxes can be mixed in the same array):

{
    "statements": [{"q": "select * from users where name = 'adhoc'"}]
}
  • Request with params:
  • positional:
{
    "statements": [
        {"q": "select * from users where name = ?", "params": ["adhoc"]},
        {"q": "select * from users where name = ?1", "params": ["adhoc"]},
        {"q": "select * from users where name = $1", "params": ["adhoc"]}
    ]
}
  • named:
{
    "statements": [
        {"q": "select * from users where name = $name", "params": {"name": "adhoc"}},
        {"q": "select * from users where name = :name", "params": {"name": "adhoc"}},
        {"q": "select * from users where name = @name", "params": {"name": "adhoc"}},
        {"q": "select * from users where name = $1", "params": {"name": "adhoc"}}, # object is order sensitive
        {"q": "select * from users where name = ?", "params": {"name": "adhoc"}},
    ]
}

Handling of BLOB

BLOBS are handled as base64 encoded string (standards alphabet, no padding), and are nested into an object for disambiguition:

{
    "statements": [
    {"q": "select * from users where name = $name", "params": {"name": {"blob": "984HG3e"}}},
                                                                  # some b64 blob --^
    ]
}

@MarinPostma MarinPostma force-pushed the query-params branch 2 times, most recently from 8be1a03 to fc17e65 Compare January 17, 2023 16:30
@MarinPostma
Copy link
Collaborator Author

bors try

bors bot added a commit that referenced this pull request Jan 17, 2023
@bors
Copy link
Contributor

bors bot commented Jan 17, 2023

try

Build succeeded:

@MarinPostma MarinPostma marked this pull request as ready for review January 17, 2023 18:33
@penberg
Copy link
Contributor

penberg commented Jan 18, 2023

@MarinPostma Do the positional ones work with SQLite? If not, we probably shouldn't do it because we want to preserve the ability to use the JavaScript driver, for example, with both SQLite (local development) and HTTP (production).

@penberg
Copy link
Contributor

penberg commented Jan 18, 2023

bors merge

@bors
Copy link
Contributor

bors bot commented Jan 18, 2023

Build succeeded:

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

Successfully merging this pull request may close these issues.

2 participants