Skip to content

apisexample

Laurent MICHEL edited this page Nov 9, 2020 · 4 revisions

Dummy Example

Basic Example: 2 tables

Let's consider the following schema:

table1(key1) joined with table2(key2)

Message returned by getObjectMap

{
  "succes": {
    "status": "OK",
    "object_map": {
      "table2": {
        "schema": "public",
        "description": "",
        "join_tables": {
          "table1": {
            "schema": "public",
            "columns": [],
            "constraints": "",
            "from": "key1",
            "target": "key2"
          }
        }
      }
    }
  }
}

Message returned by getJoinedTables("table1")

{
  "status": "OK",
  "base_table": "table1",
  "joined_tables": [
    "table2"
  ]
}

Message returned by getRootQuery

{
  "status": "OK",
  "query": "SELECT TOP 100 public.table1.key1 FROM public.table1"
}

Get attributes of table1: getTableAttributeHandlers

Let's suppose that table1 has one column named col1

{
  "status": "OK",
  "attribute_handlers": [{"name": "col1", "db_name":  "col1", "type"; "int", "ucd": "", "utype": "", "description": "", "range": ""}]
}

Set a Constraint on table1

Let's suppose we want col1 > 0

API call: setTableConstraint("table1", "col1 > 0")

Message returned getRootQuery

{
  "status": "OK",
  "query": "SELECT TOP 100 public.table1.key1 FROM public.table1 WHERE public.table1.col1 > 0"
}

Get attribute of table2 (getTableAttributeHandlers)

Let's suppose that table2 has one column named col2

{
  "status": "OK",
  "attribute_handlers": [{"name": "col2", "db_name":  "col2", "type": "int", "ucd": "", "utype": "", "description": "", "range": ""}]
}

Set a Constraint on table2

Let's suppose we want col2 = 99

API call: setTableConstraint("table2", "col2 = 99")

Message returned getRootQuery

{
  "status": "OK",
  "query": "SELECT TOP 100 public.table1.key1 FROM public.table1 "
           "JOIN public.table2 ON public.table2.key2 = public.table1 "
           "WHERE public.table1.col1 > 0 AND public.table2.col2 = 99"
}

Run the query on the root table with getQueryIds

Let's suppose that only one row (key1 = 12345) of table1 matches the query.

{
   "status": "ok", 
   "root_ids": [12345]}

Run the query the joined table with getTableQueryIds

API call getTableQueryIds("table2", "12345")

Let's suppose that 2 rows (key1 = 111 and key2 = 222) of table2 match the query.

{
  "status": "ok", 
  "root_ids": [111, 222]}

The query actually run is

SELECT TOP 100 public.table2.key2 FROM  public.table2 WHERE public.table2.key2 = 12345