Most of the first third of 02-Film now works :)
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Test / SQLite.pm
CommitLineData
ea2e61bf 1package DBIx::Class::Test::SQLite;
2
3=head1 NAME
4
5DBIx::Class::Test::SQLite - Base class for DBIx::Class tests, shamelessly ripped from Class::DBI::Test::SQLite
6
7=head1 SYNOPSIS
8
9 use base 'DBIx::Class::Test::SQLite';
10
11 __PACKAGE__->set_table('test');
12 __PACKAGE__->columns(All => qw/id name film salary/);
13
14 sub create_sql {
15 return q{
16 id INTEGER PRIMARY KEY,
17 name CHAR(40),
18 film VARCHAR(255),
19 salary INT
20 }
21 }
22
23=head1 DESCRIPTION
24
25This provides a simple base class for DBIx::Class tests using SQLite.
26Each class for the test should inherit from this, provide a create_sql()
27method which returns a string representing the SQL used to create the
28table for the class, and then call set_table() to create the table, and
29tie it to the class.
30
31=cut
32
33use strict;
34
35use base 'DBIx::Class';
36use File::Temp qw/tempfile/;
37my (undef, $DB) = tempfile();
38END { unlink $DB if -e $DB }
39
40my @DSN = ("dbi:SQLite:dbname=$DB", '', '', { AutoCommit => 1 });
41
42__PACKAGE__->connection(@DSN);
8fe001e1 43#__PACKAGE__->set_sql(_table_pragma => 'PRAGMA table_info(__TABLE__)');
44#__PACKAGE__->set_sql(_create_me => 'CREATE TABLE __TABLE__ (%s)');
ea2e61bf 45
46=head1 METHODS
47
48=head2 set_table
49
50 __PACKAGE__->set_table('test');
51
52This combines creating the table with the normal DBIx::Class table()
53call.
54
55=cut
56
57sub set_table {
58 my ($class, $table) = @_;
59 $class->table($table);
60 $class->_create_test_table;
61}
62
63sub _create_test_table {
64 my $class = shift;
8fe001e1 65 my @vals = $class->_sql_to_sth(
66 'PRAGMA table_info(__TABLE__)')->select_row;
67 $class->_sql_to_sth(
68 'CREATE TABLE '.$class->table.' ('.$class->create_sql.')'
69 )->execute unless @vals;
ea2e61bf 70}
71
72=head2 create_sql (abstract)
73
74 sub create_sql {
75 return q{
76 id INTEGER PRIMARY KEY,
77 name CHAR(40),
78 film VARCHAR(255),
79 salary INT
80 }
81 }
82
83This should return, as a text string, the schema for the table represented
84by this class.
85
86=cut
87
88sub create_sql { die "create_sql() not implemented by $_[0]\n" }
89
901;