为什么我收到错误消息?
#!/usr/bin/env perl
use warnings;
use 5.012;
use ORLite {
package => 'My::ORM',
file => 'sqlite_test.db',
create => sub {
my $dbh = shift;
$dbh->do('CREATE TABLE user ( name TEXT NOT NULL, age INTEGER )');
},
};
say My::ORM::User->table;
my $user = My::ORM::User->create( name => 'Alpha', age => 23, );
输出:
user
Can't locate object method "create" via package "My::ORM::User" at ./perl1.pl line 16.
答案 0 :(得分:3)
您正在尝试使用仅在具有PRIMARY KEY的表上可用的方法。
修复创建查询,这将起作用:
$dbh->do('CREATE TABLE user ( name TEXT PRIMARY KEY, age INTEGER )');
# ^^^^^^^^^^^