ESC

    Query

    The query endpoint allows to execute queries in the databases. Using the GET method, the query is executed in the database closest to the user’s region, thanks to the LiteFS proxy. Using the POST method, the query is executed in the primary database.

    POST

    The query endpoint allows to execute a query in the primary database.

    POST /_/query
    

    Headers

    NameTypeDescriptionRequired
    AuthorizationstringThe bearer token to connect to the server.true

    Body

    NameTypeDescriptionRequired
    db_namestringThe database to use.true
    querystringThe query to execute.true
    paramsobject | arrayThe params to use in the query.false

    The params object should use kyes with the format “:AAA”, “$AAA”, or “@AAA” that serve as placeholders for values that are bound to the parameters at a later time.

    Example:

    {
      "db_name": "example.sql",
      "query": "SELECT * FROM example WHERE id = :id",
      "params": {
        ":id": 1
      }
    }
    

    In the case of the array, the values are bound to the parameters based on the order of the array.

    Example:

    {
      "db_name": "example.sql",
      "query": "SELECT * FROM example WHERE id = ?",
      "params": [1]
    }
    

    GET

    By using the GET method, data can be retrieved with less latency from the database closest to the user’s region, thanks to the LiteFS proxy.

    GET /_/query?db_name=<DB_NAME>&query=<QUERY>&params=<PARAMS>
    

    Headers

    NameTypeDescriptionRequired
    AuthorizationstringThe bearer token to connect to the server.true

    Query String

    NameTypeFormatDescriptionRequired
    db_namestring-The database to use.true
    querystringURL EncodedThe SELECT query.true
    paramsobject | arrayURL EncodedThe params to use in the query.false

    Example:

    GET /_/query?db_name=example.sql&query=SELECT%20*%20FROM%20example%20WHERE%20id%20%3D%20%3F&params=%5B1%5D