Apache...stgres(3pm)

πŸ’– Apache::Session::Store::Postgres πŸ’–

okay so bestie, you found the Apache...stgres(3pm) page, aka the manual for Apache::Session::Store::Postgres β€” a Perl module (a 3pm situation, for sure) that keeps your session data living rent-free in a Postgres database. let's get into it 🫢


✨ NAME ✨

Apache::Session::Store::Postgres β€” Store persistent data in a Postgres database πŸ’Ύ


🌸 SYNOPSIS 🌸

the vibe check, in code:

use Apache::Session::Store::Postgres;

my $store = new Apache::Session::Store::Postgres;

$store->insert($ref);
$store->update($ref);
$store->materialize($ref);
$store->remove($ref);

like, that's literally it. four little methods and you're iconic ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

Apache::Session::Store::Postgres fulfills the storage interface of Apache::Session. Session data is stored in a Postgres database.

periodt. that's the whole plot πŸ’…


πŸŽ€ SCHEMA πŸŽ€

To use this module, you will need at least these columns in a table called 'sessions', or another name if you supply the TableName parameter.

id char(32)     # or however long your session IDs are.
a_session text  # This has an ~8 KB limit :(
bestie. do you see that :( up there. that's not me being dramatic, that's the docs themselves being sad about the ~8 KB limit on a_session text. it's giving tiny storage. it's giving claustrophobic. πŸ’€

To create this schema, you can execute this command using the psql program:

CREATE TABLE sessions (
   id char(32) not null primary key,
   a_session text
);

If you use some other command, ensure that there is a unique index on the table's id column. do not skip that part, fr fr πŸ™ˆ


πŸ’œ CONFIGURATION πŸ’œ

The module must know what datasource, username, and password to use when connecting to the database. These values can be set using the options hash (see Apache::Session documentation). The options are:

  • DataSource
  • UserName
  • Password
  • Handle
  • TableName

🌈 Example 🌈

tie %hash, 'Apache::Session::Postgres', $id, {
    DataSource => 'dbi:Pg:dbname=database',
    UserName   => 'database_user',
    Password   => 'K00l'
};

Instead, you may pass in an already-opened DBI handle to your database.

tie %hash, 'Apache::Session::Postgres', $id, {
    Handle => $dbh
};

so you either hand it the deets and let it connect itself, or you hand it a $dbh you already opened. main character energy either way, your choice πŸ‘‘


⭐ AUTHOR ⭐

This modules was written by Jeffrey William Baker <jwbaker@acm.org>

A fix for the commit policy was contributed by Michael Schout <mschout@gkg.net>

shoutout to the legends who wrote it and to the one who fixed the commit policy 🫢 (yes the original says "This modules was written", we keep the facts exactly as they are, no cap)


πŸ”₯ SEE ALSO πŸ”₯

  • Apache::Session
  • Apache::Session::Store::DBI

go read those next, iykyk πŸ“š


and that's the whole page, bestie!! this one shipped as part of perl v5.36.0, dated 2022-11-19, and the manual page title is the delightfully abbreviated Apache...stgres(3pm) πŸŽ€ slay, you now know everything about storing session data in Postgres. go forth and CREATE TABLE. πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from