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

_______________________________________________
Koha-devel mailing list
Koha-devel@lists.koha.org
http://lists.koha.org/mailman/listinfo/koha-devel

Reply via email to