NAME

DBIx::Inline - DBIx::Class without the class.

DESCRIPTION

An "inline" version to DBIx::Class, but by no means an alternative or its equal in any sense. Due to boredom and too many classes lying around I put together DBIx::Inline to try and emulute some of DBIx::Class' cool features into one script. It's far from it, but I believe it's an OK work in progress. You can still create accessors, but they are done on the fly using DBIx::Inline::ResultSet->method(name => sub { ... }). Results have ->method, but the easiest way is to use $row->load_accessors, which will create methods for all of your result values (DBIx::Inline::Result) Check out the synopsis for more info on how to use DBIx::Inline.

SYNOPSIS

package main;

use base 'DBIx::Inline';

my $schema = main->connect(
    dbi => 'SQLite:test.db'
);

my $rs = $schema->resultset('my_user_table');

# create an accessor
$rs->method(not_active => sub {
    return shift->search([], { account_status => 'disabled' }, { order => ['id'], rows => 5 });
});

# chain the custom resultset method with a core one (count)
print "Rows returned: " . $rs->not_active->count . "\n";

# make the records in the resultset active
# will return a resultset with the updated data
my $new_rs = $rs->update({account_status => 'active'});

connect

Creates the Schema instance using the hash specified. Currently only dbi is mandatory, which tells DBI which engine to use (SQLite, Pg, etc). If you're using SQLite there is no need to set user or pass.

my $dbh = DBIx::Inline->connect(
    dbi => 'SQLite:/var/db/test.db',
);

my $dbh = DBIx::Inline->connect(
    dbi  => 'Pg:host=myhost;dbname=dbname',
    user => 'username',
    pass => 'password',
);

model

This method needs a lot of work, but it functions at the moment. And I like it. Instead of calling the connect method in every file, you can share the model by putting it in inline.yml, like so.

  # inline.yml
  ---
  Foo:
    connect: 'SQLite:foo.db'
  
  AnotherSchema:
    connect: 'Pg:host=localhost;dbname=foo'
    user: 'myuser'
    pass: 'pass'

  # test.pl
  package main;

  my $rs = main->model('AnotherSchema')->resultset('the_table');

AUTHOR

Brad Haywood <brad@geeksware.net>

LICENSE

Same license as Perl