1
1
# Copyright (c) Microsoft Corporation. All rights reserved.
2
2
# Licensed under the MIT License.
3
-
3
+ import abc
4
4
import collections
5
5
import json
6
6
7
- from . import _abc
7
+
8
+ class BaseSqlRow (abc .ABC ):
9
+
10
+ @classmethod
11
+ @abc .abstractmethod
12
+ def from_json (cls , json_data : str ) -> 'BaseSqlRow' :
13
+ raise NotImplementedError
14
+
15
+ @classmethod
16
+ @abc .abstractmethod
17
+ def from_dict (cls , dct : dict ) -> 'BaseSqlRow' :
18
+ raise NotImplementedError
19
+
20
+ @abc .abstractmethod
21
+ def __getitem__ (self , key ):
22
+ raise NotImplementedError
23
+
24
+ @abc .abstractmethod
25
+ def __setitem__ (self , key , value ):
26
+ raise NotImplementedError
27
+
28
+ @abc .abstractmethod
29
+ def to_json (self ) -> str :
30
+ raise NotImplementedError
31
+
32
+
33
+ class BaseSqlRowList (abc .ABC ):
34
+ pass
8
35
9
36
10
- class SqlRow (_abc . SqlRow , collections .UserDict ):
37
+ class SqlRow (BaseSqlRow , collections .UserDict ):
11
38
"""A SQL Row.
12
39
13
40
SqlRow objects are ''UserDict'' subclasses and behave like dicts.
14
41
"""
15
42
16
43
@classmethod
17
- def from_json (cls , json_data : str ) -> 'SqlRow ' :
44
+ def from_json (cls , json_data : str ) -> 'BaseSqlRow ' :
18
45
"""Create a SqlRow from a JSON string."""
19
46
return cls .from_dict (json .loads (json_data ))
20
47
21
48
@classmethod
22
- def from_dict (cls , dct : dict ) -> 'SqlRow ' :
49
+ def from_dict (cls , dct : dict ) -> 'BaseSqlRow ' :
23
50
"""Create a SqlRow from a dict object"""
24
51
return cls ({k : v for k , v in dct .items ()})
25
52
@@ -39,6 +66,6 @@ def __repr__(self) -> str:
39
66
)
40
67
41
68
42
- class SqlRowList (_abc . SqlRowList , collections .UserList ):
69
+ class SqlRowList (BaseSqlRowList , collections .UserList ):
43
70
"A ''UserList'' subclass containing a list of :class:'~SqlRow' objects"
44
71
pass
0 commit comments