37
37
38
38
39
39
class SqlAlchemyDictTypeTest (TestCase ):
40
+
40
41
def setUp (self ):
41
42
self .engine = sa .create_engine ('crate://' )
42
- metadata = sa . MetaData ()
43
- self . mytable = sa .Table ( 'mytable' ,
44
- metadata ,
43
+ # FIXME: Deprecated with SA20.
44
+ metadata = sa .MetaData ( bind = self . engine )
45
+ self . mytable = sa . Table ( 'mytable' , metadata ,
45
46
sa .Column ('name' , sa .String ),
46
- sa .Column ('data' , Craty ),
47
- autoload_with = self .engine )
47
+ sa .Column ('data' , Craty ))
48
48
49
49
def assertSQL (self , expected_str , actual_expr ):
50
50
self .assertEqual (expected_str , str (actual_expr ).replace ('\n ' , '' ))
51
51
52
52
def test_select_with_dict_column (self ):
53
53
mytable = self .mytable
54
54
self .assertSQL (
55
- "SELECT mytable.data[:data_1 ] AS anon_1 FROM mytable" ,
55
+ "SELECT mytable.data['x' ] AS anon_1 FROM mytable" ,
56
56
select (mytable .c .data ['x' ])
57
57
)
58
58
@@ -61,7 +61,7 @@ def test_select_with_dict_column_where_clause(self):
61
61
s = select (mytable .c .data ).\
62
62
where (mytable .c .data ['x' ] == 1 )
63
63
self .assertSQL (
64
- "SELECT mytable.data FROM mytable WHERE mytable.data[:data_1 ] = :param_1 " ,
64
+ "SELECT mytable.data FROM mytable WHERE mytable.data['x' ] = ? " ,
65
65
s
66
66
)
67
67
@@ -71,7 +71,7 @@ def test_select_with_dict_column_nested_where(self):
71
71
s = s .where (mytable .c .data ['x' ]['y' ] == 1 )
72
72
self .assertSQL (
73
73
"SELECT mytable.name FROM mytable " +
74
- "WHERE mytable.data[:data_1][:param_1 ] = :param_2 " ,
74
+ "WHERE mytable.data['x']['y' ] = ? " ,
75
75
s
76
76
)
77
77
@@ -80,7 +80,7 @@ def test_select_with_dict_column_where_clause_gt(self):
80
80
s = select (mytable .c .data ).\
81
81
where (mytable .c .data ['x' ] > 1 )
82
82
self .assertSQL (
83
- "SELECT mytable.data FROM mytable WHERE mytable.data[:data_1 ] > :param_1 " ,
83
+ "SELECT mytable.data FROM mytable WHERE mytable.data['x' ] > ? " ,
84
84
s
85
85
)
86
86
@@ -90,18 +90,19 @@ def test_select_with_dict_column_where_clause_other_col(self):
90
90
s = s .where (mytable .c .data ['x' ] == mytable .c .name )
91
91
self .assertSQL (
92
92
"SELECT mytable.name FROM mytable " +
93
- "WHERE mytable.data[:data_1 ] = mytable.name" ,
93
+ "WHERE mytable.data['x' ] = mytable.name" ,
94
94
s
95
95
)
96
96
97
97
def test_update_with_dict_column (self ):
98
98
mytable = self .mytable
99
99
stmt = mytable .update ().\
100
100
where (mytable .c .name == 'Arthur Dent' ).\
101
- values ({mytable .c .data ['x' ]: "Trillian" })
102
-
101
+ values ({
102
+ "data['x']" : "Trillian"
103
+ })
103
104
self .assertSQL (
104
- "UPDATE mytable SET data[:data_1]=:param_1 WHERE mytable.name = :name_1 " ,
105
+ "UPDATE mytable SET data['x'] = ? WHERE mytable.name = ? " ,
105
106
stmt
106
107
)
107
108
0 commit comments