提交 20b6de4c 编写于 作者: M Matias Romeo

Add complex type example to simpledb

上级 7420f0db
......@@ -23,11 +23,25 @@
}
},
{
"name": "KeyValuePair",
"name": "KeyValue1",
"fields": {
"key": "String",
"value": "String"
}
},
{
"name": "ComplexType",
"fields": {
"name": "String",
"age": "UInt64"
}
},
{
"name": "KeyValue2",
"fields": {
"key": "String",
"value": "ComplexType"
}
}
],
"actions": [
......@@ -36,8 +50,8 @@
"type": "record1"
},
{
"action": "insertalpha",
"type": "KeyValuePair"
"action": "insertkv1",
"type": "KeyValue1"
},
{
"action": "insert2",
......@@ -46,6 +60,10 @@
{
"action": "insert3",
"type": "record3"
},
{
"action": "insertkv2",
"type": "KeyValue2"
}
],
"tables": [
......@@ -89,9 +107,20 @@
]
},
{
"table": "record1alpha",
"type": "KeyValuePair",
"indextype": "i64",
"table": "keyvalue1",
"type": "KeyValue1",
"indextype": "str",
"keynames": [
"key"
],
"keytypes": [
"String"
]
},
{
"table": "keyvalue2",
"type": "KeyValue2",
"indextype": "str",
"keynames": [
"key"
],
......
......@@ -14,12 +14,30 @@ extern "C" {
str[str_len] = x;
}
//void printhex( char* data, uint32_t datalen );
void apply( uint64_t code, uint64_t action ) {
if( code == N(simpledb) ) {
if( action == N(insertalpha) ) {
if( action == N(insertkv1) ) {
// eosc push message simpledb insertkv1 '{"key":"a", "value":"aa"}' -S simpledb
// eosc get table simpledb simpledb keyvalue1
char tmp[512];
auto len = readMessage(tmp, 512);
printhex(tmp, len);
char *ptr = tmp;
uint32_t key_len = (uint32_t)*ptr; ptr+=1;
char* key = ptr; ptr+=key_len;
hack_printstr(key, key_len);
char *str = ptr;
hack_printstr(str+1, *str);
uint32_t err = store_str( N(simpledb), N(keyvalue1), key, key_len, str, ((uint32_t)*str)+1);
} else if( action == N(insertkv2) ) {
// eosc push message simpledb insertkv2 '{"key":"a", "value":{"name":"aaa", "age":10}}' -S simpledb
// eosc get table simpledb simpledb keyvalue2
char tmp[512];
auto len = readMessage(tmp, 512);
......@@ -28,17 +46,16 @@ extern "C" {
char *ptr = tmp;
uint32_t key_len = (uint32_t)*ptr; ptr+=1;
char* key = ptr; ptr+=key_len;
char* key = ptr; ptr+=key_len;
hack_printstr(key, key_len);
char value_len = (uint32_t)*ptr; ptr+=1;
char* value = ptr; ptr+=value_len;
char* complex_data = ptr;
uint32_t complex_data_len = len-(key_len+1);
hack_printstr(value, value_len);
uint32_t err = store_str( N(simpledb), N(keyvalue2), key, key_len, complex_data, complex_data_len );
store_str( N(simpledb), N(record1alpha), key, key_len, value, value_len );
} else if( action == N(insert1) ) {
} else if( action == N(insert1) ) {
record1 tmp;
readMessage(&tmp, sizeof(tmp));
store_i64( N(simpledb), N(record1), &tmp, sizeof(tmp) );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册