【问题标题】:dbix::class generate schema for a non-catalyst appdbix::class 为非催化剂应用程序生成模式
【发布时间】:2012-08-21 02:51:44
【问题描述】:

我最近一直在构建 Catalyst 应用程序,我喜欢的一件事是使用 Catalyst 的创建脚本轻松地为 DBIx::Class 生成表模式。我希望能够使用 DBIX::Class 而不必手动为我的表编写模式。有没有办法做到这一点而不用手做?谢谢!

【问题讨论】:

    标签: perl schema catalyst dbix-class


    【解决方案1】:

    DBIx::Class::Schema::Loaderdbicdump 脚本可用于转储模式。文档中的一个示例:

    dbicdump -o dump_directory=./lib \
             -o components='["InflateColumn::DateTime"]' \
             -o debug=1 \
             My::Schema \
             'dbi:Pg:dbname=foo' \
             myuser \
             mypassword
    

    【讨论】:

    • 完美!正是我想要的。谢谢! :)
    • 转储模式,甚至根本不需要用户定义模式。下面的例子演示了 D:C:S:L 的工作方式与 DBIC 相同,只是交易了一点启动时间:@​​987654325@
    【解决方案2】:

    另一个更通用的模块是SQL::Translator

    【讨论】:

      【解决方案3】:
      #!/usr/bin/env perl
      
      use Modern::Perl;
      use DBIx::Class::Schema::Loader 'make_schema_at';
      
      my $DEBUG = @ARGV and $ARGV[0] =~ /^\-[\-]*v/;
      
      say $DBIx::Class::Schema::Loader::VERSION if $DEBUG;
      my @dsn = 'dbi:Pg:dbname=yourDB.db';
      
      my $options = {
      debug          => $DEBUG,
      dump_directory => 'lib',
      components     => [qw/ InflateColumn::DateTime /],
      generate_pod   => 0,
      };
      
      make_schema_at(Schema => $options, \@dsn);
      
      =head1 NAME
      
      generate_dbic_schema
      
      =head1 USAGE
      
      perl generate_dbic_schema
      
      =cut
      

      【讨论】:

        猜你喜欢
        • 2012-08-10
        • 1970-01-01
        • 2021-10-18
        • 2013-01-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-25
        • 2022-08-17
        相关资源
        最近更新 更多