dbix-class

Convert a DBIx::Class::Result into a hash

吃可爱长大的小学妹 提交于 2019-12-02 06:30:56
问题 Using DBIx::Class, I found a solution to my issue, thankfully. But I'm sure there has to be a nicer way. my $record = $schema->resultset("food")->create({name=>"bacon"}); How would I turn this record into a simple hashref instead of having to make this call right after. my record = $schema->resultset("food")->search({name=>"bacon"})->hashref_array(); Ideally I want to be able to write a code snippet as simple as {record=> $record} instead of {record => {name => $record->name, $record->food_id

Convert a DBIx::Class::Result into a hash

。_饼干妹妹 提交于 2019-12-01 23:19:49
Using DBIx::Class, I found a solution to my issue, thankfully. But I'm sure there has to be a nicer way. my $record = $schema->resultset("food")->create({name=>"bacon"}); How would I turn this record into a simple hashref instead of having to make this call right after. my record = $schema->resultset("food")->search({name=>"bacon"})->hashref_array(); Ideally I want to be able to write a code snippet as simple as {record=> $record} instead of {record => {name => $record->name, $record->food_id, ...}} This would drive me insane with a table that has alot more columns. I assume you're talking

perl DBIx sqlite {sqlite_unicode=>1}?

允我心安 提交于 2019-11-30 23:20:40
If connecting to MySQL with: my $schema = MyDatabase::Main->connect("dbi:mysql:database=$database;host=$host",'root','', {mysql_enable_utf8 => 1}); The connection is forced to utf8; Connect to SQLite : my $schema = MyDatabase::Main->connect('dbi:SQLite:data/sample.db', {sqlite_unicode => 1}); The connection seems not to be in utf8; The purpose is to eliminate having to use decode() while fetching data: from: Mojo::ByteStream->new($cycle->type)->decode('utf-8') to: $cycle->type Thanks What if you connect with this: my $schema = MyDatabase::Main->connect( 'dbi:SQLite:data/sample.db', '', # empty

perl DBIx sqlite {sqlite_unicode=>1}?

旧巷老猫 提交于 2019-11-30 18:39:54
问题 If connecting to MySQL with: my $schema = MyDatabase::Main->connect("dbi:mysql:database=$database;host=$host",'root','', {mysql_enable_utf8 => 1}); The connection is forced to utf8; Connect to SQLite: my $schema = MyDatabase::Main->connect('dbi:SQLite:data/sample.db', {sqlite_unicode => 1}); The connection seems not to be in utf8; The purpose is to eliminate having to use decode() while fetching data: from: Mojo::ByteStream->new($cycle->type)->decode('utf-8') to: $cycle->type Thanks 回答1: What