| ... | ... |
@@ -180,314 +180,6 @@ $dbi = DBIx::Custom->connect; |
| 180 | 180 |
|
| 181 | 181 |
### a little complex test |
| 182 | 182 |
|
| 183 |
- |
|
| 184 |
-test 'type_rule and filter order'; |
|
| 185 |
-$dbi = DBIx::Custom->connect; |
|
| 186 |
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
|
|
| 187 |
-$dbi->type_rule( |
|
| 188 |
- into1 => {
|
|
| 189 |
- date => sub { $_[0] . 'b' }
|
|
| 190 |
- }, |
|
| 191 |
- into2 => {
|
|
| 192 |
- date => sub { $_[0] . 'c' }
|
|
| 193 |
- }, |
|
| 194 |
- from1 => {
|
|
| 195 |
- date => sub { $_[0] . 'd' }
|
|
| 196 |
- }, |
|
| 197 |
- from2 => {
|
|
| 198 |
- date => sub { $_[0] . 'e' }
|
|
| 199 |
- } |
|
| 200 |
-); |
|
| 201 |
-$dbi->insert({key1 => '1'}, table => 'table1', filter => {key1 => sub { $_[0] . 'a' }});
|
|
| 202 |
-$result = $dbi->select(table => 'table1'); |
|
| 203 |
-$result->filter(key1 => sub { $_[0] . 'f' });
|
|
| 204 |
-is($result->fetch_first->[0], '1abcdef'); |
|
| 205 |
- |
|
| 206 |
-$dbi = DBIx::Custom->connect; |
|
| 207 |
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
|
|
| 208 |
-$dbi->type_rule( |
|
| 209 |
- from1 => {
|
|
| 210 |
- date => sub { $_[0] . 'p' }
|
|
| 211 |
- }, |
|
| 212 |
- from2 => {
|
|
| 213 |
- date => sub { $_[0] . 'q' }
|
|
| 214 |
- }, |
|
| 215 |
-); |
|
| 216 |
-$dbi->insert({key1 => '1'}, table => 'table1');
|
|
| 217 |
-$result = $dbi->select(table => 'table1'); |
|
| 218 |
-$result->type_rule( |
|
| 219 |
- from1 => {
|
|
| 220 |
- date => sub { $_[0] . 'd' }
|
|
| 221 |
- }, |
|
| 222 |
- from2 => {
|
|
| 223 |
- date => sub { $_[0] . 'e' }
|
|
| 224 |
- } |
|
| 225 |
-); |
|
| 226 |
-$result->filter(key1 => sub { $_[0] . 'f' });
|
|
| 227 |
-is($result->fetch_first->[0], '1def'); |
|
| 228 |
- |
|
| 229 |
-test 'type_rule_off'; |
|
| 230 |
-$dbi = DBIx::Custom->connect; |
|
| 231 |
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
|
|
| 232 |
-$dbi->type_rule( |
|
| 233 |
- from1 => {
|
|
| 234 |
- date => sub { $_[0] * 2 },
|
|
| 235 |
- }, |
|
| 236 |
- into1 => {
|
|
| 237 |
- date => sub { $_[0] * 2 },
|
|
| 238 |
- } |
|
| 239 |
-); |
|
| 240 |
-$dbi->insert({key1 => 2}, table => 'table1', type_rule_off => 1);
|
|
| 241 |
-$result = $dbi->select(table => 'table1', type_rule_off => 1); |
|
| 242 |
-is($result->type_rule_off->fetch->[0], 2); |
|
| 243 |
- |
|
| 244 |
-$dbi = DBIx::Custom->connect; |
|
| 245 |
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
|
|
| 246 |
-$dbi->type_rule( |
|
| 247 |
- from1 => {
|
|
| 248 |
- date => sub { $_[0] * 2 },
|
|
| 249 |
- }, |
|
| 250 |
- into1 => {
|
|
| 251 |
- date => sub { $_[0] * 3 },
|
|
| 252 |
- } |
|
| 253 |
-); |
|
| 254 |
-$dbi->insert({key1 => 2}, table => 'table1', type_rule_off => 1);
|
|
| 255 |
-$result = $dbi->select(table => 'table1', type_rule_off => 1); |
|
| 256 |
-is($result->one->{key1}, 4);
|
|
| 257 |
- |
|
| 258 |
-$dbi = DBIx::Custom->connect; |
|
| 259 |
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
|
|
| 260 |
-$dbi->type_rule( |
|
| 261 |
- from1 => {
|
|
| 262 |
- date => sub { $_[0] * 2 },
|
|
| 263 |
- }, |
|
| 264 |
- into1 => {
|
|
| 265 |
- date => sub { $_[0] * 3 },
|
|
| 266 |
- } |
|
| 267 |
-); |
|
| 268 |
-$dbi->insert({key1 => 2}, table => 'table1');
|
|
| 269 |
-$result = $dbi->select(table => 'table1'); |
|
| 270 |
-is($result->one->{key1}, 12);
|
|
| 271 |
- |
|
| 272 |
-$dbi = DBIx::Custom->connect; |
|
| 273 |
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
|
|
| 274 |
-$dbi->type_rule( |
|
| 275 |
- from1 => {
|
|
| 276 |
- date => sub { $_[0] * 2 },
|
|
| 277 |
- }, |
|
| 278 |
- into1 => {
|
|
| 279 |
- date => sub { $_[0] * 3 },
|
|
| 280 |
- } |
|
| 281 |
-); |
|
| 282 |
-$dbi->insert({key1 => 2}, table => 'table1');
|
|
| 283 |
-$result = $dbi->select(table => 'table1'); |
|
| 284 |
-is($result->fetch->[0], 12); |
|
| 285 |
- |
|
| 286 |
-$dbi = DBIx::Custom->connect; |
|
| 287 |
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
|
|
| 288 |
-$dbi->register_filter(ppp => sub { uc $_[0] });
|
|
| 289 |
-$dbi->type_rule( |
|
| 290 |
- into1 => {
|
|
| 291 |
- date => 'ppp' |
|
| 292 |
- } |
|
| 293 |
-); |
|
| 294 |
-$dbi->insert({key1 => 'a'}, table => 'table1');
|
|
| 295 |
-$result = $dbi->select(table => 'table1'); |
|
| 296 |
-is($result->one->{key1}, 'A');
|
|
| 297 |
- |
|
| 298 |
-eval{$dbi->type_rule(
|
|
| 299 |
- into1 => {
|
|
| 300 |
- date => 'pp' |
|
| 301 |
- } |
|
| 302 |
-)}; |
|
| 303 |
-like($@, qr/not registered/); |
|
| 304 |
- |
|
| 305 |
-$dbi = DBIx::Custom->connect; |
|
| 306 |
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
|
|
| 307 |
-eval {
|
|
| 308 |
- $dbi->type_rule( |
|
| 309 |
- from1 => {
|
|
| 310 |
- Date => sub { $_[0] * 2 },
|
|
| 311 |
- } |
|
| 312 |
- ); |
|
| 313 |
-}; |
|
| 314 |
-like($@, qr/lower/); |
|
| 315 |
- |
|
| 316 |
-eval {
|
|
| 317 |
- $dbi->type_rule( |
|
| 318 |
- into1 => {
|
|
| 319 |
- Date => sub { $_[0] * 2 },
|
|
| 320 |
- } |
|
| 321 |
- ); |
|
| 322 |
-}; |
|
| 323 |
-like($@, qr/lower/); |
|
| 324 |
- |
|
| 325 |
-$dbi = DBIx::Custom->connect; |
|
| 326 |
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
|
|
| 327 |
-$dbi->type_rule( |
|
| 328 |
- from1 => {
|
|
| 329 |
- date => sub { $_[0] * 2 },
|
|
| 330 |
- }, |
|
| 331 |
- into1 => {
|
|
| 332 |
- date => sub { $_[0] * 3 },
|
|
| 333 |
- } |
|
| 334 |
-); |
|
| 335 |
-$dbi->insert({key1 => 2}, table => 'table1');
|
|
| 336 |
-$result = $dbi->select(table => 'table1'); |
|
| 337 |
-$result->type_rule_off; |
|
| 338 |
-is($result->one->{key1}, 6);
|
|
| 339 |
- |
|
| 340 |
-$dbi = DBIx::Custom->connect; |
|
| 341 |
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
|
|
| 342 |
-$dbi->type_rule( |
|
| 343 |
- from1 => {
|
|
| 344 |
- date => sub { $_[0] * 2 },
|
|
| 345 |
- datetime => sub { $_[0] * 4 },
|
|
| 346 |
- }, |
|
| 347 |
-); |
|
| 348 |
-$dbi->insert({key1 => 2, key2 => 2}, table => 'table1');
|
|
| 349 |
-$result = $dbi->select(table => 'table1'); |
|
| 350 |
-$result->type_rule( |
|
| 351 |
- from1 => {
|
|
| 352 |
- date => sub { $_[0] * 3 }
|
|
| 353 |
- } |
|
| 354 |
-); |
|
| 355 |
-$row = $result->one; |
|
| 356 |
-is($row->{key1}, 6);
|
|
| 357 |
-is($row->{key2}, 2);
|
|
| 358 |
- |
|
| 359 |
-$result = $dbi->select(table => 'table1'); |
|
| 360 |
-$result->type_rule( |
|
| 361 |
- from1 => {
|
|
| 362 |
- date => sub { $_[0] * 3 }
|
|
| 363 |
- } |
|
| 364 |
-); |
|
| 365 |
-$row = $result->one; |
|
| 366 |
-is($row->{key1}, 6);
|
|
| 367 |
-is($row->{key2}, 2);
|
|
| 368 |
- |
|
| 369 |
-$result = $dbi->select(table => 'table1'); |
|
| 370 |
-$result->type_rule( |
|
| 371 |
- from1 => {
|
|
| 372 |
- date => sub { $_[0] * 3 }
|
|
| 373 |
- } |
|
| 374 |
-); |
|
| 375 |
-$row = $result->one; |
|
| 376 |
-is($row->{key1}, 6);
|
|
| 377 |
-is($row->{key2}, 2);
|
|
| 378 |
-$result = $dbi->select(table => 'table1'); |
|
| 379 |
-$result->type_rule( |
|
| 380 |
- from1 => [date => sub { $_[0] * 3 }]
|
|
| 381 |
-); |
|
| 382 |
-$row = $result->one; |
|
| 383 |
-is($row->{key1}, 6);
|
|
| 384 |
-is($row->{key2}, 2);
|
|
| 385 |
-$dbi->register_filter(fivetimes => sub { $_[0] * 5});
|
|
| 386 |
-$result = $dbi->select(table => 'table1'); |
|
| 387 |
-$result->type_rule( |
|
| 388 |
- from1 => [date => 'fivetimes'] |
|
| 389 |
-); |
|
| 390 |
-$row = $result->one; |
|
| 391 |
-is($row->{key1}, 10);
|
|
| 392 |
-is($row->{key2}, 2);
|
|
| 393 |
-$result = $dbi->select(table => 'table1'); |
|
| 394 |
-$result->type_rule( |
|
| 395 |
- from1 => [date => undef] |
|
| 396 |
-); |
|
| 397 |
-$row = $result->one; |
|
| 398 |
-is($row->{key1}, 2);
|
|
| 399 |
-is($row->{key2}, 2);
|
|
| 400 |
- |
|
| 401 |
-$dbi = DBIx::Custom->connect; |
|
| 402 |
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
|
|
| 403 |
-$dbi->type_rule( |
|
| 404 |
- from1 => {
|
|
| 405 |
- date => sub { $_[0] * 2 },
|
|
| 406 |
- }, |
|
| 407 |
-); |
|
| 408 |
-$dbi->insert({key1 => 2}, table => 'table1');
|
|
| 409 |
-$result = $dbi->select(table => 'table1'); |
|
| 410 |
-$result->filter(key1 => sub { $_[0] * 3 });
|
|
| 411 |
-is($result->one->{key1}, 12);
|
|
| 412 |
- |
|
| 413 |
-$dbi = DBIx::Custom->connect; |
|
| 414 |
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
|
|
| 415 |
-$dbi->type_rule( |
|
| 416 |
- from1 => {
|
|
| 417 |
- date => sub { $_[0] * 2 },
|
|
| 418 |
- }, |
|
| 419 |
-); |
|
| 420 |
-$dbi->insert({key1 => 2}, table => 'table1');
|
|
| 421 |
-$result = $dbi->select(table => 'table1'); |
|
| 422 |
-$result->filter(key1 => sub { $_[0] * 3 });
|
|
| 423 |
-is($result->fetch->[0], 12); |
|
| 424 |
- |
|
| 425 |
-$dbi = DBIx::Custom->connect; |
|
| 426 |
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
|
|
| 427 |
-$dbi->type_rule( |
|
| 428 |
- into1 => {
|
|
| 429 |
- date => sub { $_[0] . 'b' }
|
|
| 430 |
- }, |
|
| 431 |
- into2 => {
|
|
| 432 |
- date => sub { $_[0] . 'c' }
|
|
| 433 |
- }, |
|
| 434 |
- from1 => {
|
|
| 435 |
- date => sub { $_[0] . 'd' }
|
|
| 436 |
- }, |
|
| 437 |
- from2 => {
|
|
| 438 |
- date => sub { $_[0] . 'e' }
|
|
| 439 |
- } |
|
| 440 |
-); |
|
| 441 |
-$dbi->insert({key1 => '1'}, table => 'table1', type_rule_off => 1);
|
|
| 442 |
-$result = $dbi->select(table => 'table1'); |
|
| 443 |
-is($result->type_rule_off->fetch_first->[0], '1'); |
|
| 444 |
-$result = $dbi->select(table => 'table1'); |
|
| 445 |
-is($result->type_rule_on->fetch_first->[0], '1de'); |
|
| 446 |
- |
|
| 447 |
-$dbi = DBIx::Custom->connect; |
|
| 448 |
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
|
|
| 449 |
-$dbi->type_rule( |
|
| 450 |
- into1 => {
|
|
| 451 |
- date => sub { $_[0] . 'b' }
|
|
| 452 |
- }, |
|
| 453 |
- into2 => {
|
|
| 454 |
- date => sub { $_[0] . 'c' }
|
|
| 455 |
- }, |
|
| 456 |
- from1 => {
|
|
| 457 |
- date => sub { $_[0] . 'd' }
|
|
| 458 |
- }, |
|
| 459 |
- from2 => {
|
|
| 460 |
- date => sub { $_[0] . 'e' }
|
|
| 461 |
- } |
|
| 462 |
-); |
|
| 463 |
-$dbi->insert({key1 => '1'}, table => 'table1', type_rule1_off => 1);
|
|
| 464 |
-$result = $dbi->select(table => 'table1'); |
|
| 465 |
-is($result->type_rule1_off->fetch_first->[0], '1ce'); |
|
| 466 |
-$result = $dbi->select(table => 'table1'); |
|
| 467 |
-is($result->type_rule1_on->fetch_first->[0], '1cde'); |
|
| 468 |
- |
|
| 469 |
-$dbi = DBIx::Custom->connect; |
|
| 470 |
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
|
|
| 471 |
-$dbi->type_rule( |
|
| 472 |
- into1 => {
|
|
| 473 |
- date => sub { $_[0] . 'b' }
|
|
| 474 |
- }, |
|
| 475 |
- into2 => {
|
|
| 476 |
- date => sub { $_[0] . 'c' }
|
|
| 477 |
- }, |
|
| 478 |
- from1 => {
|
|
| 479 |
- date => sub { $_[0] . 'd' }
|
|
| 480 |
- }, |
|
| 481 |
- from2 => {
|
|
| 482 |
- date => sub { $_[0] . 'e' }
|
|
| 483 |
- } |
|
| 484 |
-); |
|
| 485 |
-$dbi->insert({key1 => '1'}, table => 'table1', type_rule2_off => 1);
|
|
| 486 |
-$result = $dbi->select(table => 'table1'); |
|
| 487 |
-is($result->type_rule2_off->fetch_first->[0], '1bd'); |
|
| 488 |
-$result = $dbi->select(table => 'table1'); |
|
| 489 |
-is($result->type_rule2_on->fetch_first->[0], '1bde'); |
|
| 490 |
- |
|
| 491 | 183 |
test 'Model class'; |
| 492 | 184 |
use MyDBI1; |
| 493 | 185 |
$dbi = MyDBI1->connect; |
| ... | ... |
@@ -558,12 +250,6 @@ is_deeply($dbi->model('company')->columns, ['id', 'name']);
|
| 558 | 250 |
|
| 559 | 251 |
|
| 560 | 252 |
|
| 561 |
- |
|
| 562 |
- |
|
| 563 |
- |
|
| 564 |
- |
|
| 565 |
- |
|
| 566 |
- |
|
| 567 | 253 |
### SQLite only test |
| 568 | 254 |
test 'prefix'; |
| 569 | 255 |
$dbi = DBIx::Custom->connect; |
| ... | ... |
@@ -695,10 +381,6 @@ is($result->fetch_first->[0], 'A'); |
| 695 | 381 |
$result = $dbi->select(table => 'table1'); |
| 696 | 382 |
is($result->one->{key1}, 'A');
|
| 697 | 383 |
|
| 698 |
- |
|
| 699 |
- |
|
| 700 |
- |
|
| 701 |
- |
|
| 702 | 384 |
# DEPRECATED! test |
| 703 | 385 |
test 'filter __ expression'; |
| 704 | 386 |
$dbi = DBIx::Custom->connect; |