File tree Expand file tree Collapse file tree 3 files changed +78
-0
lines changed Expand file tree Collapse file tree 3 files changed +78
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+
3
+ Command Query ..
4
+
5
+ """
6
+ import json
7
+
8
+ from .command_base import CommandBase
9
+
10
+
11
+ class QueryCommand (CommandBase ):
12
+
13
+ def __init__ (self , sub_parser = None ):
14
+ self ._command_list = []
15
+ super ().__init__ ('query' , sub_parser )
16
+
17
+ def create_parser (self , sub_parser ):
18
+
19
+ parser = sub_parser .add_parser (
20
+ self ._name ,
21
+ description = 'call a convex query' ,
22
+ help = 'Call a convex query command'
23
+
24
+ )
25
+
26
+ parser .add_argument (
27
+ 'query' ,
28
+ help = 'query to perform'
29
+ )
30
+
31
+ parser .add_argument (
32
+ 'name_address' ,
33
+ nargs = '?' ,
34
+ help = 'account address or account name. Defaults: Address #1'
35
+ )
36
+
37
+ return parser
38
+
39
+ def execute (self , args , output ):
40
+ convex = self .load_convex (args .url )
41
+
42
+ if args .name_address :
43
+ info = self .resolve_to_name_address (args .name_address , output )
44
+ if not info :
45
+ return
46
+ address = info ['address' ]
47
+
48
+ address = 1
49
+ result = convex .query (args .query , address )
50
+ output .add_line (json .dumps (result ))
51
+ output .set_values (result )
Original file line number Diff line number Diff line change 11
11
12
12
13
13
from convex_api .tool .command .account_command import AccountCommand
14
+ from convex_api .tool .command .query_command import QueryCommand
14
15
from convex_api .tool .command .command_base import DEFAULT_CONVEX_URL
15
16
from convex_api .tool .output import Output
16
17
@@ -81,6 +82,7 @@ def convex_tool():
81
82
82
83
command_list = [
83
84
AccountCommand (command_parser ),
85
+ QueryCommand (command_parser )
84
86
]
85
87
86
88
args = parser .parse_args ()
Original file line number Diff line number Diff line change
1
+ """
2
+
3
+ Test Query
4
+
5
+ """
6
+ from unittest .mock import Mock
7
+
8
+ from convex_api .tool .command .query_command import QueryCommand
9
+ from convex_api .tool .output import Output
10
+
11
+
12
+
13
+ def test_query_command (convex_url ):
14
+ args = Mock ()
15
+
16
+ args .url = convex_url
17
+ args .query = '(address *registry*)'
18
+ args .name_address = None
19
+
20
+ command = QueryCommand ()
21
+ output = Output ()
22
+ command .execute (args , output )
23
+ assert (output .values ['value' ])
24
+
25
+
You can’t perform that action at this time.
0 commit comments