Commit | Line | Data |
ea2e61bf |
1 | package DBIx::Class::SQL; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use base qw/Class::Data::Inheritable/; |
7 | |
8 | use constant COLS => 0; |
9 | use constant FROM => 1; |
10 | use constant COND => 2; |
11 | |
34d52be2 |
12 | =head1 NAME |
13 | |
14 | DBIx::Class::SQL - SQL Specific methods for DBIx::Class |
15 | |
16 | =head1 SYNOPSIS |
17 | |
18 | =head1 DESCRIPTION |
19 | |
20 | This class contains methods that generates SQL queries for |
21 | the rest of the L<DBIx::Class> hiarchy. It's also responsible |
22 | for executing these. |
23 | |
24 | =cut |
25 | |
ea2e61bf |
26 | __PACKAGE__->mk_classdata('_sql_statements', |
27 | { |
28 | 'select' => |
8fe001e1 |
29 | sub { "SELECT ".join(', ', @{$_[COLS]})." FROM $_[FROM] WHERE $_[COND]"; }, |
ea2e61bf |
30 | 'update' => |
8b445e33 |
31 | sub { "UPDATE $_[FROM] SET $_[COLS] WHERE $_[COND]"; }, |
ea2e61bf |
32 | 'insert' => |
8fe001e1 |
33 | sub { "INSERT INTO $_[FROM] (".join(', ', @{$_[COLS]}).") VALUES (". |
34 | join(', ', map { '?' } @{$_[COLS]}).")"; }, |
ea2e61bf |
35 | 'delete' => |
36 | sub { "DELETE FROM $_[FROM] WHERE $_[COND]"; }, |
37 | } ); |
38 | |
8b445e33 |
39 | sub create_sql { |
ea2e61bf |
40 | my ($class, $name, $cols, $from, $cond) = @_; |
8fe001e1 |
41 | my $sql = $class->_sql_statements->{$name}->($cols, $from, $cond); |
9bc6db13 |
42 | #warn $sql; |
8fe001e1 |
43 | return $sql; |
ea2e61bf |
44 | } |
45 | |
8b445e33 |
46 | *_get_sql = \&create_sql; |
47 | |
ea2e61bf |
48 | 1; |
34d52be2 |
49 | |
50 | =head1 AUTHORS |
51 | |
52 | Matt S. Trout <perl-stuff@trout.me.uk> |
53 | |
54 | =head1 LICENSE |
55 | |
56 | You may distribute this code under the same terms as Perl itself. |
57 | |
58 | =cut |