SineSwiper has asked for the wisdom of the Perl Monks concerning the following question:

Am I daft for asking for a DBIx::Class::Storage::DBI::FusionTables module? Or one that can handle CSV files? I'm trying to marry data from CSV, Oracle, and Fusion Tables together for mapping. I'm still trying to wrap my brain around DBIx::Class, but it seems like a good fit for this sort of thing. Plus, if the Storage model changes (like moving the Fusion stuff to Oracle or visa-versa), I can easily switch it out without much code changes.

I've looked into just writing the module, but I'm having real hard time figuring out a good starting place. Fusion Tables has a SQL interface, but it's limited, and I don't know exactly which subs I would need to edit to say "Feature isn't supported, etc." There's also the matter of OAuth, which ties into the Fusion Tables.

Is this a better fit for Catalyst with Catalyst::Model::DBIC::Schema? Not exactly sure where to start here...

Replies are listed 'Best First'.
Re: DBIx::Class and Google Fusion Tables
by onelesd (Pilgrim) on Aug 26, 2011 at 23:26 UTC

    From what you've described, all you need is DBIx::Class (and perhaps some of it's other modules) to abstract the databases. You can have multiple handles to all of your databases and pull them together in an OO interface. You don't need Catalyst or anything else, unless you want a framework.

    You will want to read up on DBIx::Class, I think. Especially read about DBIx::Class::ResultSet, since this is where the meat and potatoes is, and where it really started to click for me personally.

    You might also be interested in dbicdump to write a lot of the OO interface for you. It's part of the DBIx::Class modules.

      Do you have any code examples? I guess I'm still having trouble understanding how it all links together. The ResultSet methods look like what you do when you have everything together, but I guess I'm still trying to figure out the initialization piece.

      For example, let's say we have data pieces as such:

      • Oracle: Table_A - Key1, Data_A; Table_B - Key1, Key2, Data_B
      • CSV: Table_C - Key2, Data_C
      • Fusion: Table_D - Key1, Data_D

      So, how would the code look to tie these relationships together? Do all of the interfaces require a DBD module (Fusion doesn't have one)? Do they need an SQL interface (CSV doesn't have one unless you use something like DBD::CSV)? Does Fusion require a DBIx::Class::Storage module to write data to it?

      I'm also going to be throwing SNMP into the mix, which doesn't have either. I'm thinking of writing a DBD::SNMP one, anyway. But, I need to know if it's going to be useful for this project.

      Also, since this would be a web application, I figured Catalyst would also be appropriate. Hopefully, Catalyst::Model::DBIC::Schema is going to link nicely with everything else in DBIx::Class.

        There are a number of things I would need to know about your project to feel comfortable recommending one framework, module, or approach over another, but I'll try and explain DBIx::Class so you can make a decision on how to proceed.

        First thing to do is to create the object code which will let you access the data and give you back DBIx::Class objects. In DBIx:Class, a table = a DBIx::Class::ResultSource. So what the commands below do is look at your database schemas and create the code which will let you access each table as a ResultSource. Great, now you have a way to get all of the objects (rows) from each ResultSource (table). Any time you ask the database for some data, you will now get back a DBIx::Class::ResultSet.

        Now, in your application you can do whatever you need with each ResultSource - maybe you do some stuff in memory and print a report, maybe you create another database and import all of your data into a unified schema, I'm not sure what your goal is, but hopefully this helps you understand how DBIx::Class may help you.

        dbicdump -o dump_directory=./lib -o preserve_case=1 MyApp::MySQLSchema + dbi:mysql:DB_Name user password dbicdump -o dump_directory=./lib -o preserve_case=1 MyApp::OracleSchem +a dbi:oracle:DB_Name user password
        use MyApp::MySQLSchema ; use MyApp::OracleSchema ; our $schema_mysql = MyApp::MySQLSchema->connect( sub { # code that ret +urns a DBI handle } ) ; our $schema_oracle = MyApp::OracleSchema->connect( sub { # code that r +eturns another DBI handle } ) ; my $company = $schema_mysql->resultset('Company')->find($company_id) ; + # get 1 row/object my $widget = $company->find_related('widgets', $widget_id) ; # get 1 r +elated row/object my $parts = $widget->search_related('widget_parts', { in_stock => 1 }) + ; # get all matching related rows/object my $r = $widget->create_related('widget_part', { # create a row comments => $comments, creation_time => time(), }) ; $schema_mysql->txn_do( sub { $r->insert() ; $r->update() ; }) ;