DBIx::...:Epoch(3pm)

πŸ“¦
version 0.10 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– DBIx::...:Epoch πŸ’–

okay so bestie, gather round, because this is a page from the User Contributed Perl Documentation and it's literally about the module DBIx::Class::DateTime::Epoch πŸ’… she's a lil gem and we're gonna go through her together, no skipping, no skimming, we do this right 🫢


✨ NAME ✨

DBIx::Class::DateTime::Epoch β€” Automatic inflation/deflation of epoch-based columns to/from DateTime objects 🌸

like. it takes your boring raw epoch numbers and turns them into gorgeous DateTime objects and then puts them back. that's the whole vibe. and it does it automatically, which is the slay part πŸ’…


🌈 SYNOPSIS 🌈

package MySchema::Foo;

use base qw( DBIx::Class );

__PACKAGE__->load_components( qw( DateTime::Epoch TimeStamp Core ) );
__PACKAGE__->add_columns(
    name => {
        data_type => 'varchar',
        size      => 10,
    },
    bar => { # epoch stored as an int
        data_type        => 'bigint',
        inflate_datetime => 1,
    },
    baz => { # epoch stored as a string
        data_type        => 'varchar',
        size             => 50,
        inflate_datetime => 'epoch',
    },
    # working in conjunction with DBIx::Class::TimeStamp
    creation_time => {
        data_type        => 'bigint',
        inflate_datetime => 1,
        set_on_create    => 1,
    },
    modification_time => {
        data_type        => 'bigint',
        inflate_datetime => 1,
        set_on_create    => 1,
        set_on_update    => 1,
    }
);

see how bar is an int and baz is a varchar? both of them get the inflate_datetime treatment, they just get there different ways πŸ‘‘ and then creation_time and modification_time are out here working in conjunction with DBIx::Class::TimeStamp, living their best lives, setting themselves on create and update 😌✨


πŸ¦‹ DATETIME::FORMAT DEPENDENCY πŸ¦‹

not me having to be the responsible one for a sec: no assumptions have been made about which RDBMS you're using πŸ™ˆ

so, as per the note over in the DBIx::Class::InflateColumn::DateTime documentation β€” yes, go read her, she's the parent here β€” you will need to install the DateTime::Format::* module that matches your RDBMS of choice. like, the one that goes with your database. that one. install it. periodt πŸ’–


🌸 DESCRIPTION 🌸

This module automatically inflates/deflates DateTime objects from/to epoch values for the columns you specify ✨ She is, at her core, an extension to DBIx::Class::InflateColumn::DateTime, so all of those settings β€” including "locale" and "timezone" β€” are also valid here. everything she can do, this one can do too. nepotism but make it useful πŸ’…

A column gets recognized as an epoch time given one of the following scenarios:

  • "data_type" is an "int" of some sort and "inflate_datetime" is also set to a true value 🌟
  • "data_type" is some other value (e.g. "varchar") and "inflate_datetime" is explicitly set to "epoch" 🌟

and DBIx::Class::TimeStamp can also be used in conjunction with this module to support epoch-based columns that are automatically set on creation of a row and updated on subsequent modifications πŸŽ€ like a little timestamp fairy that never forgets 🧚


πŸ‘‘ METHODS πŸ‘‘

add_columns( )

Provides backwards compatibility with the older DateTime::Epoch API. she remembers her roots πŸ’œ

_inflate_to_datetime( )

Overrides column inflation to use Datetime->from_epoch. yes, that's Datetime with a lowercase s in there, bestie, we copy exactly what's written, no cap 😭

_deflate_from_datetime( )

Overrides column deflation to call epoch() on the column value. so it goes back to being a number. she contains multitudes πŸ”₯


⭐ SEE ALSO ⭐

  • DBIx::Class
  • DBIx::Class::TimeStamp
  • DateTime

iykyk, these three are the whole friend group πŸ’–


πŸ’œ AUTHORS πŸ’œ

  • Brian Cassidy <bricas@cpan.org>
  • Adam Paynter <adapay@cpan.org>

two icons. we stan. πŸ‘‘


Copyright 2006-2012 by Brian Cassidy

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

(that's the legal bit, and yes it's giving very official, but it's important so we keep it word for word πŸ’…)


okay that's the whole page!! and for the lil sign-off moment: this lovely thing is documented in perl v5.34.0, dated 2022-06-13, and the manual page lives under the name DBIx::...:Epoch(3pm) πŸ¦‹βœ¨ go inflate something, bestie πŸ’–

πŸ“¦ where this page comes from