tengine:api

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tengine:api [2022/06/09 01:15] twinnytengine:api [2023/04/23 06:35] (current) twinny
Line 1: Line 1:
 ===== API Documentation ===== ===== 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 This page provides details on how you can use TEngine via API calls
Line 8: Line 10:
  
 === Arguments === === Arguments ===
 +
 <code javascript> <code javascript>
 { {
Line 13: Line 16:
   pk=STRING   pk=STRING
   sk=STRING  (optional)   sk=STRING  (optional)
-  +
   indexes={   indexes={
     "string"={     "string"={
Line 20: Line 23:
     }     }
   } (optional)   } (optional)
-   +
 } }
 +
 </code> </code>
  
 === Return Format === === Return Format ===
 +
 <code javascript> <code javascript>
 { {
Line 30: Line 35:
   success=BOOLEAN   success=BOOLEAN
 } }
 +
 </code> </code>
  
 === Example Request === === Example Request ===
 +
 <code javascript> <code javascript>
   temp.req = {};   temp.req = {};
- +
   // Create a base table and two indexes   // Create a base table and two indexes
   // pk is mandatory, sk is optional   // pk is mandatory, sk is optional
- +
   temp.req.tablename = "player-test";   temp.req.tablename = "player-test";
   temp.req.pk = "account";   temp.req.pk = "account";
   temp.req.sk = "sort";   temp.req.sk = "sort";
- +
   temp.req.indexes = {};   temp.req.indexes = {};
- +
   temp.req.indexes.house_index = {};   temp.req.indexes.house_index = {};
   temp.req.indexes.house_index.pk = "housetype";   temp.req.indexes.house_index.pk = "housetype";
   temp.req.indexes.house_index.sk = "housesubtype";   temp.req.indexes.house_index.sk = "housesubtype";
- +
   temp.req.indexes.location_index = {};   temp.req.indexes.location_index = {};
   temp.req.indexes.location_index.pk = "location";   temp.req.indexes.location_index.pk = "location";
-  + 
-  //create table +  //create table
   temp.r = TEngine.createtable(temp.req);   temp.r = TEngine.createtable(temp.req);
   if (temp.r.error) {   if (temp.r.error) {
     printf("[TEngine Error]: %s", temp.r.error);     printf("[TEngine Error]: %s", temp.r.error);
-  } +  } 
 </code> </code>
  
 === Example Return === === Example Return ===
 +
 <code javascript> <code javascript>
 { {
Line 65: Line 74:
    "error": ""    "error": ""
 } }
 +
 </code> </code>
  
Line 80: Line 90:
   }   }
 } }
 +
 </code> </code>
  
 === Return Format === === Return Format ===
 +
 <code javascript> <code javascript>
 { {
Line 89: Line 101:
   result=OBJECT   result=OBJECT
 } }
 +
 </code> </code>
  
 === Example Request === === Example Request ===
 +
 <code javascript> <code javascript>
   temp.req = {};   temp.req = {};
   temp.req.tablename = "player-test";   temp.req.tablename = "player-test";
- +
   temp.req.keys.account = "Jane";   temp.req.keys.account = "Jane";
   temp.req.keys.sort = "housedata";   temp.req.keys.sort = "housedata";
- +
   temp.r = TEngine.get(temp.req);   temp.r = TEngine.get(temp.req);
   if (temp.r.error) {   if (temp.r.error) {
     printf("[TEngine Error]: %s", temp.r.error);     printf("[TEngine Error]: %s", temp.r.error);
   }   }
 +
 </code> </code>
  
Line 113: Line 128:
    "result": {"sample":"data"}    "result": {"sample":"data"}
 } }
 +
 </code> </code>
  
Line 119: Line 135:
 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) 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. +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 Conditions include
-begins_with - the sort key begins with the provided string + 
-* > - the sort key is greater than the provided value (Note: compared as a string) +  * begins_with - the sort key begins with the provided string 
-* < - the sort key is less than the provided value (Note: compared as a string)+  * > - the sort key is greater than the provided value (Note: compared as a string) 
 +  * < - the sort key is less than the provided value (Note: compared as a string)
  
 Consider this table with the following items: Consider this table with the following items:
 +
 +<code>
 ... ...
 {pk: "item1", sk: "sort_19"} {pk: "item1", sk: "sort_19"}
