DBIx::Skinny
スキーマクラス
package MyDB;
use DBIx::Skinny setup =>
{ dsn => 'dbi:Pg:dbname=test_db;host=localhost', username => 'liberty', password => '' };
package MyDB::Schema;
use DBIx::Skinny::Schema;
install_table users => schema {
pk 'id';
columns qw/id name birth_on group_id/;
};
install_table groups => schema {
pk 'id';
columns qw/id name/;
};
普通にSELECT
use MyDB;
use Perl6::Say;
my $db = MyDB->new;
my $row = $db->search('users', {name => 'taro'})->first;
say $row->id;
say $row->name;
SQLを手で書いてSELECT
use Perl6::Say;
my $db = MyDB->new;
my $row = $db->search_by_sql(
"SELECT * FROM users WHERE name = ?",
['taro'],
'users' # 結果セットオブジェクトの基準テーブルを指定
)->first;
say $row->id;
say $row->name;