DBIx::Class
手柄布尔值:
负荷此组件和声明为博列齐墩果值。
package Table;
__PACKAGE__->load_components(qw/InflateColumn::Boolean Core/);
__PACKAGE__->table('table');
__PACKAGE__->true_is('Y');
__PACKAGE__->add_columns(
foo => {
data_type => 'varchar',
is_boolean => 1,
},
bar => {
data_type => 'varchar',
is_boolean => 1,
true_is => qr/^(?:yes|ja|oui|si)$/i,
},
baz => {
data_type => 'int',
is_boolean => 1,
false_is => ['0', '-1'],
},
);
然后你就可以把指定列的布尔:
print 'table.foo is ', $table->foo ? 'true' : 'false', "\n";
print 'table.bar is ', $table->bar ? 'true' : 'false', "\n";
布尔对象仍然stringifies实际字段值:
print $table->foo; # prints "Y" if it is true
UPD如何选择行其字段为真
因为DBIx::Class
使用SQL::Abstract
搜索与TRUE
值应该参考bool
元运算符字段:
my %where = (
-bool => 'is_user',
-not_bool => 'is_enabled',
);
会给你:
WHERE is_user AND NOT is_enabled
值得注意的是,DBIx :: Class将undef视为NULL。 – Blaskovicz