简体   繁体   English

DBIx::Class::Schema::Loader dbicdump 是否可以为 JSYNC 自动添加序列化程序

[英]Is it possible for DBIx::Class::Schema::Loader dbicdump to auto add serializer for JSYNC

I'm running我在跑

dbicdump -o dump_directory=./lib \
          -o components='["InflateColumn::DateTime", "InflateColumn::Serializer"]' \
          -o debug=1 \
          -o db_schema=foo \
          -o qualify_objects=1 \
          Foo::Schema \
          'dbi:Pg:dbname=foo' username password

against a Postgres database with the hopes that the generated schema will generate the code necessary to inflate timestamp and JSON column types.针对 Postgres 数据库,希望生成的模式将生成膨胀时间戳和 JSON 列类型所需的代码。

Looking at the generated Schema files, I see the查看生成的 Schema 文件,我看到

__PACKAGE__->load_components("InflateColumn::Serializer", "InflateColumn::DateTime");

line, but now I have to add serializer_class => 'JSYNC' to each of the JSON columns I want to inflate and deflate.行,但现在我必须将serializer_class => 'JSYNC'添加到我想要充气和放气的每个 JSON 列中。

Is there a way to get dbicdump to do this automatically or is it expected practice to manually set these accessors?有没有办法让 dbicdump 自动执行此操作,或者手动设置这些访问器是预期的做法?

Thanks!谢谢!

Not sure this is possible from the dbicdump program, but if you use the the following perl program, you can do exactly what I want:不确定从 dbicdump 程序是否可行,但是如果您使用以下 perl 程序,您可以完全按照我的意愿进行操作:

#!/usr/bin/env perl
use strict;
use warnings;
use DBIx::Class::Schema::Loader qw/make_schema_at/;

make_schema_at(
    'Foo::Schema',
    {
        dump_directory => './lib',
        components     => [ "InflateColumn::Serializer", "InflateColumn::DateTime" ],
        db_schema      => 1,
        qualify_objects => 1,
        custom_column_info => sub {
            my ($table, $column_name, $column_info) = @_;
            if ( $column_info->{data_type} eq "json" ) {
                return { serializer_class => "JSYNC" };
            }
        },
    },
    [
         "dbi:Pg:dbname=foo',
         "username",
         "password"
     ]
);

Hope this saves someone some research time.希望这可以节省一些研究时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM