[Koha-devel] [RFC: DBIx::Class 1/3] DBIx::Class - new C4::Schema object

Andrew Moore andrew.moore at liblime.com
Fri Oct 24 16:10:42 CEST 2008


This first patch contains a C4::Schema object, which is a subclass of a
DBIx::Class class that reads the database and figures out the schema from there.
It can eventually be our interface into the database, replacing the SQL that we write.

There are other ways to write this. Alternative suggestions are encouraged.

---
 C4/Schema.pm |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
 create mode 100644 C4/Schema.pm

diff --git a/C4/Schema.pm b/C4/Schema.pm
new file mode 100644
index 0000000..aa4f9a6
--- /dev/null
+++ b/C4/Schema.pm
@@ -0,0 +1,20 @@
+package C4::Schema;
+use base qw/DBIx::Class::Schema::Loader/;
+
+__PACKAGE__->loader_options(
+    debug => 0,
+);
+
+my $context = C4::Context->new();
+
+my $db_driver = 'mysql';
+my $db_name   = $context->config('database');
+my $db_host   = $context->config('hostname');
+my $db_port   = $context->config('port') || '';
+my $db_user   = $context->config('user');
+my $db_passwd = $context->config('pass');
+
+__PACKAGE__->connection( "DBI:$db_driver:dbname=$db_name;host=$db_host;port=$db_port",
+                         $db_user, $db_passwd);
+
+1;
-- 
1.5.6




More information about the Koha-devel mailing list