... | ... |
@@ -196,101 +196,6 @@ my $binary; |
196 | 196 |
# Prepare table |
197 | 197 |
$dbi = DBIx::Custom->connect; |
198 | 198 |
|
199 |
-test 'dbi method from model'; |
|
200 |
-$dbi = MyDBI9->connect; |
|
201 |
-eval { $dbi->execute('drop table table1') }; |
|
202 |
-$dbi->execute($create_table1); |
|
203 |
-$dbi->setup_model; |
|
204 |
-$model = $dbi->model('table1'); |
|
205 |
-eval{$model->execute('select * from table1')}; |
|
206 |
-ok(!$@); |
|
207 |
- |
|
208 |
-test 'column table option'; |
|
209 |
-$dbi = MyDBI9->connect; |
|
210 |
-eval { $dbi->execute('drop table table1') }; |
|
211 |
-$dbi->execute($create_table1); |
|
212 |
-eval { $dbi->execute('drop table table2') }; |
|
213 |
-$dbi->execute($create_table2); |
|
214 |
-$dbi->setup_model; |
|
215 |
-$dbi->execute('insert into table1 (key1, key2) values (1, 2);'); |
|
216 |
-$dbi->execute('insert into table2 (key1, key3) values (1, 4);'); |
|
217 |
-$model = $dbi->model('table1'); |
|
218 |
-$result = $model->select( |
|
219 |
- column => [ |
|
220 |
- $model->column('table2', {alias => 'table2_alias'}) |
|
221 |
- ], |
|
222 |
- where => {'table2_alias.key3' => 4} |
|
223 |
-); |
|
224 |
-is_deeply($result->one, |
|
225 |
- {'table2_alias.key1' => 1, 'table2_alias.key3' => 4}); |
|
226 |
- |
|
227 |
-$dbi->separator('__'); |
|
228 |
-$result = $model->select( |
|
229 |
- column => [ |
|
230 |
- $model->column('table2', {alias => 'table2_alias'}) |
|
231 |
- ], |
|
232 |
- where => {'table2_alias.key3' => 4} |
|
233 |
-); |
|
234 |
-is_deeply($result->one, |
|
235 |
- {'table2_alias__key1' => 1, 'table2_alias__key3' => 4}); |
|
236 |
- |
|
237 |
-$dbi->separator('-'); |
|
238 |
-$result = $model->select( |
|
239 |
- column => [ |
|
240 |
- $model->column('table2', {alias => 'table2_alias'}) |
|
241 |
- ], |
|
242 |
- where => {'table2_alias.key3' => 4} |
|
243 |
-); |
|
244 |
-is_deeply($result->one, |
|
245 |
- {'table2_alias-key1' => 1, 'table2_alias-key3' => 4}); |
|
246 |
- |
|
247 |
-test 'create_model'; |
|
248 |
-$dbi = DBIx::Custom->connect; |
|
249 |
-eval { $dbi->execute('drop table table1') }; |
|
250 |
-eval { $dbi->execute('drop table table2') }; |
|
251 |
-$dbi->execute($create_table1); |
|
252 |
-$dbi->execute($create_table2); |
|
253 |
- |
|
254 |
-$dbi->create_model( |
|
255 |
- table => 'table1', |
|
256 |
- join => [ |
|
257 |
- 'left outer join table2 on table1.key1 = table2.key1' |
|
258 |
- ], |
|
259 |
- primary_key => ['key1'] |
|
260 |
-); |
|
261 |
-$model2 = $dbi->create_model( |
|
262 |
- table => 'table2' |
|
263 |
-); |
|
264 |
-$dbi->create_model( |
|
265 |
- table => 'table3', |
|
266 |
- filter => [ |
|
267 |
- key1 => {in => sub { uc $_[0] }} |
|
268 |
- ] |
|
269 |
-); |
|
270 |
-$dbi->setup_model; |
|
271 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
272 |
-$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3}); |
|
273 |
-$model = $dbi->model('table1'); |
|
274 |
-$result = $model->select( |
|
275 |
- column => [$model->mycolumn, $model->column('table2')], |
|
276 |
- where => {'table1.key1' => 1} |
|
277 |
-); |
|
278 |
-is_deeply($result->one, |
|
279 |
- {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3}); |
|
280 |
-is_deeply($model2->select->one, {key1 => 1, key3 => 3}); |
|
281 |
- |
|
282 |
-test 'model method'; |
|
283 |
-test 'create_model'; |
|
284 |
-$dbi = DBIx::Custom->connect; |
|
285 |
-eval { $dbi->execute('drop table table2') }; |
|
286 |
-$dbi->execute($create_table2); |
|
287 |
-$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3}); |
|
288 |
-$model = $dbi->create_model( |
|
289 |
- table => 'table2' |
|
290 |
-); |
|
291 |
-$model->method(foo => sub { shift->select(@_) }); |
|
292 |
-is_deeply($model->foo->one, {key1 => 1, key3 => 3}); |
|
293 |
- |
|
294 | 199 |
test 'merge_param'; |
295 | 200 |
$dbi = DBIx::Custom->new; |
296 | 201 |
$params = [ |
... | ... |
@@ -1236,6 +1141,101 @@ like($@, qr/unexpected "{"/, "error : 2"); |
1236 | 1141 |
|
1237 | 1142 |
|
1238 | 1143 |
### a little complex test |
1144 |
+test 'dbi method from model'; |
|
1145 |
+$dbi = MyDBI9->connect; |
|
1146 |
+eval { $dbi->execute('drop table table1') }; |
|
1147 |
+$dbi->execute($create_table1); |
|
1148 |
+$dbi->setup_model; |
|
1149 |
+$model = $dbi->model('table1'); |
|
1150 |
+eval{$model->execute('select * from table1')}; |
|
1151 |
+ok(!$@); |
|
1152 |
+ |
|
1153 |
+test 'column table option'; |
|
1154 |
+$dbi = MyDBI9->connect; |
|
1155 |
+eval { $dbi->execute('drop table table1') }; |
|
1156 |
+$dbi->execute($create_table1); |
|
1157 |
+eval { $dbi->execute('drop table table2') }; |
|
1158 |
+$dbi->execute($create_table2); |
|
1159 |
+$dbi->setup_model; |
|
1160 |
+$dbi->execute('insert into table1 (key1, key2) values (1, 2);'); |
|
1161 |
+$dbi->execute('insert into table2 (key1, key3) values (1, 4);'); |
|
1162 |
+$model = $dbi->model('table1'); |
|
1163 |
+$result = $model->select( |
|
1164 |
+ column => [ |
|
1165 |
+ $model->column('table2', {alias => 'table2_alias'}) |
|
1166 |
+ ], |
|
1167 |
+ where => {'table2_alias.key3' => 4} |
|
1168 |
+); |
|
1169 |
+is_deeply($result->one, |
|
1170 |
+ {'table2_alias.key1' => 1, 'table2_alias.key3' => 4}); |
|
1171 |
+ |
|
1172 |
+$dbi->separator('__'); |
|
1173 |
+$result = $model->select( |
|
1174 |
+ column => [ |
|
1175 |
+ $model->column('table2', {alias => 'table2_alias'}) |
|
1176 |
+ ], |
|
1177 |
+ where => {'table2_alias.key3' => 4} |
|
1178 |
+); |
|
1179 |
+is_deeply($result->one, |
|
1180 |
+ {'table2_alias__key1' => 1, 'table2_alias__key3' => 4}); |
|
1181 |
+ |
|
1182 |
+$dbi->separator('-'); |
|
1183 |
+$result = $model->select( |
|
1184 |
+ column => [ |
|
1185 |
+ $model->column('table2', {alias => 'table2_alias'}) |
|
1186 |
+ ], |
|
1187 |
+ where => {'table2_alias.key3' => 4} |
|
1188 |
+); |
|
1189 |
+is_deeply($result->one, |
|
1190 |
+ {'table2_alias-key1' => 1, 'table2_alias-key3' => 4}); |
|
1191 |
+ |
|
1192 |
+test 'create_model'; |
|
1193 |
+$dbi = DBIx::Custom->connect; |
|
1194 |
+eval { $dbi->execute('drop table table1') }; |
|
1195 |
+eval { $dbi->execute('drop table table2') }; |
|
1196 |
+$dbi->execute($create_table1); |
|
1197 |
+$dbi->execute($create_table2); |
|
1198 |
+ |
|
1199 |
+$dbi->create_model( |
|
1200 |
+ table => 'table1', |
|
1201 |
+ join => [ |
|
1202 |
+ 'left outer join table2 on table1.key1 = table2.key1' |
|
1203 |
+ ], |
|
1204 |
+ primary_key => ['key1'] |
|
1205 |
+); |
|
1206 |
+$model2 = $dbi->create_model( |
|
1207 |
+ table => 'table2' |
|
1208 |
+); |
|
1209 |
+$dbi->create_model( |
|
1210 |
+ table => 'table3', |
|
1211 |
+ filter => [ |
|
1212 |
+ key1 => {in => sub { uc $_[0] }} |
|
1213 |
+ ] |
|
1214 |
+); |
|
1215 |
+$dbi->setup_model; |
|
1216 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
1217 |
+$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3}); |
|
1218 |
+$model = $dbi->model('table1'); |
|
1219 |
+$result = $model->select( |
|
1220 |
+ column => [$model->mycolumn, $model->column('table2')], |
|
1221 |
+ where => {'table1.key1' => 1} |
|
1222 |
+); |
|
1223 |
+is_deeply($result->one, |
|
1224 |
+ {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3}); |
|
1225 |
+is_deeply($model2->select->one, {key1 => 1, key3 => 3}); |
|
1226 |
+ |
|
1227 |
+test 'model method'; |
|
1228 |
+test 'create_model'; |
|
1229 |
+$dbi = DBIx::Custom->connect; |
|
1230 |
+eval { $dbi->execute('drop table table2') }; |
|
1231 |
+$dbi->execute($create_table2); |
|
1232 |
+$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3}); |
|
1233 |
+$model = $dbi->create_model( |
|
1234 |
+ table => 'table2' |
|
1235 |
+); |
|
1236 |
+$model->method(foo => sub { shift->select(@_) }); |
|
1237 |
+is_deeply($model->foo->one, {key1 => 1, key3 => 3}); |
|
1238 |
+ |
|
1239 | 1239 |
test 'join'; |
1240 | 1240 |
$dbi = DBIx::Custom->connect; |
1241 | 1241 |
eval { $dbi->execute('drop table table1') }; |