6
6
will have to look into schema objects for more complete serialization.
7
7
"""
8
8
from unittest import main , IsolatedAsyncioTestCase
9
+ from os import environ
9
10
10
11
from surrealdb .connections .async_ws import AsyncWsSurrealConnection
11
12
from surrealdb .data .types .record_id import RecordID
@@ -30,7 +31,7 @@ async def asyncSetUp(self):
30
31
await self .connection .use (namespace = self .namespace , database = self .database_name )
31
32
32
33
# Cleanup
33
- await self .connection .query ("DELETE person;" )
34
+ await self .connection .query ("REMOVE TABLE person;" )
34
35
35
36
async def test_none (self ):
36
37
schema = """
@@ -63,5 +64,45 @@ async def test_none(self):
63
64
await self .connection .query ("REMOVE TABLE person;" )
64
65
await self .connection .close ()
65
66
67
+ async def test_none_with_query (self ):
68
+ is_sdb21 = environ .get ("SURREALDB_VERSION" , "v2.1.4" ).startswith ("v2.1." )
69
+ schema = """
70
+ DEFINE TABLE person SCHEMAFULL TYPE NORMAL;
71
+ DEFINE FIELD name ON person TYPE string;
72
+ DEFINE FIELD nums ON person TYPE array<option<int>>;
73
+ """
74
+ await self .connection .query (schema )
75
+ outcome = await self .connection .query (
76
+ "UPSERT person MERGE {id: $id, name: $name, nums: $nums}" ,
77
+ {"id" : [1 ,2 ], "name" : "John" , "nums" : [None ]}
78
+ )
79
+ record_check = RecordID (table_name = "person" , identifier = [1 , 2 ])
80
+ self .assertEqual (1 , len (outcome ))
81
+ self .assertEqual (record_check , outcome [0 ]["id" ])
82
+ self .assertEqual ("John" , outcome [0 ]["name" ])
83
+ if is_sdb21 :
84
+ self .assertEqual ([], outcome [0 ].get ("nums" ))
85
+ else :
86
+ self .assertEqual ([None ], outcome [0 ].get ("nums" ))
87
+
88
+ outcome = await self .connection .query (
89
+ "UPSERT person MERGE {id: $id, name: $name, nums: $nums}" ,
90
+ {"id" : [3 ,4 ], "name" : "Dave" , "nums" : [None ]}
91
+ )
92
+ record_check = RecordID (table_name = "person" , identifier = [3 , 4 ])
93
+ self .assertEqual (1 , len (outcome ))
94
+ self .assertEqual (record_check , outcome [0 ]["id" ])
95
+ self .assertEqual ("Dave" , outcome [0 ]["name" ])
96
+ if is_sdb21 :
97
+ self .assertEqual ([], outcome [0 ].get ("nums" ))
98
+ else :
99
+ self .assertEqual ([None ], outcome [0 ].get ("nums" ))
100
+
101
+ outcome = await self .connection .query ("SELECT * FROM person" )
102
+ self .assertEqual (2 , len (outcome ))
103
+
104
+ await self .connection .query ("REMOVE TABLE person;" )
105
+ await self .connection .close ()
106
+
66
107
if __name__ == "__main__" :
67
108
main ()
0 commit comments