Line 135: Line 154:
 {pk: "item1", sk: "sort_24"} {pk: "item1", sk: "sort_24"}
 ... ...
 +
 +</code>
  
 Example queries: Example queries:
  
-pk == item1 : will return all 6 items  +  * pk == item1 : will return all 6 items 
-pk == item1 and sk == "sort_20" : will return the single matching item+  pk == item1 and sk == "sort_20" : will return the single matching item
  
-pk == item1 and sk begins_with "sort_2" : will return the 5 items where sk starts with sort_2 +  * pk == item1 and sk begins_with "sort_2" : will return the 5 items where sk starts with sort_2 
-pk == item1 and sk > sort_23 : will return just sort_24 since it's the only item > 23+  pk == item1 and sk > sort_23 : will return just sort_24 since it's the only item > 23
  
 === Argument Format === === Argument Format ===
 +
 <code javascript> <code javascript>
 { {
Line 151: Line 173:
     "string"=STRING     "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"} }
 } }
 +
 </code> </code>
  
 +=== Return Format ===
 +
 +<code javascript>
 +{
 +  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
 +}
 +
 +</code>
 +
 +=== Example Request ===
 +
 +<code javascript>
 +tbd
 +
 +</code>
 +
 +=== Example Return ===
 +
 +<code javascript>
 +tbd
 +
 +</code>
  
 ==== Put / Update ==== ==== Put / Update ====
  
-Both methods use the same underlying method but the difference is: \\ +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
-**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. 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 === === Argument Format ===
Line 170: Line 220:
   tablename=STRING   tablename=STRING
   keys = {   keys = {
-    "string"=STRING +    "string"=STRING
   }   }
   data = {   data = {
Line 178: Line 228:
   }   }
 } }
 +
 </code> </code>
  
 === Return Format === === Return Format ===
 +
 <code javascript> <code javascript>
 { {
Line 186: Line 238:
   success=BOOLEAN   success=BOOLEAN
 } }
 +
 </code> </code>
  
 === Example Request === === Example Request ===
 +
 <code javascript> <code javascript>
   temp.req = {};   temp.req = {};
   temp.req.keys.account = "Jane";   temp.req.keys.account = "Jane";
   temp.req.keys.sort = "housedata";   temp.req.keys.sort = "housedata";
- +
   temp.req.data.housetype="house1";   temp.req.data.housetype="house1";
   temp.req.data.housesubtype="a1";   temp.req.data.housesubtype="a1";
Line 203: Line 257:
     printf("[TEngine Error]: %s", temp.r.error);     printf("[TEngine Error]: %s", temp.r.error);
   }   }
 +
 </code> </code>
  
Line 212: Line 267:
    "error": ""    "error": ""
 } }
 +
 </code> </code>
  
Line 219: Line 275:
  
 === Argument Format === === Argument Format ===
 +
 <code javascript> <code javascript>
 { {
Line 226: Line 283:
   }   }
 } }
 +
 </code> </code>
  
 === Return Format === === Return Format ===
 +
 <code javascript> <code javascript>
 { {
Line 234: Line 293:
   success=BOOLEAN   success=BOOLEAN
 } }
 +
 </code> </code>
  
 === Example Request === === Example Request ===
 +
 <code javascript> <code javascript>
   temp.req = {};   temp.req = {};
Line 246: Line 307:
     printf("[TEngine Error]: %s", temp.r.error);     printf("[TEngine Error]: %s", temp.r.error);
   }   }
 +
 </code> </code>
  
 === Example Return === === Example Return ===
 +
 <code javascript> <code javascript>
 { {
Line 254: Line 317:
    "error": ""    "error": ""
 } }
 +
 </code> </code>
 +
 +==== ListTables ====
 +
 +tbd
 +
 +==== DescribeTable ====
 +
 +tbd
 +
 +----
  
 ~~DISCUSSION~~ ~~DISCUSSION~~
 +
 +
  • tengine/api.1654737340.txt.gz
  • Last modified: 2022/06/09 01:15
  • by twinny