• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

lib/Class/DBI/H03-Sep-2005-23665

t/H03-Sep-2005-8653

ChangesH A D03-Sep-20052.6 KiB9066

INSTALLH A D11-Oct-2003450 118

MANIFESTH A D03-Sep-2005181 1110

META.ymlH A D03-Sep-2005431 1412

Makefile.PLH A D11-Oct-2003876 3827

READMEH A D03-Sep-20054.1 KiB12689

README

1NAME
2    Class::DBI::mysql - Extensions to Class::DBI for MySQL
3
4SYNOPSIS
5      package Film;
6      use base 'Class::DBI::mysql';
7      __PACKAGE__->set_db('Main', 'dbi:mysql:dbname', 'user', 'password');
8      __PACKAGE__->set_up_table("film");
9
10      __PACKAGE__->autoinflate(dates => 'Time::Piece');
11
12      # Somewhere else ...
13
14      my $type = $class->column_type('column_name');
15      my @allowed = $class->enum_vals('column_name');
16
17      my $tonights_viewing  = Film->retrieve_random;
18
19DESCRIPTION
20    This is an extension to Class::DBI, containing several functions and
21    optimisations for the MySQL database. Instead of setting Class::DBI as
22    your base class, use this instead.
23
24METHODS
25  set_up_table
26            __PACKAGE__->set_up_table("table_name");
27
28    Traditionally, to use Class::DBI, you have to set up the columns:
29
30            __PACKAGE__->columns(All => qw/list of columns/);
31            __PACKAGE__->columns(Primary => 'column_name');
32
33    Whilst this allows for more flexibility if you're going to arrange your
34    columns into a variety of groupings, sometimes you just want to create
35    the 'all columns' list. Well, this information is really simple to
36    extract from MySQL itself, so why not just use that?
37
38    This call will extract the list of all the columns, and the primary key
39    and set them up for you. It will die horribly if the table contains no
40    primary key, or has a composite primary key.
41
42  autoinflate
43      __PACKAGE__->autoinflate(column_type => 'Inflation::Class');
44
45      __PACKAGE__->autoinflate(timestamp => 'Time::Piece');
46      __PACKAGE__->autoinflate(dates => 'Time::Piece');
47
48    This will automatically set up has_a() relationships for all columns of
49    the specified type to the given class.
50
51    We currently assume that all classess passed will be able to inflate and
52    deflate without needing extra has_a arguments, with the example of
53    Time::Piece objects, which we deal with using Time::Piece::mysql (which
54    you'll have to have installed!).
55
56    The special type 'dates' will autoinflate all columns of type date,
57    datetime or timestamp.
58
59  create_table
60            $class->create_table(q{
61                    name    VARCHAR(40)     NOT NULL PRIMARY KEY,
62                    rank    VARCHAR(20)     NOT NULL DEFAULT 'Private',
63                    serial  INTEGER         NOT NULL
64            });
65
66    This creates the table for the class, with the given schema. If the
67    table already exists we do nothing.
68
69    A typical use would be:
70
71            Music::CD->table('cd');
72            Music::CD->create_table(q{
73              cdid   MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
74              artist MEDIUMINT UNSIGNED NOT NULL,
75                    title  VARCHAR(255),
76                    year   YEAR,
77                    INDEX (artist),
78                    INDEX (title)
79            });
80            Music::CD->set_up_table;
81
82  drop_table
83            $class->drop_table;
84
85    Drops the table for this class, if it exists.
86
87  column_type
88            my $type = $class->column_type('column_name');
89
90    This returns the 'type' of this table (VARCHAR(20), BIGINT, etc.)
91
92  enum_vals
93            my @allowed = $class->enum_vals('column_name');
94
95    This returns a list of the allowable values for an ENUM column.
96
97  retrieve_random
98            my $film = Film->retrieve_random;
99
100    This will select a random row from the database, and return you the
101    relevant object.
102
103    (MySQL 3.23 and higher only, at this point)
104
105SEE ALSO
106    Class::DBI. MySQL (http://www.mysql.com/)
107
108AUTHOR
109    Tony Bowden
110
111BUGS and QUERIES
112    Please direct all correspondence regarding this module to:
113    bug-Class-DBI-mysql@rt.cpan.org
114
115COPYRIGHT AND LICENSE
116      Copyright (C) 2001-2005 Tony Bowden.
117
118      This program is free software; you can redistribute it and/or modify it under
119      the terms of the GNU General Public License; either version 2 of the License,
120      or (at your option) any later version.
121
122      This program is distributed in the hope that it will be useful, but WITHOUT
123      ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
124      FOR A PARTICULAR PURPOSE.
125
126