Subject: [Dbix-class] Re: using as normal perl module To

Fernan Aguero fernan.aguero at gmail.com
Mon Aug 1 19:16:29 GMT 2011


On Mon, Aug 1, 2011 at 4:01 PM, Rajeev Prasad <rp.neuli at yahoo.com> wrote:
> for using DBIx, I am not sure what i need to do and what i can do (so new i
> am to this).
>
>
> i have found this page, it is a wonderful resource to me (thanks to author),
> it has demystified quite a few things about how to start. It is saying very
> clearly that:
> "To use DBIC you first need to setup your Schema - the logical model of the
> database tables, views and relationships....."
>
> so i tried:
> i have this mysql database with few tables in it:
> according to author, after i run this script i should have a directory
> structure in my current (or specified) folder, for all my tables and
> database. When i run the following code, I get no error, but no output
> either. can anyone help plz?
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use DBIx::Class::Schema::Loader qw/make_schema_at/;
>
> make_schema_at(
>     'mytestdb::Schema',
>     {debug => 0, dump_directory => '../db/',
>     generate_pod => 0,},
>     ['dbi:mysql:robodb:localhost:3306', 'root', 'sqlpassowrd']',
> );
>
>
> i want to create that directory structure one dir above (from where my
> script is), hence i want to use ../db/   (../db/ does not exist yet.)
>
> thank you.
> Rajeev

Rajeev,

this is how I did it.

First, create a minimal module, defining access to your db (e.g. mydb.pm)

mydb.pm:
package mydb;

use strict;
use warnings;

use base 'DBIx::Class::Schema::Loader';

# set these before running
my $dbname = '';
my $dbuser = '';
my $dbpass = '';
my $dbhost = '';

__PACKAGE__->loader_options( relationships	=> 1 );

__PACKAGE__->connection(
	"dbi:mysql:dbname=$dbname:host=$dbhost",
	"$dbuser",
	"$dbpass" );

1;


Then call perl using this module, as in:
perl -MDBIx::Class::Schema::Loader=dump_to_dir:/path/to/your/app/lib/ -Mmydb -e1

dump_to_dir should point to your app's 'lib' directory. This is where
you want the schema (a new directory called 'mydb' will be created and
all your classes (one per table) will appear here).

you have to run this command from the same directory where your mydb.pm file is.

Good luck,

-- 
fernan



More information about the DBIx-Class mailing list