Make sure values can be appended to an array and that we can concatenate two arrays.
(self)
| 132 | |
| 133 | @engines_skip("sqlite") |
| 134 | def test_cat(self): |
| 135 | """ |
| 136 | Make sure values can be appended to an array and that we can |
| 137 | concatenate two arrays. |
| 138 | """ |
| 139 | MyTable(value=[5]).save().run_sync() |
| 140 | |
| 141 | MyTable.update( |
| 142 | {MyTable.value: MyTable.value.cat([6])}, force=True |
| 143 | ).run_sync() |
| 144 | |
| 145 | self.assertEqual( |
| 146 | MyTable.select(MyTable.value).run_sync(), |
| 147 | [{"value": [5, 6]}], |
| 148 | ) |
| 149 | |
| 150 | # Try plus symbol - add array to the end |
| 151 | |
| 152 | MyTable.update( |
| 153 | {MyTable.value: MyTable.value + [7]}, force=True |
| 154 | ).run_sync() |
| 155 | |
| 156 | self.assertEqual( |
| 157 | MyTable.select(MyTable.value).run_sync(), |
| 158 | [{"value": [5, 6, 7]}], |
| 159 | ) |
| 160 | |
| 161 | # Add array to the start |
| 162 | |
| 163 | MyTable.update( |
| 164 | {MyTable.value: [4] + MyTable.value}, force=True |
| 165 | ).run_sync() |
| 166 | |
| 167 | self.assertEqual( |
| 168 | MyTable.select(MyTable.value).run_sync(), |
| 169 | [{"value": [4, 5, 6, 7]}], |
| 170 | ) |
| 171 | |
| 172 | # Add array to the start and end |
| 173 | MyTable.update( |
| 174 | {MyTable.value: [3] + MyTable.value + [8]}, force=True |
| 175 | ).run_sync() |
| 176 | |
| 177 | self.assertEqual( |
| 178 | MyTable.select(MyTable.value).run_sync(), |
| 179 | [{"value": [3, 4, 5, 6, 7, 8]}], |
| 180 | ) |
| 181 | |
| 182 | @sqlite_only |
| 183 | def test_cat_sqlite(self): |