| 1 | package SQL::Engine::Grammar::Mysql; | ||
| 2 | |||
| 3 | use 5.014; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use registry; | ||
| 9 | use routines; | ||
| 10 | |||
| 11 | use Data::Object::Class; | ||
| 12 | |||
| 13 | extends 'SQL::Engine::Grammar'; | ||
| 14 | |||
| 15 | our $VERSION = '0.02'; # VERSION | ||
| 16 | |||
| 17 | # METHODS | ||
| 18 | |||
| 19 | method column_change(HashRef $data) { | ||
| 20 | $self->operation($self->term(qw(start transaction))); | ||
| 21 | |||
| 22 | my $def = $self->column_definition($data->{column}); | ||
| 23 | |||
| 24 | # column type | ||
| 25 | $self->operation(do { | ||
| 26 | my $sql = []; | ||
| 27 | |||
| 28 | # alter table | ||
| 29 | push @$sql, $self->term(qw(alter table)); | ||
| 30 | |||
| 31 | # safe | ||
| 32 | push @$sql, $self->term(qw(if exists)) if $data->{safe}; | ||
| 33 | |||
| 34 | # for | ||
| 35 | push @$sql, $self->table($data->{for}); | ||
| 36 | |||
| 37 | # alter column | ||
| 38 | push @$sql, $self->term('modify'); | ||
| 39 | |||
| 40 | # column name | ||
| 41 | push @$sql, $self->name($data->{column}{name}); | ||
| 42 | |||
| 43 | # column tyoe | ||
| 44 | push @$sql, $def->{type}; | ||
| 45 | |||
| 46 | # column (null | not null) | ||
| 47 | push @$sql, $data->{column}{nullable} | ||
| 48 | ? $self->term(qw(not null)) : $self->term(qw(not null)); | ||
| 49 | |||
| 50 | # sql statement | ||
| 51 | join ' ', @$sql | ||
| 52 | }); | ||
| 53 | |||
| 54 | # column default | ||
| 55 | $self->operation(do { | ||
| 56 | my $sql = []; | ||
| 57 | |||
| 58 | # alter table | ||
| 59 | push @$sql, $self->term(qw(alter table)); | ||
| 60 | |||
| 61 | # safe | ||
| 62 | push @$sql, $self->term(qw(if exists)) if $data->{safe}; | ||
| 63 | |||
| 64 | # for | ||
| 65 | push @$sql, $self->table($data->{for}); | ||
| 66 | |||
| 67 | # alter column | ||
| 68 | push @$sql, $self->term(qw(alter column)); | ||
| 69 | |||
| 70 | # column name | ||
| 71 | push @$sql, $self->name($data->{column}{name}); | ||
| 72 | |||
| 73 | # column (set | drop) default | ||
| 74 | push @$sql, | ||
| 75 | $data->{column}{default} | ||
| 76 | ? ($self->term('set'), $def->{default}) | ||
| 77 | : ($self->term('drop'), $self->term('default')); | ||
| 78 | |||
| 79 | # sql statement | ||
| 80 | join ' ', @$sql | ||
| 81 | }); | ||
| 82 | |||
| 83 | $self->operation($self->term('commit')); | ||
| 84 | |||
| 85 | return $self; | ||
| 86 | } | ||
| 87 | |||
| 88 | method column_definition(HashRef $data) { | ||
| 89 | my $def = $self->next::method($data); | ||
| 90 | |||
| 91 | if (exists $data->{default}) { | ||
| 92 | $def->{default} = join ' ', $self->term('default'), | ||
| 93 | sprintf '(%s)', $self->expression($data->{default}); | ||
| 94 | } | ||
| 95 | |||
| 96 | if ($data->{increment}) { | ||
| 97 | $def->{increment} = $self->term('auto_increment'); | ||
| 98 | } | ||
| 99 | |||
| 100 | return $def; | ||
| 101 | } | ||
| 102 | |||
| 103 | method index_drop(HashRef $data) { | ||
| 104 | my $sql = []; | ||
| 105 | |||
| 106 | # drop | ||
| 107 | push @$sql, $self->term('drop'); | ||
| 108 | |||
| 109 | # index | ||
| 110 | push @$sql, $self->term('index'); | ||
| 111 | |||
| 112 | # index name | ||
| 113 | push @$sql, $self->wrap($self->index_name($data)); | ||
| 114 | |||
| 115 | # table name | ||
| 116 | push @$sql, $self->term('on'), $self->table($data->{for}); | ||
| 117 | |||
| 118 | # sql statement | ||
| 119 | my $result = join ' ', @$sql; | ||
| 120 | |||
| 121 | return $self->operation($result); | ||
| 122 | } | ||
| 123 | |||
| 124 | method transaction(HashRef $data) { | ||
| 125 | my @mode; | ||
| 126 | if ($data->{mode}) { | ||
| 127 | @mode = map $self->term($_), @{$data->{mode}}; | ||
| 128 | } | ||
| 129 | $self->operation($self->term('start', 'transaction', @mode)); | ||
| 130 | $self->process($_) for @{$data->{queries}}; | ||
| 131 | $self->operation($self->term('commit')); | ||
| 132 | |||
| 133 | return $self; | ||
| 134 | } | ||
| 135 | |||
| 136 | method type_binary(HashRef $data) { | ||
| 137 | |||
| 138 | return 'blob'; | ||
| 139 | } | ||
| 140 | |||
| 141 | method type_boolean(HashRef $data) { | ||
| 142 | |||
| 143 | return 'tinyint(1)'; | ||
| 144 | } | ||
| 145 | |||
| 146 | method type_char(HashRef $data) { | ||
| 147 | my $options = $data->{options} || []; | ||
| 148 | |||
| 149 | return sprintf('char(%s)', $self->value($options->[0] || 1)); | ||
| 150 | } | ||
| 151 | |||
| 152 | method type_date(HashRef $data) { | ||
| 153 | |||
| 154 | return 'date'; | ||
| 155 | } | ||
| 156 | |||
| 157 | method type_datetime(HashRef $data) { | ||
| 158 | |||
| 159 | return 'datetime'; | ||
| 160 | } | ||
| 161 | |||
| 162 | method type_datetime_wtz(HashRef $data) { | ||
| 163 | |||
| 164 | return 'datetime'; | ||
| 165 | } | ||
| 166 | |||
| 167 | method type_decimal(HashRef $data) { | ||
| 168 | my $options = $data->{options} || []; | ||
| 169 | |||
| 170 | return sprintf( | ||
| 171 | 'decimal(%s)', | ||
| 172 | join(', ', | ||
| 173 | $self->value($options->[0]) || 5, | ||
| 174 | $self->value($options->[1]) || 2) | ||
| 175 | ); | ||
| 176 | } | ||
| 177 | |||
| 178 | method type_double(HashRef $data) { | ||
| 179 | my $options = $data->{options} || []; | ||
| 180 | |||
| 181 | return sprintf( | ||
| 182 | 'double(%s)', | ||
| 183 | join(', ', | ||
| 184 | $self->value($options->[0]) || 5, | ||
| 185 | $self->value($options->[1]) || 2) | ||
| 186 | ); | ||
| 187 | } | ||
| 188 | |||
| 189 | method type_enum(HashRef $data) { | ||
| 190 | my $options = $data->{options}; | ||
| 191 | |||
| 192 | return sprintf('enum(%s)', join(', ', map $self->value($_), @$options)); | ||
| 193 | } | ||
| 194 | |||
| 195 | method type_float(HashRef $data) { | ||
| 196 | |||
| 197 | return $self->type_double($data); | ||
| 198 | } | ||
| 199 | |||
| 200 | method type_integer(HashRef $data) { | ||
| 201 | |||
| 202 | return 'int'; | ||
| 203 | } | ||
| 204 | |||
| 205 | method type_integer_big(HashRef $data) { | ||
| 206 | |||
| 207 | return 'bigint'; | ||
| 208 | } | ||
| 209 | |||
| 210 | method type_integer_big_unsigned(HashRef $data) { | ||
| 211 | |||
| 212 | return join ' ', $self->type_integer_big($data), 'unsigned'; | ||
| 213 | } | ||
| 214 | |||
| 215 | method type_integer_medium(HashRef $data) { | ||
| 216 | |||
| 217 | return 'mediumint'; | ||
| 218 | } | ||
| 219 | |||
| 220 | method type_integer_medium_unsigned(HashRef $data) { | ||
| 221 | |||
| 222 | return join ' ', $self->type_integer_medium($data), 'unsigned'; | ||
| 223 | } | ||
| 224 | |||
| 225 | method type_integer_small(HashRef $data) { | ||
| 226 | |||
| 227 | return 'smallint'; | ||
| 228 | } | ||
| 229 | |||
| 230 | method type_integer_small_unsigned(HashRef $data) { | ||
| 231 | |||
| 232 | return join ' ', $self->type_integer_small($data), 'unsigned'; | ||
| 233 | } | ||
| 234 | |||
| 235 | method type_integer_tiny(HashRef $data) { | ||
| 236 | |||
| 237 | return 'tinyint'; | ||
| 238 | } | ||
| 239 | |||
| 240 | method type_integer_tiny_unsigned(HashRef $data) { | ||
| 241 | |||
| 242 | return join ' ', $self->type_integer_tiny($data), 'unsigned'; | ||
| 243 | } | ||
| 244 | |||
| 245 | method type_integer_unsigned(HashRef $data) { | ||
| 246 | |||
| 247 | return join ' ', $self->type_integer($data), 'unsigned'; | ||
| 248 | } | ||
| 249 | |||
| 250 | method type_json(HashRef $data) { | ||
| 251 | |||
| 252 | return 'json'; | ||
| 253 | } | ||
| 254 | |||
| 255 | method type_number(HashRef $data) { | ||
| 256 | |||
| 257 | return $self->type_integer($data); | ||
| 258 | } | ||
| 259 | |||
| 260 | method type_string(HashRef $data) { | ||
| 261 | my $options = $data->{options} || []; | ||
| 262 | |||
| 263 | return sprintf('varchar(%s)', $options->[0] || 255); | ||
| 264 | } | ||
| 265 | |||
| 266 | method type_text(HashRef $data) { | ||
| 267 | |||
| 268 | return 'text'; | ||
| 269 | } | ||
| 270 | |||
| 271 | method type_text_long(HashRef $data) { | ||
| 272 | |||
| 273 | return 'longtext'; | ||
| 274 | } | ||
| 275 | |||
| 276 | method type_text_medium(HashRef $data) { | ||
| 277 | |||
| 278 | return 'mediumtext'; | ||
| 279 | } | ||
| 280 | |||
| 281 | method type_time(HashRef $data) { | ||
| 282 | |||
| 283 | return 'time'; | ||
| 284 | } | ||
| 285 | |||
| 286 | method type_time_wtz(HashRef $data) { | ||
| 287 | |||
| 288 | return 'time'; | ||
| 289 | } | ||
| 290 | |||
| 291 | method type_timestamp(HashRef $data) { | ||
| 292 | |||
| 293 | return 'timestamp'; | ||
| 294 | } | ||
| 295 | |||
| 296 | method type_timestamp_wtz(HashRef $data) { | ||
| 297 | |||
| 298 | return 'timestamp'; | ||
| 299 | } | ||
| 300 | |||
| 301 | method type_uuid(HashRef $data) { | ||
| 302 | |||
| 303 | return 'char(36)'; | ||
| 304 | } | ||
| 305 | |||
| 306 | method view_create(HashRef $data) { | ||
| 307 | my $sql = []; | ||
| 308 | |||
| 309 | # create | ||
| 310 | push @$sql, $self->term('create'); | ||
| 311 | |||
| 312 | # view | ||
| 313 | push @$sql, $self->term('view'); | ||
| 314 | |||
| 315 | # safe | ||
| 316 | if ($data->{safe}) { | ||
| 317 | push @$sql, $self->term(qw(if not exists)); | ||
| 318 | } | ||
| 319 | |||
| 320 | # view name | ||
| 321 | push @$sql, $self->name($data->{name}); | ||
| 322 | |||
| 323 | # columns | ||
| 324 | if (my $columns = $data->{columns}) { | ||
| 325 | push @$sql, | ||
| 326 | sprintf('(%s)', join(', ', map $self->expression($_), @$columns)); | ||
| 327 | } | ||
| 328 | |||
| 329 | # query | ||
| 330 | if (my $query = $data->{query}) { | ||
| 331 | $self->select($query->{select}); | ||
| 332 | my $operation = $self->operations->pop; | ||
| 333 | $self->{bindings} = $operation->bindings; | ||
| 334 | push @$sql, $self->term('as'); | ||
| 335 | push @$sql, $operation->statement; | ||
| 336 | } | ||
| 337 | |||
| 338 | # sql statement | ||
| 339 | my $result = join ' ', @$sql; | ||
| 340 | |||
| 341 | return $self->operation($result); | ||
| 342 | } | ||
| 343 | |||
| 344 | method wrap(Str $name) { | ||
| 345 | |||
| 346 | return qq(`$name`); | ||
| 347 | } | ||
| 348 | |||
| 349 | 1; | ||
| 350 | |||
| 351 | =encoding utf8 | ||
| 352 | |||
| 353 | =head1 NAME | ||
| 354 | |||
| 355 | SQL::Engine::Grammar::Mysql - Grammar For MySQL | ||
| 356 | |||
| 357 | =cut | ||
| 358 | |||
| 359 | =head1 ABSTRACT | ||
| 360 | |||
| 361 | SQL::Engine Grammar For MySQL | ||
| 362 | |||
| 363 | =cut | ||
| 364 | |||
| 365 | =head1 SYNOPSIS | ||
| 366 | |||
| 367 | use SQL::Engine::Grammar::Mysql; | ||
| 368 | |||
| 369 | my $grammar = SQL::Engine::Grammar::Mysql->new( | ||
| 370 | schema => { | ||
| 371 | select => { | ||
| 372 | from => { | ||
| 373 | table => 'users' | ||
| 374 | }, | ||
| 375 | columns => [ | ||
| 376 | { | ||
| 377 | column => '*' | ||
| 378 | } | ||
| 379 | ] | ||
| 380 | } | ||
| 381 | } | ||
| 382 | ); | ||
| 383 | |||
| 384 | # $grammar->execute; | ||
| 385 | |||
| 386 | =cut | ||
| 387 | |||
| 388 | =head1 DESCRIPTION | ||
| 389 | |||
| 390 | This package provides methods for converting | ||
| 391 | L<json-sql|https://github.com/iamalnewkirk/json-sql> data structures into | ||
| 392 | MySQL statements. | ||
| 393 | |||
| 394 | =cut | ||
| 395 | |||
| 396 | =head1 INHERITS | ||
| 397 | |||
| 398 | This package inherits behaviors from: | ||
| 399 | |||
| 400 | L<SQL::Engine::Grammar> | ||
| 401 | |||
| 402 | =cut | ||
| 403 | |||
| 404 | =head1 LIBRARIES | ||
| 405 | |||
| 406 | This package uses type constraints from: | ||
| 407 | |||
| 408 | L<Types::Standard> | ||
| 409 | |||
| 410 | =cut | ||
| 411 | |||
| 412 | =head1 METHODS | ||
| 413 | |||
| 414 | This package implements the following methods: | ||
| 415 | |||
| 416 | =cut | ||
| 417 | |||
| 418 | =head2 column_change | ||
| 419 | |||
| 420 | column_change(HashRef $data) : Object | ||
| 421 | |||
| 422 | The column_change method generates SQL statements to change a column | ||
| 423 | definition. | ||
| 424 | |||
| 425 | =over 4 | ||
| 426 | |||
| 427 | =item column_change example #1 | ||
| 428 | |||
| 429 | my $grammar = SQL::Engine::Grammar::Mysql->new( | ||
| 430 | schema => { | ||
| 431 | 'column-change' => { | ||
| 432 | for => { | ||
| 433 | table => 'users' | ||
| 434 | }, | ||
| 435 | column => { | ||
| 436 | name => 'accessed', | ||
| 437 | type => 'datetime', | ||
| 438 | nullable => 1 | ||
| 439 | } | ||
| 440 | } | ||
| 441 | } | ||
| 442 | ); | ||
| 443 | |||
| 444 | $grammar->column_change($grammar->schema->{'column-change'}); | ||
| 445 | |||
| 446 | =back | ||
| 447 | |||
| 448 | =cut | ||
| 449 | |||
| 450 | =head2 transaction | ||
| 451 | |||
| 452 | transaction(HashRef $data) : Object | ||
| 453 | |||
| 454 | The transaction method generates SQL statements to commit an atomic database | ||
| 455 | transaction. | ||
| 456 | |||
| 457 | =over 4 | ||
| 458 | |||
| 459 | =item transaction example #1 | ||
| 460 | |||
| 461 | my $grammar = SQL::Engine::Grammar::Mysql->new( | ||
| 462 | schema => { | ||
| 463 | 'transaction' => { | ||
| 464 | queries => [ | ||
| 465 | { | ||
| 466 | 'table-create' => { | ||
| 467 | name => 'users', | ||
| 468 | columns => [ | ||
| 469 | { | ||
| 470 | name => 'id', | ||
| 471 | type => 'integer', | ||
| 472 | primary => 1 | ||
| 473 | } | ||
| 474 | ] | ||
| 475 | } | ||
| 476 | } | ||
| 477 | ] | ||
| 478 | } | ||
| 479 | } | ||
| 480 | ); | ||
| 481 | |||
| 482 | $grammar->transaction($grammar->schema->{'transaction'}); | ||
| 483 | |||
| 484 | =back | ||
| 485 | |||
| 486 | =cut | ||
| 487 | |||
| 488 | =head2 type_binary | ||
| 489 | |||
| 490 | type_binary(HashRef $data) : Str | ||
| 491 | |||
| 492 | The type_binary method returns the SQL expression representing a binary data | ||
| 493 | type. | ||
| 494 | |||
| 495 | =over 4 | ||
| 496 | |||
| 497 | =item type_binary example #1 | ||
| 498 | |||
| 499 | # given: synopsis | ||
| 500 | |||
| 501 | $grammar->type_binary({}); | ||
| 502 | |||
| 503 | # blob | ||
| 504 | |||
| 505 | =back | ||
| 506 | |||
| 507 | =cut | ||
| 508 | |||
| 509 | =head2 type_boolean | ||
| 510 | |||
| 511 | type_boolean(HashRef $data) : Str | ||
| 512 | |||
| 513 | The type_boolean method returns the SQL expression representing a boolean data type. | ||
| 514 | |||
| 515 | =over 4 | ||
| 516 | |||
| 517 | =item type_boolean example #1 | ||
| 518 | |||
| 519 | # given: synopsis | ||
| 520 | |||
| 521 | $grammar->type_boolean({}); | ||
| 522 | |||
| 523 | # tinyint(1) | ||
| 524 | |||
| 525 | =back | ||
| 526 | |||
| 527 | =cut | ||
| 528 | |||
| 529 | =head2 type_char | ||
| 530 | |||
| 531 | type_char(HashRef $data) : Str | ||
| 532 | |||
| 533 | The type_char method returns the SQL expression representing a char data type. | ||
| 534 | |||
| 535 | =over 4 | ||
| 536 | |||
| 537 | =item type_char example #1 | ||
| 538 | |||
| 539 | # given: synopsis | ||
| 540 | |||
| 541 | $grammar->type_char({}); | ||
| 542 | |||
| 543 | # char(1) | ||
| 544 | |||
| 545 | =back | ||
| 546 | |||
| 547 | =cut | ||
| 548 | |||
| 549 | =head2 type_date | ||
| 550 | |||
| 551 | type_date(HashRef $data) : Str | ||
| 552 | |||
| 553 | The type_date method returns the SQL expression representing a date data type. | ||
| 554 | |||
| 555 | =over 4 | ||
| 556 | |||
| 557 | =item type_date example #1 | ||
| 558 | |||
| 559 | # given: synopsis | ||
| 560 | |||
| 561 | $grammar->type_date({}); | ||
| 562 | |||
| 563 | # date | ||
| 564 | |||
| 565 | =back | ||
| 566 | |||
| 567 | =cut | ||
| 568 | |||
| 569 | =head2 type_datetime | ||
| 570 | |||
| 571 | type_datetime(HashRef $data) : Str | ||
| 572 | |||
| 573 | The type_datetime method returns the SQL expression representing a datetime | ||
| 574 | data type. | ||
| 575 | |||
| 576 | =over 4 | ||
| 577 | |||
| 578 | =item type_datetime example #1 | ||
| 579 | |||
| 580 | # given: synopsis | ||
| 581 | |||
| 582 | $grammar->type_datetime({}); | ||
| 583 | |||
| 584 | # datetime | ||
| 585 | |||
| 586 | =back | ||
| 587 | |||
| 588 | =cut | ||
| 589 | |||
| 590 | =head2 type_datetime_wtz | ||
| 591 | |||
| 592 | type_datetime_wtz(HashRef $data) : Str | ||
| 593 | |||
| 594 | The type_datetime_wtz method returns the SQL expression representing a datetime | ||
| 595 | (and timezone) data type. | ||
| 596 | |||
| 597 | =over 4 | ||
| 598 | |||
| 599 | =item type_datetime_wtz example #1 | ||
| 600 | |||
| 601 | # given: synopsis | ||
| 602 | |||
| 603 | $grammar->type_datetime_wtz({}); | ||
| 604 | |||
| 605 | # datetime | ||
| 606 | |||
| 607 | =back | ||
| 608 | |||
| 609 | =cut | ||
| 610 | |||
| 611 | =head2 type_decimal | ||
| 612 | |||
| 613 | type_decimal(HashRef $data) : Str | ||
| 614 | |||
| 615 | The type_decimal method returns the SQL expression representing a decimal data | ||
| 616 | type. | ||
| 617 | |||
| 618 | =over 4 | ||
| 619 | |||
| 620 | =item type_decimal example #1 | ||
| 621 | |||
| 622 | # given: synopsis | ||
| 623 | |||
| 624 | $grammar->type_decimal({}); | ||
| 625 | |||
| 626 | # decimal(5, 2) | ||
| 627 | |||
| 628 | =back | ||
| 629 | |||
| 630 | =cut | ||
| 631 | |||
| 632 | =head2 type_double | ||
| 633 | |||
| 634 | type_double(HashRef $data) : Str | ||
| 635 | |||
| 636 | The type_double method returns the SQL expression representing a double data | ||
| 637 | type. | ||
| 638 | |||
| 639 | =over 4 | ||
| 640 | |||
| 641 | =item type_double example #1 | ||
| 642 | |||
| 643 | # given: synopsis | ||
| 644 | |||
| 645 | $grammar->type_double({}); | ||
| 646 | |||
| 647 | # double(5, 2) | ||
| 648 | |||
| 649 | =back | ||
| 650 | |||
| 651 | =cut | ||
| 652 | |||
| 653 | =head2 type_enum | ||
| 654 | |||
| 655 | type_enum(HashRef $data) : Str | ||
| 656 | |||
| 657 | The type_enum method returns the SQL expression representing a enum data type. | ||
| 658 | |||
| 659 | =over 4 | ||
| 660 | |||
| 661 | =item type_enum example #1 | ||
| 662 | |||
| 663 | # given: synopsis | ||
| 664 | |||
| 665 | $grammar->type_enum({ options => ['light', 'dark'] }); | ||
| 666 | |||
| 667 | # enum('light', 'dark') | ||
| 668 | |||
| 669 | =back | ||
| 670 | |||
| 671 | =cut | ||
| 672 | |||
| 673 | =head2 type_float | ||
| 674 | |||
| 675 | type_float(HashRef $data) : Str | ||
| 676 | |||
| 677 | The type_float method returns the SQL expression representing a float data | ||
| 678 | type. | ||
| 679 | |||
| 680 | =over 4 | ||
| 681 | |||
| 682 | =item type_float example #1 | ||
| 683 | |||
| 684 | # given: synopsis | ||
| 685 | |||
| 686 | $grammar->type_float({}); | ||
| 687 | |||
| 688 | # double(1, 1) | ||
| 689 | |||
| 690 | =back | ||
| 691 | |||
| 692 | =cut | ||
| 693 | |||
| 694 | =head2 type_integer | ||
| 695 | |||
| 696 | type_integer(HashRef $data) : Str | ||
| 697 | |||
| 698 | The type_integer method returns the SQL expression representing a integer data | ||
| 699 | type. | ||
| 700 | |||
| 701 | =over 4 | ||
| 702 | |||
| 703 | =item type_integer example #1 | ||
| 704 | |||
| 705 | # given: synopsis | ||
| 706 | |||
| 707 | $grammar->type_integer({}); | ||
| 708 | |||
| 709 | # int | ||
| 710 | |||
| 711 | =back | ||
| 712 | |||
| 713 | =cut | ||
| 714 | |||
| 715 | =head2 type_integer_big | ||
| 716 | |||
| 717 | type_integer_big(HashRef $data) : Str | ||
| 718 | |||
| 719 | The type_integer_big method returns the SQL expression representing a | ||
| 720 | big-integer data type. | ||
| 721 | |||
| 722 | =over 4 | ||
| 723 | |||
| 724 | =item type_integer_big example #1 | ||
| 725 | |||
| 726 | # given: synopsis | ||
| 727 | |||
| 728 | $grammar->type_integer_big({}); | ||
| 729 | |||
| 730 | # bigint | ||
| 731 | |||
| 732 | =back | ||
| 733 | |||
| 734 | =cut | ||
| 735 | |||
| 736 | =head2 type_integer_big_unsigned | ||
| 737 | |||
| 738 | type_integer_big_unsigned(HashRef $data) : Str | ||
| 739 | |||
| 740 | The type_integer_big_unsigned method returns the SQL expression representing a | ||
| 741 | big unsigned integer data type. | ||
| 742 | |||
| 743 | =over 4 | ||
| 744 | |||
| 745 | =item type_integer_big_unsigned example #1 | ||
| 746 | |||
| 747 | # given: synopsis | ||
| 748 | |||
| 749 | $grammar->type_integer_big_unsigned({}); | ||
| 750 | |||
| 751 | # bigint unsigned | ||
| 752 | |||
| 753 | =back | ||
| 754 | |||
| 755 | =cut | ||
| 756 | |||
| 757 | =head2 type_integer_medium | ||
| 758 | |||
| 759 | type_integer_medium(HashRef $data) : Str | ||
| 760 | |||
| 761 | The type_integer_medium method returns the SQL expression representing a medium | ||
| 762 | integer data type. | ||
| 763 | |||
| 764 | =over 4 | ||
| 765 | |||
| 766 | =item type_integer_medium example #1 | ||
| 767 | |||
| 768 | # given: synopsis | ||
| 769 | |||
| 770 | $grammar->type_integer_medium({}); | ||
| 771 | |||
| 772 | # mediumint | ||
| 773 | |||
| 774 | =back | ||
| 775 | |||
| 776 | =cut | ||
| 777 | |||
| 778 | =head2 type_integer_medium_unsigned | ||
| 779 | |||
| 780 | type_integer_medium_unsigned(HashRef $data) : Str | ||
| 781 | |||
| 782 | The type_integer_medium_unsigned method returns the SQL expression representing | ||
| 783 | a unsigned medium integer data type. | ||
| 784 | |||
| 785 | =over 4 | ||
| 786 | |||
| 787 | =item type_integer_medium_unsigned example #1 | ||
| 788 | |||
| 789 | # given: synopsis | ||
| 790 | |||
| 791 | $grammar->type_integer_medium_unsigned({}); | ||
| 792 | |||
| 793 | # mediumint unsigned | ||
| 794 | |||
| 795 | =back | ||
| 796 | |||
| 797 | =cut | ||
| 798 | |||
| 799 | =head2 type_integer_small | ||
| 800 | |||
| 801 | type_integer_small(HashRef $data) : Str | ||
| 802 | |||
| 803 | The type_integer_small method returns the SQL expression representing a small | ||
| 804 | integer data type. | ||
| 805 | |||
| 806 | =over 4 | ||
| 807 | |||
| 808 | =item type_integer_small example #1 | ||
| 809 | |||
| 810 | # given: synopsis | ||
| 811 | |||
| 812 | $grammar->type_integer_small({}); | ||
| 813 | |||
| 814 | # smallint | ||
| 815 | |||
| 816 | =back | ||
| 817 | |||
| 818 | =cut | ||
| 819 | |||
| 820 | =head2 type_integer_small_unsigned | ||
| 821 | |||
| 822 | type_integer_small_unsigned(HashRef $data) : Str | ||
| 823 | |||
| 824 | The type_integer_small_unsigned method returns the SQL expression representing | ||
| 825 | a unsigned small integer data type. | ||
| 826 | |||
| 827 | =over 4 | ||
| 828 | |||
| 829 | =item type_integer_small_unsigned example #1 | ||
| 830 | |||
| 831 | # given: synopsis | ||
| 832 | |||
| 833 | $grammar->type_integer_small_unsigned({}); | ||
| 834 | |||
| 835 | # smallint unsigned | ||
| 836 | |||
| 837 | =back | ||
| 838 | |||
| 839 | =cut | ||
| 840 | |||
| 841 | =head2 type_integer_tiny | ||
| 842 | |||
| 843 | type_integer_tiny(HashRef $data) : Str | ||
| 844 | |||
| 845 | The type_integer_tiny method returns the SQL expression representing a tiny | ||
| 846 | integer data type. | ||
| 847 | |||
| 848 | =over 4 | ||
| 849 | |||
| 850 | =item type_integer_tiny example #1 | ||
| 851 | |||
| 852 | # given: synopsis | ||
| 853 | |||
| 854 | $grammar->type_integer_tiny({}); | ||
| 855 | |||
| 856 | # tinyint | ||
| 857 | |||
| 858 | =back | ||
| 859 | |||
| 860 | =cut | ||
| 861 | |||
| 862 | =head2 type_integer_tiny_unsigned | ||
| 863 | |||
| 864 | type_integer_tiny_unsigned(HashRef $data) : Str | ||
| 865 | |||
| 866 | The type_integer_tiny_unsigned method returns the SQL expression representing a | ||
| 867 | unsigned tiny integer data type. | ||
| 868 | |||
| 869 | =over 4 | ||
| 870 | |||
| 871 | =item type_integer_tiny_unsigned example #1 | ||
| 872 | |||
| 873 | # given: synopsis | ||
| 874 | |||
| 875 | $grammar->type_integer_tiny_unsigned({}); | ||
| 876 | |||
| 877 | # tinyint unsigned | ||
| 878 | |||
| 879 | =back | ||
| 880 | |||
| 881 | =cut | ||
| 882 | |||
| 883 | =head2 type_integer_unsigned | ||
| 884 | |||
| 885 | type_integer_unsigned(HashRef $data) : Str | ||
| 886 | |||
| 887 | The type_integer_unsigned method returns the SQL expression representing a | ||
| 888 | unsigned integer data type. | ||
| 889 | |||
| 890 | =over 4 | ||
| 891 | |||
| 892 | =item type_integer_unsigned example #1 | ||
| 893 | |||
| 894 | # given: synopsis | ||
| 895 | |||
| 896 | $grammar->type_integer_unsigned({}); | ||
| 897 | |||
| 898 | # int unsigned | ||
| 899 | |||
| 900 | =back | ||
| 901 | |||
| 902 | =cut | ||
| 903 | |||
| 904 | =head2 type_json | ||
| 905 | |||
| 906 | type_json(HashRef $data) : Str | ||
| 907 | |||
| 908 | The type_json method returns the SQL expression representing a json data type. | ||
| 909 | |||
| 910 | =over 4 | ||
| 911 | |||
| 912 | =item type_json example #1 | ||
| 913 | |||
| 914 | # given: synopsis | ||
| 915 | |||
| 916 | $grammar->type_json({}); | ||
| 917 | |||
| 918 | # json | ||
| 919 | |||
| 920 | =back | ||
| 921 | |||
| 922 | =cut | ||
| 923 | |||
| 924 | =head2 type_number | ||
| 925 | |||
| 926 | type_number(HashRef $data) : Str | ||
| 927 | |||
| 928 | The type_number method returns the SQL expression representing a number data | ||
| 929 | type. | ||
| 930 | |||
| 931 | =over 4 | ||
| 932 | |||
| 933 | =item type_number example #1 | ||
| 934 | |||
| 935 | # given: synopsis | ||
| 936 | |||
| 937 | $grammar->type_number({}); | ||
| 938 | |||
| 939 | # int | ||
| 940 | |||
| 941 | =back | ||
| 942 | |||
| 943 | =cut | ||
| 944 | |||
| 945 | =head2 type_string | ||
| 946 | |||
| 947 | type_string(HashRef $data) : Str | ||
| 948 | |||
| 949 | The type_string method returns the SQL expression representing a string data | ||
| 950 | type. | ||
| 951 | |||
| 952 | =over 4 | ||
| 953 | |||
| 954 | =item type_string example #1 | ||
| 955 | |||
| 956 | # given: synopsis | ||
| 957 | |||
| 958 | $grammar->type_string({}); | ||
| 959 | |||
| 960 | # varchar(255) | ||
| 961 | |||
| 962 | =back | ||
| 963 | |||
| 964 | =cut | ||
| 965 | |||
| 966 | =head2 type_text | ||
| 967 | |||
| 968 | type_text(HashRef $data) : Str | ||
| 969 | |||
| 970 | The type_text method returns the SQL expression representing a text data type. | ||
| 971 | |||
| 972 | =over 4 | ||
| 973 | |||
| 974 | =item type_text example #1 | ||
| 975 | |||
| 976 | # given: synopsis | ||
| 977 | |||
| 978 | $grammar->type_text({}); | ||
| 979 | |||
| 980 | # text | ||
| 981 | |||
| 982 | =back | ||
| 983 | |||
| 984 | =cut | ||
| 985 | |||
| 986 | =head2 type_text_long | ||
| 987 | |||
| 988 | type_text_long(HashRef $data) : Str | ||
| 989 | |||
| 990 | The type_text_long method returns the SQL expression representing a long text | ||
| 991 | data type. | ||
| 992 | |||
| 993 | =over 4 | ||
| 994 | |||
| 995 | =item type_text_long example #1 | ||
| 996 | |||
| 997 | # given: synopsis | ||
| 998 | |||
| 999 | $grammar->type_text_long({}); | ||
| 1000 | |||
| 1001 | # longtext | ||
| 1002 | |||
| 1003 | =back | ||
| 1004 | |||
| 1005 | =cut | ||
| 1006 | |||
| 1007 | =head2 type_text_medium | ||
| 1008 | |||
| 1009 | type_text_medium(HashRef $data) : Str | ||
| 1010 | |||
| 1011 | The type_text_medium method returns the SQL expression representing a medium | ||
| 1012 | text data type. | ||
| 1013 | |||
| 1014 | =over 4 | ||
| 1015 | |||
| 1016 | =item type_text_medium example #1 | ||
| 1017 | |||
| 1018 | # given: synopsis | ||
| 1019 | |||
| 1020 | $grammar->type_text_medium({}); | ||
| 1021 | |||
| 1022 | # mediumtext | ||
| 1023 | |||
| 1024 | =back | ||
| 1025 | |||
| 1026 | =cut | ||
| 1027 | |||
| 1028 | =head2 type_time | ||
| 1029 | |||
| 1030 | type_time(HashRef $data) : Str | ||
| 1031 | |||
| 1032 | The type_time method returns the SQL expression representing a time data type. | ||
| 1033 | |||
| 1034 | =over 4 | ||
| 1035 | |||
| 1036 | =item type_time example #1 | ||
| 1037 | |||
| 1038 | # given: synopsis | ||
| 1039 | |||
| 1040 | $grammar->type_time({}); | ||
| 1041 | |||
| 1042 | # time | ||
| 1043 | |||
| 1044 | =back | ||
| 1045 | |||
| 1046 | =cut | ||
| 1047 | |||
| 1048 | =head2 type_time_wtz | ||
| 1049 | |||
| 1050 | type_time_wtz(HashRef $data) : Str | ||
| 1051 | |||
| 1052 | The type_time_wtz method returns the SQL expression representing a time (and | ||
| 1053 | timezone) data type. | ||
| 1054 | |||
| 1055 | =over 4 | ||
| 1056 | |||
| 1057 | =item type_time_wtz example #1 | ||
| 1058 | |||
| 1059 | # given: synopsis | ||
| 1060 | |||
| 1061 | $grammar->type_time_wtz({}); | ||
| 1062 | |||
| 1063 | # time | ||
| 1064 | |||
| 1065 | =back | ||
| 1066 | |||
| 1067 | =cut | ||
| 1068 | |||
| 1069 | =head2 type_timestamp | ||
| 1070 | |||
| 1071 | type_timestamp(HashRef $data) : Str | ||
| 1072 | |||
| 1073 | The type_timestamp method returns the SQL expression representing a timestamp | ||
| 1074 | data type. | ||
| 1075 | |||
| 1076 | =over 4 | ||
| 1077 | |||
| 1078 | =item type_timestamp example #1 | ||
| 1079 | |||
| 1080 | # given: synopsis | ||
| 1081 | |||
| 1082 | $grammar->type_timestamp({}); | ||
| 1083 | |||
| 1084 | # timestamp | ||
| 1085 | |||
| 1086 | =back | ||
| 1087 | |||
| 1088 | =cut | ||
| 1089 | |||
| 1090 | =head2 type_timestamp_wtz | ||
| 1091 | |||
| 1092 | type_timestamp_wtz(HashRef $data) : Str | ||
| 1093 | |||
| 1094 | The type_timestamp_wtz method returns the SQL expression representing a | ||
| 1095 | timestamp (and timezone) data type. | ||
| 1096 | |||
| 1097 | =over 4 | ||
| 1098 | |||
| 1099 | =item type_timestamp_wtz example #1 | ||
| 1100 | |||
| 1101 | # given: synopsis | ||
| 1102 | |||
| 1103 | $grammar->type_timestamp_wtz({}); | ||
| 1104 | |||
| 1105 | # timestamp | ||
| 1106 | |||
| 1107 | =back | ||
| 1108 | |||
| 1109 | =cut | ||
| 1110 | |||
| 1111 | =head2 type_uuid | ||
| 1112 | |||
| 1113 | type_uuid(HashRef $data) : Str | ||
| 1114 | |||
| 1115 | The type_uuid method returns the SQL expression representing a uuid data type. | ||
| 1116 | |||
| 1117 | =over 4 | ||
| 1118 | |||
| 1119 | =item type_uuid example #1 | ||
| 1120 | |||
| 1121 | # given: synopsis | ||
| 1122 | |||
| 1123 | $grammar->type_uuid({}); | ||
| 1124 | |||
| 1125 | # char(36) | ||
| 1126 | |||
| 1127 | =back | ||
| 1128 | |||
| 1129 | =cut | ||
| 1130 | |||
| 1131 | =head2 wrap | ||
| 1132 | |||
| 1133 | wrap(Str $name) : Str | ||
| 1134 | |||
| 1135 | The wrap method returns a SQL-escaped string. | ||
| 1136 | |||
| 1137 | =over 4 | ||
| 1138 | |||
| 1139 | =item wrap example #1 | ||
| 1140 | |||
| 1141 | # given: synopsis | ||
| 1142 | |||
| 1143 | $grammar->wrap('field'); | ||
| 1144 | |||
| 1145 | # "field" | ||
| 1146 | |||
| 1147 | =back | ||
| 1148 | |||
| 1149 | =cut | ||
| 1150 | |||
| 1151 | =head1 AUTHOR | ||
| 1152 | |||
| 1153 | Al Newkirk, C<awncorp@cpan.org> | ||
| 1154 | |||
| 1155 | =head1 LICENSE | ||
| 1156 | |||
| 1157 | Copyright (C) 2011-2019, Al Newkirk, et al. | ||
| 1158 | |||
| 1159 | This is free software; you can redistribute it and/or modify it under the terms | ||
| 1160 | of the The Apache License, Version 2.0, as elucidated in the L<"license | ||
| 1161 | file"|https://github.com/iamalnewkirk/sql-engine/blob/master/LICENSE>. | ||
| 1162 | |||
| 1163 | =head1 PROJECT | ||
| 1164 | |||
| 1165 | L<Wiki|https://github.com/iamalnewkirk/sql-engine/wiki> | ||
| 1166 | |||
| 1167 | L<Project|https://github.com/iamalnewkirk/sql-engine> | ||
| 1168 | |||
| 1169 | L<Initiatives|https://github.com/iamalnewkirk/sql-engine/projects> | ||
| 1170 | |||
| 1171 | L<Milestones|https://github.com/iamalnewkirk/sql-engine/milestones> | ||
| 1172 | |||
| 1173 | L<Contributing|https://github.com/iamalnewkirk/sql-engine/blob/master/CONTRIBUTE.md> | ||
| 1174 | |||
| 1175 | L<Issues|https://github.com/iamalnewkirk/sql-engine/issues> | ||
| 1176 | |||
| 1177 | =cut |