tengine:api

This is an old revision of the document!


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

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": ""
}

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": ""
}
Enter your comment. Wiki syntax is allowed:
 
  • tengine/api.1654735755.txt.gz
  • Last modified: 2022/06/09 00:49
  • by twinny