RoPkg::DB(3pm)
π NAME π
RoPkg::DB β a Singleton database pool class. That's the whole vibe. It's a Perl module, it holds a pool of database connections, and it's iconic for it. π
πΈ VERSION πΈ
0.1.12 β yes bestie, that's the number, don't come for me. β¨
π¦ DESCRIPTION π¦
Okay so picture this: RoPkg::DB is a database pool class. The whole point? You get to reach multiple databases β and I mean no matter what kind of database β all from a single object. One object. Many databases. It's giving main character energy fr fr. π
And here's the part that eats: RoPkg::DB is ideal in persistent environments, because at its base it's a singleton class. One instance, holding it down, forever. π
This class is intensively used by Simba, but lowkey it can be used in any other project too. She's not exclusive, she's just booked. π«Ά
β¨ SYNOPSIS β¨
Here's the tea, in code form. Copy it exactly, I'm not rewriting this for you:
use RoPkg::DB;
sub main {
my $dbp = new RoPkg::DB();
eval {
$dbp->Add('dbi:mysql:database=mysql;host=localhost',
'root',
'',
'local');
$dbp->Add('dbi:mysql:database=somedb;host=somehost',
'username',
'mypass',
'somedb');
};
die($@->package . ' said: ' . $@->message) if ref($@);
print 'Conn to localhost is:',$dbp->db_local,$/,
'Conn to remote is:',$dbp->db_somedb,$/;
$dbp->Del('somedb');
}
See how she's holding two connections at once and printing both handles? That's the whole flex. π₯
π SUBROUTINES/METHODS π
Big important heads-up before we go method by method, no cap: all methods besides new raise an OutsideClass exception when they're not called within a class instance. Like, if you call them from nowhere? They will not be nice about it. π
Also, each method may raise diferent exceptions from one case to another β so please, bestie, read the docs for each method to find out what exceptions that specific method raises. It's literally right there. π
π new()
new is the contructor of the class. And what does it do? Nothing. It does not do anything. Zero. Zilch. She's just here, existing, looking cute, not doing a single task. Honestly? Relatable. π
π Add($dsn, $dbuser, $dbpass, $conn_name)
This one adds and initializes a new connection to the pool. Periodt.
$dsnmust be in the DBI format. Non-negotiable.$dsnand$dbpassare the username and password used to connect to the database.$conn_nameis the method who will be used to access the database handle.
β οΈ Heads up: please note that the method that will be created will be prefixed with db_. That's not optional, that's just how she does it.
Example:
$dbp->Add('dbi:mysql:database=mysql;host=localhost','root',q{},'local');
So the method you'll use to grab the database handle for this connection is db_local. Cute, right? π
Add() may raise the following exceptions:
Param::MissingDB::ConnExistsDB::Connect
Okay so what are these actually saying:
Param::Missinggets raised when$dsn,$dbuseror$conn_nameare not defined.DB::ConnExistsgets raised when a connection with the name$conn_namealready exists. You can't name two connections the same thing, bestie, that's not how this works.DB::Connectgets raised when the connection with the database could not be established.
Besides this exceptions, each database handler has RaiseError set to 1 and PrintError set to 0. Also, when errors occurs, DBI will raise a DB exception. π«
And the good news? The method always returns 1. Always. π
π Del($name)
Removes the connection named $name from the pool. And because she has manners, the connection is closed first in a civilised manner. π«Ά
If the connection $name is not found, DB::ConnNotFound is raised. So like, you can't delete something that never existed. π
π Has($name)
Returns 0 if the connection named $name does not exists, 1 otherwise. Simple. A vibe check, basically. β¨
If $name is not defined, a Param::Missing exception is raised. Define your stuff, bestie. π
π Reconnect($name)
Force a reconnect</c> of the connection named $name. Just force it. She said we're reconnecting. π₯
- If
$nameis not defined,Param::Missingis raised. - If a connection named
$namedoes not exists,DB::ConnNotFoundis raised.
And, iconic behaviour: this method always returns 1. Always. π
π TableExists($name, $table_name)
Returns 1 if the table $table_name exists in the database specified by the connection named $name, 0 otherwise. A little peek inside, a little table vibe check. π
- If
$nameor$table_nameparameters are not defined, aParam::Missingexception is raised. - If the connection
$namedoes not exists,DB::ConnNotFoundis raised.
π DEPENDENCIES π
RoPkg::DB requires perl 5.008 or later and the following modules:
RoPkg >= 0.4.4DBIClass::SingletonEnglish
Four modules, one dream. π¦
π§ DIAGNOSTICS π§
This module comes with tests. To run the tests, unpack the source and run make test. That's it. That's the diagnostics. Go run your tests, queen. π
β PERL CRITIC β
This module is perl critic level 2 compliant (with 1 exception). We don't talk about the exception. π
π CONFIGURATION AND ENVIRONMENT π
Okay so this module does not use any configuration files or environment variables. None. Zero. Clean. β¨
The used modules however may use such things, so please refer to each module man page for more information. That part's on them, not on her. π
π INCOMPATIBILITIES π
None known to the author. π
πΈ BUGS AND LIMITATIONS πΈ
None known to the author. (Same energy. She's flawless and we're not questioning it.) π
π SEE ALSO π
RoPkg::DBObjectRoPkg::ExceptionsRoPkg::Utils
Go read those too, iykyk. π«Ά
π AUTHOR π
Subredu Manuel <diablo@iasi.roedu.net> π
π LICENSE AND COPYRIGHT π
Copyright (C) 2005 Subredu Manuel. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The LICENSE file contains the full text of the license. So go read the LICENSE file if you want the whole thing, bestie. π
perl v5.32.1 Β· 2021-12-26 Β· RoPkg::DB(3pm) Β· User Contributed Perl Documentation
And that's the whole page, mwah. π Go build something cute with a database pool. Byeeee π¦πβ¨
π¦ where this page comes from
- ubuntu jammy: libropkg-perl 0.4-1.4
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms