DB::Object::Fields::Field - Table Field Object
my $dbh = DB::Object->connect({ driver => 'Pg', conf_file => $conf, database => 'my_shop', host => 'localhost', login => 'super_admin', schema => 'auth', # debug => 3, }) || bailout( "Unable to connect to sql server on host localhost: ", DB::Object->error ); my $tbl_object = $dbh->customers || die( "Unable to get the customers table object: ", $dbh->error, "\n" ); my $fields = $tbl_object->fields; print( "Fields for table \"", $tbl_object->name, "\": ", Dumper( $fields ), "\n" ); my $c = $tbl_object->fo->currency; print( "Got field object for currency: \"", ref( $c ), "\": '$c'\n" ); printf( "Name: %s\n", $c->name ); printf( "Type: %s\n", $c->type ); printf( "Default: %s\n", $c->default ); printf( "Position: %s\n", $c->pos ); printf( "Table: %s\n", $c->table ); printf( "Database: %s\n", $c->database ); printf( "Schema: %s\n", $c->schema ); printf( "Next field: %s (%s)\n", $c->next, ref( $c->next ) ); print( "Showing name fully qualified: ", $c->prefixed( 3 )->name, "\n" ); ## would print: my_shop.public.customers.currency print( "Trying again (should keep prefix): ", $c->name, "\n" ); ## would print again: my_shop.public.customers.currency print( "Now cancel prefixing at the table fields level.\n" ); $tbl_object->fo->prefixed( 0 ); print( "Showing name fully qualified again (should not be prefixed): ", $c->name, "\n" ); ## would print currency print( "First element is: ", $c->first, "\n" ); print( "Last element is: ", $c->last, "\n" );
0.1
This is a table field object as instantiated by DB::Object::Fields
DB::Object::Fields
Creates a new DB::Object::Fields::Field objects. It may also take an hash like arguments, that also are method of the same name.
DB::Object::Fields::Field
Toggles debug mode on/off
Given a field position from 1 to n, this will find and return the field object. It returns undef or empty list if none could be found.
This returns the name of the field, possibly prefixed
Returns the name of the database this field is attached to.
Returns the database object, ie the one used to make sql queries
Returns the default value, if any, for that field.
Returns the first field in the table.
Returns the last field in the table.
Returns the field name. This is also what is returned when object is stringified. For example
my $c = $tbl_object->fo->last_name; print( "$c\n" ); ## will produce "last_name"
The output is altered by the use of prefixed. See below.
Returns the next field object.
Returns the position of the field in the table. This is an integer starting from 1.
Called without argument, this will instruct the field name to be returned prefixed by the table name.
print( $tbl_object->fo->last_name->prefixed, "\n" ); ## would produce my_shop.last_name
prefixed can also be called with an integer as argument. 1 will prefix it with the table name, 2 with the schema name and 3 with the database name.
Returns the previous field object.
Returns the table schema to which this field is attached.
Returns the table name for this field.
Same as above. This returns the table name.
Returns the table object which is a DB::Object::Tables object.
DB::Object::Tables
Returns the field type such as jsonb, Cjson>, varchar, integer, etc.
jsonb
varchar
integer
Jacques Deguest <jack@deguest.jp>
perl
Copyright (c) 2020 DEGUEST Pte. Ltd.
All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install DB::Object, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DB::Object
CPAN shell
perl -MCPAN -e shell install DB::Object
For more information on module installation, please visit the detailed CPAN module installation guide.