-
Notifications
You must be signed in to change notification settings - Fork 2
/
GJDataStore.hx
82 lines (55 loc) · 2.13 KB
/
GJDataStore.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Copyright (c) 2019 Charles Griffiths
*/
package gjCloud;
class GJDataStore
{
static var fetchDir:String = "/data-store/";
static var removeDir:String = "/data-store/remove/";
static var setDir:String = "/data-store/set/";
static var updateDir:String = "/data-store/update/";
static var getkeysDir:String = "/data-store/get-keys/";
static public function fetch( key:String ):GJTransaction
{
return new GJTransaction( fetchDir ).addGameID().addArg( "key", key );
}
static public function fetchUserData( key:String ):GJTransaction
{
return fetch( key ).addUserName().addUserToken();
}
static public function remove( key:String ):GJTransaction
{
return new GJTransaction( removeDir ).addGameID().addArg( "key", key );
}
static public function removeUserData( key:String ):GJTransaction
{
return remove( key ).addUserName().addUserToken();
}
static public function set( key:String, value:String ):GJTransaction
{
return new GJTransaction( setDir ).addGameID().addArg( "key", key ).addArg( "data", value );
}
static public function setUserData( key:String, value:String ):GJTransaction
{
return set( key, value ).addUserName().addUserToken();
}
static var operations = [ "add", "subtract", "multiply", "divide", "append", "prepend" ];
static public function update( key:String, op:String, value:String ):GJTransaction
{
if (-1 == operations.indexOf( op )) return set( key, value );
return new GJTransaction( updateDir ).addGameID().addArg( "key", key ).addArg( "operation", op ).addArg( "value", value );
}
static public function updateUserData( key:String, op:String, value:String ):GJTransaction
{
return update( key, op, value ).addUserName().addUserToken();
}
static public function getKeys( ?pattern:String=null )
{
if ("*" == pattern) pattern = null;
return new GJTransaction( getkeysDir ).addGameID().addArg( "pattern", pattern );
}
static public function getUserKeys( ?pattern:String=null )
{
return getKeys( pattern ).addUserName().addUserToken();
}
}