Showing 1 changed files with 71 additions and 24 deletions
+71 -24
lib/DBIx/Custom/QueryBuilder/TagProcessor.pm
... ...
@@ -40,75 +40,122 @@ sub in {
40 40
     croak qq{Column and count of values must be specified in tag "{in }"}
41 41
       unless $column && $count && $count =~ /^\d+$/;
42 42
 
43
-    # Expand
44
-    my $expand = "$column in (";
43
+    # Part of statement
44
+    my $s = "$column in (";
45 45
     for (my $i = 0; $i < $count; $i++) {
46
-        $expand .= '?, ';
46
+        $s .= '?, ';
47 47
     }
48
-    $expand =~ s/, $//;
49
-    $expand .= ')';
48
+    $s =~ s/, $//;
49
+    $s .= ')';
50 50
     
51 51
     # Columns
52 52
     my $columns = [];
53 53
     push @$columns, $column for (0 .. $count - 1);
54 54
     
55
-    return [$expand, $columns];
55
+    return [$s, $columns];
56 56
 }
57 57
 
58 58
 sub insert {
59 59
     my @columns = @_;
60 60
     
61
-    # Insert
62
-    my $expand = '(';
63
-    $expand .= "$_, " for @columns;
64
-    $expand =~ s/, $//;
65
-    $expand .= ') ';
66
-    $expand .= 'values (';
67
-    $expand .= "?, " for @columns;
68
-    $expand =~ s/, $//;
69
-    $expand .= ')';
61
+    # Part of insert statement
62
+    my $s = '(';
63
+    $s .= "$_, " for @columns;
64
+    $s =~ s/, $//;
65
+    $s .= ') ';
66
+    $s .= 'values (';
67
+    $s .= "?, " for @columns;
68
+    $s =~ s/, $//;
69
+    $s .= ')';
70 70
     
71
-    return [$expand, \@columns];
71
+    return [$s, \@columns];
72 72
 }
73 73
 
74 74
 sub update {
75 75
     my @columns = @_;
76 76
     
77
-    # Update
78
-    my $expand = 'set ';
79
-    $expand .= "$_ = ?, " for @columns;
80
-    $expand =~ s/, $//;
77
+    # Part of update statement
78
+    my $s = 'set ';
79
+    $s .= "$_ = ?, " for @columns;
80
+    $s =~ s/, $//;
81 81
     
82
-    return [$expand, \@columns];
82
+    return [$s, \@columns];
83 83
 }
84 84
 
85 85
 1;
86 86
 
87 87
 =head1 NAME
88 88
 
89
-DBIx::Custom::SQLBuilder::TagProcessors - Tag processor
90
-
91
-=head1 FUNCTIONS
89
+DBIx::Custom::SQLBuilder::TagProcessors - Tag processors
90
+
91
+=head1 Processors
92
+
93
+Processor is function,
94
+which receive arguments and return a part of SQL statment
95
+and column names.
96
+The part of SQL statment contains placeholders.
97
+the count of placeholders must be
98
+same as the count of column names.
99
+
100
+    sub processor_name {
101
+        my @args = @_;
102
+        
103
+        # Part of statment, which constains placeholders
104
+        my $s;
105
+        
106
+        # Column names
107
+        my $columns = [];
108
+        
109
+        # Do something
110
+        # ...
111
+        
112
+        return [$s, $columns];
113
+    }
92 114
 
93 115
 =head2 C<placeholder>
94 116
 
117
+    ('NAME')  ->  ['?', ['NAME']]
118
+
95 119
 =head2 C<equal>
96 120
 
121
+    ('NAME')  ->  ['NAME = ?', ['NAME']]
122
+
97 123
 =head2 C<not_equal>
98 124
 
125
+    ('NAME')  ->  ['NAME <> ?', ['NAME']]
126
+
99 127
 =head2 C<greater_than>
100 128
 
129
+    ('NAME')  ->  ['NAME > ?', ['NAME']]
130
+
101 131
 =head2 C<lower_than>
102 132
 
133
+    ('NAME')  ->  ['NAME < ?', ['NAME']]
134
+
103 135
 =head2 C<greater_than_equal>
104 136
 
137
+    ('NAME')  ->  ['NAME >= ?', ['NAME']]
138
+
105 139
 =head2 C<lower_than_equal>
106 140
 
141
+    ('NAME')  ->  ['NAME <= ?', ['NAME']]
142
+
107 143
 =head2 C<like>
108 144
 
145
+    ('NAME')  ->  ['NAME like ?', ['NAME']]
146
+
109 147
 =head2 C<in>
110 148
 
149
+    ('NAME', 3)  -> ['NAME in (?, ?, ?)', ['NAME', 'NAME', 'NAME']]
150
+
111 151
 =head2 C<insert>
112 152
 
153
+    ('NAME1', 'NAME2')
154
+      ->  ['(NAME1, NAME2) values (?, ?, ?)', ['NAME1', 'NAME2']]
155
+
113 156
 =head2 C<update>
114 157
 
158
+    ('NAME1', 'NAME2')
159
+      ->  ['set NAME1 = ?, NAME2 = ?', ['NAME1', 'NAME2']]
160
+
161
+=cut