[Dbix-class] Defaulting a column by configuration

Bob MacCallum uncoolbob at gmail.com
Fri Jun 1 14:14:26 GMT 2012


On Fri, Jun 1, 2012 at 2:43 PM, Bill Moseley <moseley at hank.org> wrote:

> I have a time_zone column, but sadly it allows nulls.  Fixing the database
> would be the correct approach, but for now I'm looking at defaulting the
> column.  But, the default value depends on which database we are connected
> to.
>
> The result class is used in both a Catalyst app and in cron jobs.  Both
> the Catalyst app and the cron jobs pull the connect_info from a single
> config config, so the only thing I really have in common for all uses is
> connect_info.
>
> So, in the result class I can use "around time_zone =3D> sub {}" to set t=
he
> default
>
> One option is to just do a match on the database name in the dsn:
>
>  $self->result_source->storage->connect_info->[0]->{dsn}.
>
>
> but I can't be sure someone won't change that later.
>
> Now I'm looking at just adding a "default_time_zone" to connect_info and
> then inspecting:
>
> $self->result_source->storage->connect_info->[0]->{default_time_zone}.
>
> And then do:
>
> around time_zone =3D> sub {
>     my $orig =3D shift;
>     my $self =3D shift;
>     return $self->$orig( @_ )
> || $self->result_source->storage->connect_info->[0]->{default_time_zone};
> };
>
> Is there a more elegant solution to this?
>
> I don't like stuffing non-database args into connect_info, of course, but
> it seems like the only thing I have available in all my environments.
>

couldn't/shouldn't the default timezone be stored in the db, in a simple
key/value table called "meta" or similar?



>
> --
> Bill Moseley
> moseley at hank.org
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive:
> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120601/7b8=
c9c0a/attachment.htm


More information about the DBIx-Class mailing list