DBIx::C...Generic(3)
π DBIx::C...Generic(3) β aka DBIx::Class::Storage::DBI::Oracle::Generic π
okay so bestie, gather round, because this page is literally the Oracle Support for DBIx::Class β¨ (that's the NAME, and yes it's the whole vibe of this file, no cap).
πΈ SYNOPSIS πΈ
here's the group chat of code examples, verbatim, do not touch:
# In your result (table) classes
use base 'DBIx::Class::Core';
__PACKAGE__->add_columns({ id => { sequence => 'mysequence', auto_nextval => 1 } });
__PACKAGE__->set_primary_key('id');
# Somewhere in your Code
# add some data to a table with a hierarchical relationship
$schema->resultset('Person')->create ({
firstname => 'foo',
lastname => 'bar',
children => [
{
firstname => 'child1',
lastname => 'bar',
children => [
{
firstname => 'grandchild',
lastname => 'bar',
}
],
},
{
firstname => 'child2',
lastname => 'bar',
},
],
});
# select from the hierarchical relationship
my $rs = $schema->resultset('Person')->search({},
{
'start_with' => { 'firstname' => 'foo', 'lastname' => 'bar' },
'connect_by' => { 'parentid' => { '-prior' => { -ident => 'personid' } },
'order_siblings_by' => { -asc => 'name' },
};
);
# this will select the whole tree starting from person "foo bar", creating
# following query:
# SELECT
# me.persionid me.firstname, me.lastname, me.parentid
# FROM
# person me
# START WITH
# firstname = 'foo' and lastname = 'bar'
# CONNECT BY
# parentid = prior personid
# ORDER SIBLINGS BY
# firstname ASC
(no i did NOT fix the persionid typos, that's literally what the source says, iykyk π
)
π¦ DESCRIPTION π¦
This class implements base Oracle support β like, the foundational Oracle stuff, the main character energy of Oracle storage π«Ά
The subclass DBIx::Class::Storage::DBI::Oracle::WhereJoins is the one for (+) joins in Oracle versions before 9.0. that's its whole personality, and we respect it.
π METHODS π
get_autoinc_seq
Returns the sequence name for an autoincrement column. slay, it tells you the sequence β¨
datetime_parser_type
This sets the proper DateTime::Format module for use with DBIx::Class::InflateColumn::DateTime. matching them up like the besties they are π
connect_call_datetime_setup
Used as:
on_connect_call => 'datetime_setup'
In connect_info to set the session nls date, and timestamp values for use with DBIx::Class::InflateColumn::DateTime and the necessary environment variables for DateTime::Format::Oracle, which is used by it. (yes it's the module that the module uses, we don't make the rules π§)
Maximum allowable precision is used, unless the environment variables have already been set β like, if you already set them, it respects you, lowkey iconic.
These are the defaults used:
$ENV{NLS_DATE_FORMAT} ||= 'YYYY-MM-DD HH24:MI:SS';
$ENV{NLS_TIMESTAMP_FORMAT} ||= 'YYYY-MM-DD HH24:MI:SS.FF';
$ENV{NLS_TIMESTAMP_TZ_FORMAT} ||= 'YYYY-MM-DD HH24:MI:SS.FF TZHTZM';
To get more than second precision with DBIx::Class::InflateColumn::DateTime for your timestamps, use something like this:
use Time::HiRes 'time';
my $ts = DateTime->from_epoch(epoch => time);
sub-second precision, she's thriving π
relname_to_table_alias
DBIx::Class uses DBIx::Class::Relationship names as table aliases in queries.
Unfortunately β and this is the sad part π β Oracle doesn't support identifiers over 30 chars in length, so the DBIx::Class::Relationship name is shortened and appended with half of an MD5 hash. half! of an MD5 hash! truncated name plus hash bits, that's the whole trick π
See "relname_to_table_alias" in DBIx::Class::Storage::DBI.
with_deferred_fk_checks
Runs a coderef between:
alter session set constraints = deferred
...
alter session set constraints = immediate
to defer foreign key checks. fancy π
β οΈ Constraints must be declared "DEFERRABLE" for this to work. fr fr, if they're not deferrable, this whole situation does not go.
π ATTRIBUTES π
Following additional attributes can be used in resultsets. yes, additional, there's more, keep going bestie π
connect_by or connect_by_nocycle
Value: \%connect_by
A hashref of conditions used to specify the relationship between parent rows and child rows of the hierarchy.
connect_by => { parentid => 'prior personid' }
# adds a connect by statement to the query:
# SELECT
# me.persionid me.firstname, me.lastname, me.parentid
# FROM
# person me
# CONNECT BY
# parentid = prior persionid
connect_by_nocycle => { parentid => 'prior personid' }
# adds a connect by statement to the query:
# SELECT
# me.persionid me.firstname, me.lastname, me.parentid
# FROM
# person me
# CONNECT BY NOCYCLE
# parentid = prior persionid
NOCYCLE is literally the one that says "bestie please, do not loop forever" π
start_with
Value: \%condition
A hashref of conditions which specify the root row(s) of the hierarchy. the starting point, the pilot episode, the origin story π±
It uses the same syntax as "search" in DBIx::Class::ResultSet
start_with => { firstname => 'Foo', lastname => 'Bar' }
# SELECT
# me.persionid me.firstname, me.lastname, me.parentid
# FROM
# person me
# START WITH
# firstname = 'foo' and lastname = 'bar'
# CONNECT BY
# parentid = prior persionid
order_siblings_by
Value: ($order_siblings_by | \@order_siblings_by)
Which column(s) to order the siblings by. one column or a whole arrayref, your call β¨
It uses the same syntax as "order_by" in DBIx::Class::ResultSet
'order_siblings_by' => 'firstname ASC'
# SELECT
# me.persionid me.firstname, me.lastname, me.parentid
# FROM
# person me
# CONNECT BY
# parentid = prior persionid
# ORDER SIBLINGS BY
# firstname ASC
π«Ά FURTHER QUESTIONS? π«Ά
Check the list of additional DBIC resources. that's it, that's the whole answer, go explore π¦
π COPYRIGHT AND LICENSE π
This module is free software copyright by the DBIx::Class (DBIC) authors. You can redistribute it and/or modify it under the same terms as the DBIx::Class library. π open source, we stan.
and that's the page, bestie π sign-off time: this was perl v5.42.0, dated 2025-01-22, and it's DBIx::C...Generic(3) β go forth and build your Oracle hierarchies, you're gonna eat π
π¦ where this page comes from
- opensuse-leap 16.0: perl-DBIx-Class 0.082844-bp160.1.10 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms