Requests
Last updated
Last updated
A request is a JSON structure that is passed via a POST HTTP call to ws4sqlite, using the port specified when the server application.
First and foremost, the database we connect to is specified in the URL of the POST call. It is something like this:
That db2
part is the database ID, and must match the id
of a database, defined in the .
Second, and very important, the request must contain the header:
This is a JSON that exemplifies all possible elements of a request.
Let's go through it.
Line 2; string; map
or list
(case insensitive); default map
Since 0.16
This is the format for result sets, in the response. By default, it returns an (ordered) map with the results, but it can return a list of them, too.
Lines 3-6; object
Line 7; list of objects; mandatory
Must be not empty. The list of the queries or statements that will actually be performed on the database, with their own parameters.
Lines 9, 12, 16, 20; string; mandatory one of query
or statement
The actual SQL to execute.
Specifying it as query
means that a result set is expected (typically, SELECT
queries or queries with a RETURNING
clause).
Specifying a statement
will not return a result set, but a count of affected records.
Line 24; string; mandatory as the above
A query
or a statement
(see above) can consist of a reference to a Stored Query. They are prepended by a #
. An error will occour if the S.Q. with an ID equal to the part after the #
was not defined for this database.
Lines 13, 21; object
Since 0.16, there are two forms of parameters:
Positional, as in Line 13; in the SQL you'll want to use the ?
form for placeholders, and then specify the parameters, in order, in a list;
Named, as in line 21; in the SQL use :name
or @name
, and specify an object with their value. May help reduce clutter.
What happens if some parameter values aren't defined in the values
object, in its named form? If there are less parameter values than expected, it will give an error. If they are correct in number, but some parameter names don't match, the missing parameters will be assigned a value of null
.
Lines 25..28; list of objects
Only for statement
s, more than one set of parameter values can be specified; the statement will be applied to them in a batch (by preparing the statement).
Line 29; Boolean
If is enabled in INLINE
mode, this object describes the credentials. See the .
They will be run in a transaction, and the transaction will be committed only if all the queries that are not marked as noFail
(see the ) do successfully complete.
See the .
If the query needs to be parametrized, named parameters can be defined in the statement using SQLite (e.g. :id
or @id
, or ?
), and the proper values for them must be specified here. You can specify values that do not match a parameter; they'll be ignored.
When a query/statement fails, by default the whole transaction is rolled back and a response with a single error is returned (the first one for the whole transaction). Specifying this flag, the error will be reported for that statement, but the execution will continue and eventually be committed. See the for more details.