Queries

Queries are a way to interact with data

You could execute queries via

  • rest resources i.e GET /products
  • admin panel elements
  • javascript code nesting them any way you want

Parameters

Parameters are used to pass external data into application

Sample query

{
  "type": "sql-select",
  "id": "get-products",
  "connection": "sample-database-connection",
  "query": "SELECT * FROM `product` where appConfigId = :configId (id IN(:id) or name like %:name%)",
  "resultType": "list",
  "public": false,
  "permissions": [
    "admin",
    "user"
  ],
  "params": [
    {
      "name": "name",
      "list": false,
      "type": "string",
      "required": false
    },
    {
      "name": "configId",
      "serverValue": "$.config.someToken",
      "type": "string",
      "required": false
    },
    {
      "name": "notUsedDataFromCurrentUser",
      "serverValue": "$.user.otherData.test",
      "type": "string",
      "required": false
    },
    {
      "name": "id",
      "type": "int",
      "required": true,
      "list": true,
      "default": [0]
    }
  ]
}

public - determine if you can call this query from admin panel or not. You could create insert-order-item query that should be accessible only from internal javascript logic

serverValue - this option can be used to extract data from configuration or current user using special variables $.user or $.config

permissions - roles that are allowed to execute particular query

Each query MUST contains params section

{
  "someToken": "thisIsSomeRandomToken"
}
[
  {
    "login": "demo",
    "password": "demo",
    "permissions": ["admin"],
    "id": 1,
    "otherData": {
      "test": 1
    }
  }
]

Using query in rest endpoint

You could create rest endpoint to call get-products query by creating one file

{
  "path": "/products/{id}",
  "methods": [
    "POST"
  ],
  "query": "get-products",
  "authorized": false
}
{
  "name": "exampleUsername"
}

As the result you will get json response with list of products that are matching this sql value

Last modified April 16, 2024: content fix (a2d9b96)