Plack:...e::DBI(3pm)

πŸ’– Plack::Session::Store::DBI πŸ’–

okay bestie, so this is the User Contributed Perl Documentation page for Plack::Session::Store::DBI (it's a 3pm manual, iykyk) and honestly?? it's giving "sessions but make it a database" and I'm obsessed. let's get into it 🫢


✨ NAME ✨

Plack::Session::Store::DBI β€” a session store that's all about that DBI life. literally a session store backed by DBI. no cap. πŸ’…


🌸 SYNOPSIS 🌸

here's the whole vibe, copied exactly because details are sacred:

use Plack::Builder;
use Plack::Middleware::Session;
use Plack::Session::Store::DBI;

my $app = sub {
    return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ];
};

builder {
    enable 'Session',
        store => Plack::Session::Store::DBI->new(
            dbh => DBI->connect( @connect_args )
        );
    $app;
};

# set get_dbh callback for ondemand

builder {
    enable 'Session',
        store => Plack::Session::Store::DBI->new(
            get_dbh => sub { DBI->connect( @connect_args ) }
        );
    $app;
};

# with custom serializer/deserializer

builder {
    enable 'Session',
        store => Plack::Session::Store::DBI->new(
            dbh => DBI->connect( @connect_args )
            # YAML takes its args in the opposite order
            serializer   => sub { YAML::DumpFile( reverse @_ ) },
            deserializer => sub { YAML::LoadFile( @_ ) },
        );
    $app;
};

# use custom session table name, session ID or data columns

builder {
    enable 'Session',
        store => Plack::Session::Store::DBI->new(
            dbh         => DBI->connect( @connect_args ),
            table_name  => 'my_session_table',
            id_column   => 'session_id',
            data_column => 'data',
        );
    $app;
};

like, yes ma'am, four whole flavors and every single one of them slays πŸ’…βœ¨


πŸ¦‹ DESCRIPTION πŸ¦‹

so this module implements DBI-based storage for your session data. that's the whole thing, bestie. πŸ’–

by default it uses Storable and MIME::Base64 to serialize and deserialize the data β€” but don't worry, you can configure that super easily if Storable isn't your main character.

also, important: this is a subclass of Plack::Session::Store and it implements its full interface. so everything you'd expect from that parent class? it's here. periodt. πŸ‘‘


πŸŽ€ SESSION TABLE SCHEMA πŸŽ€

okay so your session table HAS to have at least this structure, minimum, no negotiating:

CREATE TABLE sessions (
    id           CHAR(72) PRIMARY KEY,
    session_data TEXT
);
⚠️ the tea: MySQL TEXT fields only store 64KB. so if your session data is gonna exceed that size, you'll want to move to MEDIUMTEXT, MEDIUMBLOB, or larger. don't get caught out there with a too-small column, that's embarrassing fr fr 😭

you can also opt to specify alternative table names (using table_name), plus alternative columns for the session ID (id_column) and for session data storage (data_column). this is especially useful if you're converting from an existing session mechanism β€” lowkey iconic behavior honestly 🌈


🧚 EXTENDING 🧚

Plack::Session::Store::DBI has built-in functionality so that inheriting modules can set additional columns on each session row. so if you wanna be extra (and you should πŸ’…), this is your moment.

by overriding the additional_column_data function, you can return a hash of columns and values to set. and here's the cute part β€” the session data hashref gets passed to the overridden additional_column_data function as its only argument, so you can use session data values as appropriate for any additional column data you would like to set. data-driven customization, she's a genius 🫢✨


πŸ‘‘ AUTHORS πŸ‘‘

many aspects of this module were partially based upon Catalyst::Plugin::Session::Store::DBI β€” giving credit where credit is due, we love to see it.

Daisuke Maki


Copyright 2009, 2010 Daisuke Maki "<daisuke@endeworks.jp>"

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


πŸ’œ SEE ALSO energy: technically this page doesn't ship a SEE ALSO section, but bestie the family tree is right there in the text β€” Plack::Session::Store, Plack::Middleware::Session, Plack::Builder, Storable, MIME::Base64, and Catalyst::Plugin::Session::Store::DBI. go say hi to your cousins. 😌

and that's the whole page, no notes. this was Plack::Session::Store::DBI, 3pm, brought to you by User Contributed Perl Documentation β€” page generated by perl v5.40.1 on 2025-08-10. thanks for coming to my ted talk, slay responsibly, and hydrate bestie πŸ’–πŸŒΈπŸ¦‹πŸŽ€βœ¨

πŸ“¦ where this page comes from