Table of Contents

API Documentation

( I accidentally nuked all documentation so It's currently being rebuilt! May be some missing parts of old/invalid details )

This page provides details on how you can use TEngine via API calls

CreateTable

Used to create a new table. If the table already exists, it will error out. You must provide a partition key but a sort key is optional. You can also add additional indexes which also require a partition key and an optional sort key. Currently it's not possible to add indexes to an existing table.

Arguments

{
  tablename=STRING,
  pk=STRING
  sk=STRING  (optional)
 
  indexes={
    "string"={
      pk=STRING
      sk=STRING  (optional)
    }
  } (optional)
 
}

Return Format

{
  error=STRING
  success=BOOLEAN
}

Example Request

  temp.req = {};
 
  // Create a base table and two indexes
  // pk is mandatory, sk is optional
 
  temp.req.tablename = "player-test";
  temp.req.pk = "account";
  temp.req.sk = "sort";
 
  temp.req.indexes = {};
 
  temp.req.indexes.house_index = {};
  temp.req.indexes.house_index.pk = "housetype";
  temp.req.indexes.house_index.sk = "housesubtype";
 
  temp.req.indexes.location_index = {};
  temp.req.indexes.location_index.pk = "location";
 
  //create table
  temp.r = TEngine.createtable(temp.req);
  if (temp.r.error) {
    printf("[TEngine Error]: %s", temp.r.error);
  }

Example Return

{
   "success": 1,
   "error": ""
}

Get

Retrieve a single item from the table based on the provided partition and sort key (where specified). If the item does not exist, it will not fail but instead, return an empty array. Get requests can not be made on an index: use the Query instead.

Request Format

{
  tablename=STRING
  keys={
    "string"=STRING
  }
}

Return Format

{
  error=STRING
  success=BOOLEAN
  result=OBJECT
}

Example Request

  temp.req = {};
  temp.req.tablename = "player-test";
 
  temp.req.keys.account = "Jane";
  temp.req.keys.sort = "housedata";
 
  temp.r = TEngine.get(temp.req);
  if (temp.r.error) {
    printf("[TEngine Error]: %s", temp.r.error);
  }

Example Return

{
   "success": 1,
   "error": "",
   "result": {"sample":"data"}
}

Query

Queries can be made either on the base table or an index. It must be made on a partition key but the sort key is optional, even if the table is configured with a sort key. When the table/index only has a partition key, the single item with the matching partition key will be returned. If the table/index is configured with a partition key and sort key, it can provide every single item which matches the partition key. You can provide the sort key to return items matching the partiyion key and sort key (note that in an index, this can be multiple items)

You can also opt to provide conditions which will be tested on the sort key. Each condition will be tested and the item will only be returned if true to all conditions.

Conditions include

Consider this table with the following items:

...
{pk: "item1", sk: "sort_19"}
{pk: "item1", sk: "sort_20"}
{pk: "item1", sk: "sort_21"}
{pk: "item1", sk: "sort_22"}
{pk: "item1", sk: "sort_23"}
{pk: "item1", sk: "sort_24"}
...

Example queries:

Argument Format

{
  tablename=STRING
  keys={
    "string"=STRING
  }
  sortorder="ASC"/"DESC" - set the sort order to be returned. ASC by default. Note this is sorted by string value: not numeric
  startat=INTEGER - if set, skips the number of items configured here before potentially read and returning items. Useful for pagination
  limit=INTEGER - if set, limits the number of read/returned items. Useful for pagination
  conditions=ARRAY of ARRAYS e.g. {  {"begins_with", "sort_"}, {">", "sort_5"}, {"<", "sort_15"} }
}

Return Format

{
  result=[KEYS,DATA]
  success=BOOLEAN
  readcount=INTEGER  - how many items were read and returned (after limit, startat, conditions)
  foundcount=INTEGER - how many items were intiially found
  error=STRING
}

Example Request

tbd

Example Return

tbd

Put / Update

Both methods use the same underlying method but the difference is:
Put: will either replace an existing item with the request or create a new item if it does not exist
Update: will either update an existing item with the request or create a new item if it does not exist

If the item matches any indexes in the table, the item will automatically be added to the index. If the item was previously in the index but no longer matches, it will be removed.

Argument Format

{
  tablename=STRING
  keys = {
    "string"=STRING
  }
  data = {
    "string"=STRING
    "string"={}
    "string"=[]
  }
}

Return Format

{
  error=STRING
  success=BOOLEAN
}

Example Request

  temp.req = {};
  temp.req.keys.account = "Jane";
  temp.req.keys.sort = "housedata";
 
  temp.req.data.housetype="house1";
  temp.req.data.housesubtype="a1";
  temp.req.data.randomvariable="just because";
  temp.req.data.location="Elsewhere";
  temp.req.tablename="player-test";
  temp.r = TEngine.put(temp.req);
  if (temp.r.error) {
    printf("[TEngine Error]: %s", temp.r.error);
  }

Return Example

{
   "success": 1,
   "error": ""
}

DeleteItem

Will delete the specified item from the table. If the table has indexes and the item was written to one or more indexes, it will also be deleted from the index

Argument Format

{
  tablename=STRING
  keys={
    "string"=STRING
  }
}

Return Format

{
  error=STRING
  success=BOOLEAN
}

Example Request

  temp.req = {};
  temp.req.tablename="player-test";
  temp.req.keys.account = "Jane";
  temp.req.keys.sort = "housedata";
  temp.r = TEngine.deleteitem(temp.req);
  if (temp.r.error) {
    printf("[TEngine Error]: %s", temp.r.error);
  }

Example Return

{
   "success": 1,
   "error": ""
}

ListTables

tbd

DescribeTable

tbd