Class: Arel::Visitors::ToSql
- Inherits:
-
Object
- Object
- Arel::Visitors::ToSql
- Defined in:
- lib/arel_extensions/visitors/to_sql.rb
Constant Summary collapse
- COMMA =
', '
Instance Method Summary collapse
- #json_value(o, v) ⇒ Object
- #make_json_null ⇒ Object
-
#make_json_string(expr) ⇒ Object
Escape properly the string expression expr.
- #visit_Arel_Nodes_And(o, collector) ⇒ Object
- #visit_Arel_Nodes_As(o, collector) ⇒ Object
- #visit_Arel_Nodes_LessThan(o, collector) ⇒ Object
- #visit_Arel_Nodes_NotRegexp(o, collector) ⇒ Object
- #visit_Arel_Nodes_Or(o, collector) ⇒ Object
- #visit_Arel_Nodes_Regexp(o, collector) ⇒ Object
- #visit_ArelExtensions_InsertManager_BulkValues(o, collector) ⇒ Object
-
#visit_ArelExtensions_Nodes_Abs(o, collector) ⇒ Object
Math Functions.
- #visit_ArelExtensions_Nodes_Blank(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Case(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Case_Else(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Case_When(o, collector) ⇒ Object
-
#visit_ArelExtensions_Nodes_Cast(o, collector) ⇒ Object
comparators.
- #visit_ArelExtensions_Nodes_Ceil(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Coalesce(o, collector) ⇒ Object
-
#visit_ArelExtensions_Nodes_Concat(o, collector) ⇒ Object
String functions.
-
#visit_ArelExtensions_Nodes_DateAdd(o, collector) ⇒ Object
Date operations.
- #visit_ArelExtensions_Nodes_DateDiff(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_DateSub(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Downcase(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_FindInSet(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Floor(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Format(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_FormattedDate(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_FormattedNumber(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_GroupConcat(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_IDoesNotMatch(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_IMatches(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_IsNotNull(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_IsNull(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Json(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_JsonGroup(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Length(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_LevenshteinDistance(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Locate(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Log10(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Ltrim(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_MD5(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_NotBlank(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Power(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Rand(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_RegexpReplace(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Repeat(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Replace(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Round(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Rtrim(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Soundex(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Std(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Substring(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Sum(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Then(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Trim(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Union(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_UnionAll(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Upcase(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Variance(o, collector) ⇒ Object
Instance Method Details
#json_value(o, v) ⇒ Object
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 627 def json_value(o, v) case o.type_of_node(v) when :string Arel.when(v.is_null).then(make_json_null).else(make_json_string(v)) when :date s = v.format('%Y-%m-%d') Arel.when(s.is_null).then(make_json_null).else(make_json_string(s)) when :datetime s = v.format('%Y-%m-%dT%H:%M:%S') Arel.when(s.is_null).then(make_json_null).else(make_json_string(s)) when :time s = v.format('%H:%M:%S') Arel.when(s.is_null).then(make_json_null).else(make_json_string(s)) when :nil make_json_null else ArelExtensions::Nodes::Cast.new([v, :string]).coalesce(make_json_null) end end |
#make_json_null ⇒ Object
22 23 24 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 22 def make_json_null Arel.quoted('null') end |
#make_json_string(expr) ⇒ Object
Escape properly the string expression expr. Take care of escaping.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 8 def make_json_string expr Arel.quoted('"') \ + expr .coalesce('') .replace('\\', '\\\\') .replace('"', '\"') .replace("\b", '\b') .replace("\f", '\f') .replace("\n", '\n') .replace("\r", '\r') .replace("\t", '\t') \ + '"' end |
#visit_Arel_Nodes_And(o, collector) ⇒ Object
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 588 def visit_Arel_Nodes_And o, collector case o.children.length when 0 collector << '1 = 1' # but this should not happen when 1 collector = visit o.children[0], collector else collector << '(' o.children.each_with_index { |arg, i| if i != 0 collector << ') AND (' end collector = visit arg, collector } collector << ')' end collector end |
#visit_Arel_Nodes_As(o, collector) ⇒ Object
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 376 def visit_Arel_Nodes_As o, collector if o.left.respond_to?(:alias) o.left.alias = nil end if o.left.is_a?(Arel::Nodes::Binary) collector << '(' collector = visit o.left, collector collector << ')' else collector = visit o.left, collector end collector << ' AS ' collector = visit o.right, collector collector end |
#visit_Arel_Nodes_LessThan(o, collector) ⇒ Object
556 557 558 559 560 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 556 def visit_Arel_Nodes_LessThan o, collector collector = visit o.left, collector collector << ' < ' visit o.right, collector end |
#visit_Arel_Nodes_NotRegexp(o, collector) ⇒ Object
401 402 403 404 405 406 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 401 def visit_Arel_Nodes_NotRegexp o, collector collector = visit o.left, collector collector << ' NOT REGEXP ' collector = visit o.right, collector collector end |
#visit_Arel_Nodes_Or(o, collector) ⇒ Object
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 608 def visit_Arel_Nodes_Or o, collector case o.children.length when 0 collector << '1 = 0' # but this should not happen when 1 collector = visit o.children[0], collector else collector << '(' o.children.each_with_index { |arg, i| if i != 0 collector << ') OR (' end collector = visit arg, collector } collector << ')' end collector end |
#visit_Arel_Nodes_Regexp(o, collector) ⇒ Object
393 394 395 396 397 398 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 393 def visit_Arel_Nodes_Regexp o, collector collector = visit o.left, collector collector << ' REGEXP ' collector = visit o.right, collector collector end |
#visit_ArelExtensions_InsertManager_BulkValues(o, collector) ⇒ Object
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 465 def visit_ArelExtensions_InsertManager_BulkValues o, collector collector << 'VALUES ' row_nb = o.left.length o.left.each_with_index do |row, idx| collector << '(' len = row.length - 1 row.zip(o.cols).each_with_index { |(value, attr), i| case value when Arel::Nodes::SqlLiteral, Arel::Nodes::BindParam collector = visit value, collector else collector << quote(value, attr && column_for(attr)).to_s end collector << COMMA unless i == len } collector << (idx == row_nb - 1 ? ')' : '), ') end collector end |
#visit_ArelExtensions_Nodes_Abs(o, collector) ⇒ Object
Math Functions
27 28 29 30 31 32 33 34 35 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 27 def visit_ArelExtensions_Nodes_Abs o, collector collector << 'ABS(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Blank(o, collector) ⇒ Object
258 259 260 261 262 263 264 265 266 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 258 def visit_ArelExtensions_Nodes_Blank o, collector # visit o.left.coalesce('').trim.length.eq(0), collector collector << 'LENGTH(TRIM(COALESCE(' collector = visit o.expr, collector collector << COMMA collector = visit Arel.quoted(''), collector collector << '))) = 0' collector end |
#visit_ArelExtensions_Nodes_Case(o, collector) ⇒ Object
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 522 def visit_ArelExtensions_Nodes_Case o, collector collector << 'CASE ' if o.case visit o.case, collector collector << ' ' end o.conditions.each do |condition| visit condition, collector collector << ' ' end if o.default visit o.default, collector collector << ' ' end collector << 'END' end |
#visit_ArelExtensions_Nodes_Case_Else(o, collector) ⇒ Object
546 547 548 549 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 546 def visit_ArelExtensions_Nodes_Case_Else o, collector collector << 'ELSE ' visit Arel.quoted(o.expr), collector end |
#visit_ArelExtensions_Nodes_Case_When(o, collector) ⇒ Object
539 540 541 542 543 544 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 539 def visit_ArelExtensions_Nodes_Case_When o, collector collector << 'WHEN ' visit Arel.quoted(o.left), collector collector << ' THEN ' visit Arel.quoted(o.right), collector end |
#visit_ArelExtensions_Nodes_Cast(o, collector) ⇒ Object
comparators
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 320 def visit_ArelExtensions_Nodes_Cast o, collector as_attr = case o.as_attr when :binary then 'binary' when :datetime then 'datetime' when :decimal, :float, :number then 'float' when :int then 'int' when :string then 'char' when :text, :ntext then 'text' when :time then 'time' else o.as_attr.to_s end collector << 'CAST(' collector = visit o.left, collector collector << ' AS ' collector = visit Arel::Nodes::SqlLiteral.new(as_attr), collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Ceil(o, collector) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 37 def visit_ArelExtensions_Nodes_Ceil o, collector collector << 'CEIL(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Coalesce(o, collector) ⇒ Object
341 342 343 344 345 346 347 348 349 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 341 def visit_ArelExtensions_Nodes_Coalesce o, collector collector << 'COALESCE(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Concat(o, collector) ⇒ Object
String functions
102 103 104 105 106 107 108 109 110 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 102 def visit_ArelExtensions_Nodes_Concat o, collector collector << 'CONCAT(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_DateAdd(o, collector) ⇒ Object
Date operations
455 456 457 458 459 460 461 462 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 455 def visit_ArelExtensions_Nodes_DateAdd o, collector collector << 'DATE_ADD(' collector = visit o.left, collector collector << COMMA collector = visit o.sqlite_value(o.right), collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_DateDiff(o, collector) ⇒ Object
351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 351 def visit_ArelExtensions_Nodes_DateDiff o, collector collector << if o.left_node_type == :ruby_time || o.left_node_type == :datetime || o.left_node_type == :time 'TIMEDIFF(' else 'DATEDIFF(' end collector = visit o.left, collector collector << COMMA collector = visit o.right, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_DateSub(o, collector) ⇒ Object
365 366 367 368 369 370 371 372 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 365 def visit_ArelExtensions_Nodes_DateSub o, collector collector << 'DATE_SUB(' collector = visit o.left, collector collector << COMMA collector = visit o.right, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Downcase(o, collector) ⇒ Object
208 209 210 211 212 213 214 215 216 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 208 def visit_ArelExtensions_Nodes_Downcase o, collector collector << 'LOWER(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_FindInSet(o, collector) ⇒ Object
188 189 190 191 192 193 194 195 196 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 188 def visit_ArelExtensions_Nodes_FindInSet o, collector collector << 'FIND_IN_SET(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Floor(o, collector) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 47 def visit_ArelExtensions_Nodes_Floor o, collector collector << 'FLOOR(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Format(o, collector) ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 278 def visit_ArelExtensions_Nodes_Format o, collector case o.col_type when :date, :datetime, :time collector << 'STRFTIME(' collector = visit o.right, collector collector << COMMA collector = visit o.left, collector collector << ')' when :integer, :float, :decimal collector << 'FORMAT(' collector = visit o.left, collector collector << COMMA collector = visit o.right, collector collector << ')' else collector = visit o.left, collector end collector end |
#visit_ArelExtensions_Nodes_FormattedDate(o, collector) ⇒ Object
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 298 def visit_ArelExtensions_Nodes_FormattedDate o, collector case o.col_type when :date, :datetime, :time collector << 'STRFTIME(' collector = visit o.right, collector collector << COMMA collector = visit o.left, collector collector << ')' when :integer, :float, :decimal collector << 'FORMAT(' collector = visit o.left, collector collector << COMMA collector = visit o.right, collector collector << ')' else collector = visit o.left, collector end collector end |
#visit_ArelExtensions_Nodes_FormattedNumber(o, collector) ⇒ Object
551 552 553 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 551 def visit_ArelExtensions_Nodes_FormattedNumber o, collector visit o.left, collector end |
#visit_ArelExtensions_Nodes_GroupConcat(o, collector) ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 112 def visit_ArelExtensions_Nodes_GroupConcat o, collector collector << 'GROUP_CONCAT(' collector = visit o.left, collector if o.separator && o.separator != 'NULL' collector << COMMA collector = visit o.separator, collector end collector << ')' collector end |
#visit_ArelExtensions_Nodes_IDoesNotMatch(o, collector) ⇒ Object
418 419 420 421 422 423 424 425 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 418 def visit_ArelExtensions_Nodes_IDoesNotMatch o, collector collector = infix_value o, collector, ' NOT ILIKE ' if o.escape collector << ' ESCAPE ' collector = visit o.escape, collector end collector end |
#visit_ArelExtensions_Nodes_IMatches(o, collector) ⇒ Object
408 409 410 411 412 413 414 415 416 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 408 def visit_ArelExtensions_Nodes_IMatches o, collector collector = infix_value o, collector, ' ILIKE ' if o.escape collector << ' ESCAPE ' visit o.escape, collector else collector end end |
#visit_ArelExtensions_Nodes_IsNotNull(o, collector) ⇒ Object
434 435 436 437 438 439 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 434 def visit_ArelExtensions_Nodes_IsNotNull o, collector collector << 'NOT ISNULL(' collector = visit o.expr, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_IsNull(o, collector) ⇒ Object
427 428 429 430 431 432 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 427 def visit_ArelExtensions_Nodes_IsNull o, collector collector << 'ISNULL(' collector = visit o.expr, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Json(o, collector) ⇒ Object
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 647 def visit_ArelExtensions_Nodes_Json o, collector case o.dict when Array res = Arel.quoted('[') o.dict.each.with_index do |v, i| if i != 0 res += ', ' end res += json_value(o, v) end res += ']' collector = visit res, collector when Hash res = Arel.quoted('{') o.dict.each.with_index do |(k, v), i| if i != 0 res += ', ' end res += make_json_string(ArelExtensions::Nodes::Cast.new([k, :string])) + ': ' res += json_value(o, v) end res += '}' collector = visit res, collector else collector = visit o.dict, collector end collector end |
#visit_ArelExtensions_Nodes_JsonGroup(o, collector) ⇒ Object
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 676 def visit_ArelExtensions_Nodes_JsonGroup o, collector if o.as_array res = Arel.quoted('[') \ + (o.orders ? o.dict.group_concat(', ', order: Array(o.orders)) : o.dict.group_concat(', ')).coalesce('') \ + ']' collector = visit res, collector else res = Arel.quoted('{') orders = o.orders || o.dict.keys o.dict.each.with_index do |(k, v), i| if i != 0 res = res + ', ' end kv = make_json_string(ArelExtensions::Nodes::Cast.new([k, :string])) + ': ' kv += json_value(o, v) res = res + kv.group_concat(', ', order: Array(orders)).coalesce('') end res = res + '}' collector = visit res, collector end collector end |
#visit_ArelExtensions_Nodes_Length(o, collector) ⇒ Object
130 131 132 133 134 135 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 130 def visit_ArelExtensions_Nodes_Length o, collector collector << "#{o.bytewise ? '' : 'CHAR_'}LENGTH(" collector = visit o.left, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_LevenshteinDistance(o, collector) ⇒ Object
576 577 578 579 580 581 582 583 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 576 def visit_ArelExtensions_Nodes_LevenshteinDistance o, collector collector << 'LEVENSHTEIN_DISTANCE(' collector = visit o.left, collector collector << COMMA collector = visit o.right, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Locate(o, collector) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 137 def visit_ArelExtensions_Nodes_Locate o, collector collector << 'LOCATE(' collector = visit o.right, collector collector << COMMA collector = visit o.left, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Log10(o, collector) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 77 def visit_ArelExtensions_Nodes_Log10 o, collector collector << 'LOG10(' collector = visit o.left, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Ltrim(o, collector) ⇒ Object
238 239 240 241 242 243 244 245 246 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 238 def visit_ArelExtensions_Nodes_Ltrim o, collector collector << 'LTRIM(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_MD5(o, collector) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 123 def visit_ArelExtensions_Nodes_MD5 o, collector collector << 'MD5(' collector = visit o.left, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_NotBlank(o, collector) ⇒ Object
268 269 270 271 272 273 274 275 276 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 268 def visit_ArelExtensions_Nodes_NotBlank o, collector # visit o.left.coalesce('').trim.length.gt(0), collector collector << 'LENGTH(TRIM(COALESCE(' collector = visit o.expr, collector collector << COMMA collector = visit Arel.quoted(''), collector collector << '))) > 0' collector end |
#visit_ArelExtensions_Nodes_Power(o, collector) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 84 def visit_ArelExtensions_Nodes_Power o, collector collector << 'POW(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Rand(o, collector) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 57 def visit_ArelExtensions_Nodes_Rand o, collector collector << 'RAND(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_RegexpReplace(o, collector) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 167 def visit_ArelExtensions_Nodes_RegexpReplace o, collector collector << 'REGEXP_REPLACE(' visit o.left, collector collector << COMMA visit Arel.quoted(o.pattern.to_s), collector collector << COMMA visit o.substitute, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Repeat(o, collector) ⇒ Object
178 179 180 181 182 183 184 185 186 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 178 def visit_ArelExtensions_Nodes_Repeat o, collector collector << 'REPEAT(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Replace(o, collector) ⇒ Object
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 156 def visit_ArelExtensions_Nodes_Replace o, collector collector << 'REPLACE(' visit o.left, collector collector << COMMA visit o.pattern, collector collector << COMMA visit o.substitute, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Round(o, collector) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 67 def visit_ArelExtensions_Nodes_Round o, collector collector << 'ROUND(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Rtrim(o, collector) ⇒ Object
248 249 250 251 252 253 254 255 256 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 248 def visit_ArelExtensions_Nodes_Rtrim o, collector collector << 'RTRIM(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Soundex(o, collector) ⇒ Object
198 199 200 201 202 203 204 205 206 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 198 def visit_ArelExtensions_Nodes_Soundex o, collector collector << 'SOUNDEX(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Std(o, collector) ⇒ Object
562 563 564 565 566 567 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 562 def visit_ArelExtensions_Nodes_Std o, collector collector << 'STD(' visit o.left, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Substring(o, collector) ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 146 def visit_ArelExtensions_Nodes_Substring o, collector collector << 'SUBSTRING(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Sum(o, collector) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 94 def visit_ArelExtensions_Nodes_Sum o, collector collector << 'SUM(' collector = visit o.expr, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Then(o, collector) ⇒ Object
441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 441 def visit_ArelExtensions_Nodes_Then o, collector collector << 'CASE WHEN (' collector = visit o.left, collector collector << ') THEN ' collector = visit o.right, collector if o.expressions[2] collector << ' ELSE ' collector = visit o.expressions[2], collector end collector << ' END' collector end |
#visit_ArelExtensions_Nodes_Trim(o, collector) ⇒ Object
228 229 230 231 232 233 234 235 236 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 228 def visit_ArelExtensions_Nodes_Trim o, collector collector << 'TRIM(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Union(o, collector) ⇒ Object
508 509 510 511 512 513 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 508 def visit_ArelExtensions_Nodes_Union o, collector collector = visit o.left, collector collector << ' UNION ' collector = visit o.right, collector collector end |
#visit_ArelExtensions_Nodes_UnionAll(o, collector) ⇒ Object
515 516 517 518 519 520 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 515 def visit_ArelExtensions_Nodes_UnionAll o, collector collector = visit o.left, collector collector << ' UNION ALL ' collector = visit o.right, collector collector end |
#visit_ArelExtensions_Nodes_Upcase(o, collector) ⇒ Object
218 219 220 221 222 223 224 225 226 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 218 def visit_ArelExtensions_Nodes_Upcase o, collector collector << 'UPPER(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Variance(o, collector) ⇒ Object
569 570 571 572 573 574 |
# File 'lib/arel_extensions/visitors/to_sql.rb', line 569 def visit_ArelExtensions_Nodes_Variance o, collector collector << 'VARIANCE(' visit o.left, collector collector << ')' collector end |