[Dbix-class] DBIx Class - Creating on the fly tables

Rob Kinyon rob.kinyon at gmail.com
Fri Dec 16 13:03:34 GMT 2011


On Fri, Dec 16, 2011 at 06:37, Peter Rabbitson <rabbit+dbic at rabbit.us> wrote:
> Rohan M wrote:
>>
>> Hi All,
>>
>>   I came up against a situation where I need to create table based on user
>> input file (lets say csv).   How can I create on the fly tables using
>> DBIx::Class considering the column numbers are varying with each user file?
>>
>> This is something very similar of having mysql temporary table and loading
>> a file into the table using load command.
>>
>> Could anybody give me directions/points on how to go about ?
>>
>
> What is it exactly you are trying to do? You already described how
> would you normally do it, there is no reason to shoehorn this into
> DBIC just for the sake of it (DBIC being a tool, not a framework).
>
> Clarify your objective for more specific help :)

I think the idea is that I have some $schema that was created either
via a set of classes on disk or Schema::Loader. I now have a need for
a new source, possible a temporary table or a view, that I will be
working with for a while. This source may need to have relationships
with existing sources. I definitely want to be able to ->search() over
it (as ->search() is a very powerful tool). I definitely want
::ResultSet and ::Row objects.

The point is that there isn't some sane way of injecting a new source
into the schema without replicating a lot of work that
::Schema->connect() does. A proposed API could be:

$schema->add_source({
    $source_name => {
        table => $table_name, # What would be passed to __PACKAGE__->table()
        columns => { ... }, # What would be passed to __PACKAGE__->add_columns()
        relationships => { ... } # optional hash of relationships
        result_methods => { ... } # optional hash of name/subrefs
providing methods to be installed
        resultset_methods => { ... } # optional hash of name/subrefs
providing methods to be installed
    },
});

And add_source() just DWIMs.

Rob



More information about the DBIx-Class mailing list