background image

Custom queries

Run your own read-only SQL SELECT against a project. See the Custom queries guide for the syntax and limits.

Background and examples: Custom queries

Run a query

POST /v1/data/query

Runs a custom SELECT query.

Parameters

project uuid query required

The GUID of the project.

Request body application/json

The query and the values of its parameters.

query string required

One SELECT statement, using table and field names as in the database designer. Use @name for parameters.

parameters object

The values of the @parameters in the query, by name.

Responses

  • 200 Returns the result of the query.
  • 400 If the query is not allowed or not valid (every problem is listed with its line and column), took too long or failed.
  • 401 If the user is not signed in.
  • 403 If the tier doesn't include custom queries or a table can't be read by the caller.
  • 429 If too many custom queries are already running for the project.

Request

curl -X POST 'https://api.stellards.io/v1/data/query?project=PROJECT_ID' \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "query": "select c.name, count(o.id) as orders from customers c left join orders o on o.customer = c.id where c.city = @city group by c.name",
    "parameters": {
      "city": "Ghent"
    }
  }'

Response 200

{
  "messages": [],
  "isSuccess": true,
  "data": {
    "columns": [
      {
        "name": "Customers",
        "type": "NVarChar(255)"
      }
    ],
    "rows": [
      {}
    ],
    "count": 1,
    "truncated": false,
    "durationMs": 38
  }
}

Check a query

POST /v1/data/query/validate

Checks a custom SELECT query without running it, the way the console's editor does while you type. Field names are checked as well. It is not counted against the request limit or kept in the query log.

Parameters

project uuid query required

The GUID of the project.

Request body application/json

The query and the names of the parameters it may use.

query string required
parameters string[]

Responses

  • 200 Returns the problems, if any.
  • 401 If the caller is not signed in.
  • 403 If the tier doesn't include custom queries.

Request

curl -X POST 'https://api.stellards.io/v1/data/query/validate?project=PROJECT_ID' \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "query": "select c.name from customers c where c.city = @city",
    "parameters": [
      "city"
    ]
  }'

Response 200

{
  "messages": [],
  "isSuccess": true,
  "data": {
    "valid": false,
    "problems": []
  }
}

List the names a query can use

GET /v1/data/query/schema

The names a custom query can use: the tables the caller can read with their fields, and the allowed functions.

Parameters

project uuid query required

The GUID of the project.

Responses

  • 200 Returns the tables and functions.
  • 401 If the caller is not signed in.
  • 403 If the tier doesn't include custom queries.

Request

curl -X GET 'https://api.stellards.io/v1/data/query/schema?project=PROJECT_ID' \
  -H 'Authorization: Bearer ACCESS_TOKEN'

Response 200

{
  "messages": [],
  "isSuccess": true,
  "data": {
    "tables": [
      4
    ],
    "functions": [
      "string"
    ]
  }
}

Run a query Path-style route

POST /project/{project}/query

Runs a custom SELECT query.

Parameters

project uuid path required

The GUID of the project. Provided as a route parameter.

Request body application/json

The query and the values of its parameters.

query string required

One SELECT statement, using table and field names as in the database designer. Use @name for parameters.

parameters object

The values of the @parameters in the query, by name.

Responses

  • 200 Returns the result of the query.
  • 400 If the query is not allowed or not valid (every problem is listed with its line and column), took too long or failed.
  • 401 If the caller is not signed in and has no valid access token.
  • 403 If the tier doesn't include custom queries or a table can't be read by the caller.
  • 429 If too many custom queries are already running for the project.

Request

curl -X POST 'https://api.stellards.io/project/PROJECT_ID/query' \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "query": "select c.name, count(o.id) as orders from customers c left join orders o on o.customer = c.id where c.city = @city group by c.name",
    "parameters": {
      "city": "Ghent"
    }
  }'

Response 200

{
  "messages": [],
  "isSuccess": true,
  "data": {
    "columns": [
      {
        "name": "Customers",
        "type": "NVarChar(255)"
      }
    ],
    "rows": [
      {}
    ],
    "count": 1,
    "truncated": false,
    "durationMs": 38
  }
}

List the names a query can use Path-style route

GET /project/{project}/query/schema

The names a custom query can use: the tables the caller can read with their fields, and the allowed functions.

Parameters

project uuid path required

The GUID of the project. Provided as a route parameter.

Responses

  • 200 Returns the tables and functions.
  • 401 If the caller is not signed in and has no valid access token.
  • 403 If the tier doesn't include custom queries.

Request

curl -X GET 'https://api.stellards.io/project/PROJECT_ID/query/schema' \
  -H 'Authorization: Bearer ACCESS_TOKEN'

Response 200

{
  "messages": [],
  "isSuccess": true,
  "data": {
    "tables": [
      4
    ],
    "functions": [
      "string"
    ]
  }
}

Check a query Path-style route

POST /project/{project}/query/validate

Checks a custom SELECT query without running it, the way the console's editor does while you type. Field names are checked as well. It is not counted against the request limit or kept in the query log.

Parameters

project uuid path required

The GUID of the project. Provided as a route parameter.

Request body application/json

The query and the names of the parameters it may use.

query string required
parameters string[]

Responses

  • 200 Returns the problems, if any.
  • 401 If the caller is not signed in and has no valid access token.
  • 403 If the tier doesn't include custom queries.

Request

curl -X POST 'https://api.stellards.io/project/PROJECT_ID/query/validate' \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "query": "select c.name from customers c where c.city = @city",
    "parameters": [
      "city"
    ]
  }'

Response 200

{
  "messages": [],
  "isSuccess": true,
  "data": {
    "valid": false,
    "problems": []
  }
}