从 Class::DBI 迁移到 DBIx::Class
我目前正在对 DBIx::Class 进行一些研究,以便从 Class::DBI 迁移我当前的应用程序。老实说,在配置结果类时,我对 DBIx::Class 有点失望,使用 Class::DBI 我可以通过调用 on 函数而不需要代码生成器来在模型上设置元数据,所以我的问题是。 ..我可以对 DBIX::Class 做同样的事情吗,而且 DBIx::Class 似乎不支持客户端触发器,或者我没有查看错误的文档?
I'm currently doing some research on DBIx::Class in order to migrate my current application from Class::DBI. Honestly I'm a bit disappointed about the DBIx::Class when it comes to configuring the result classes, with Class::DBI I could setup metadata on models just by calling the on function without a code generator and so on my question is ... can I the same thing with DBIX::Class also it seems that client-side triggers are not supported in DBIx::Class or i'm not looking at the wrong docs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以通过在 Result 类中重新定义适当的方法(new/create/update/delete 等)并调用父级(通过
$self->next::method()
)来实现触发器它,无论是在代码之前还是之后。不可否认,与 Class::DBI 中的之前/之后触发器相比,它有点笨拙。至于元数据 - 您是在谈论对象上的临时列吗?即不会存储在数据库行中的数据。这些可以使用 CPAN 上的 Class::Accessor::* 模块之一轻松添加。
从 CDBI 切换到 DBIC 时最困难的更改之一是根据结果集进行思考 - 通常是通过类方法实现的在 CDBI 中成为 ResultSet 上的一种方法 - 并且代码可能需要大量重构,它并不总是从一个到另一个的直接转换。
Triggers can be implemented by redefining the appropriate method (new/create/update/delete etc) in the Result class, and calling the parent (via
$self->next::method()
) within it, either before or after your code. Admittedly it's a bit clumsy compared to the before/after triggers in Class::DBI.As for metadata - are you talking about temporary columns on an object? i.e. data that won't be stored in the database row. These can be added easily using one of the Class::Accessor::* modules on CPAN
One of the hardest changes to make when switching from CDBI to DBIC is to think in terms of ResultSets - often what would have been implemented via a Class method in CDBI becomes a method on a ResultSet - and code may need to be refactored considerably, it's not always a straightforward conversion from one to the other.