NAME

DB::Object::Fields::Field - Table Field Object

SYNOPSIS

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" );

VERSION

0.1

DESCRIPTION

This is a table field object as instantiated by DB::Object::Fields

CONSTRUCTOR

new( %arg )

Creates a new DB::Object::Fields::Field objects. It may also take an hash like arguments, that also are method of the same name.

debug

Toggles debug mode on/off

METHODS

_find_siblings()

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.

as_string()

This returns the name of the field, possibly prefixed

database()

Returns the name of the database this field is attached to.

database_object()

Returns the database object, ie the one used to make sql queries

default()

Returns the default value, if any, for that field.

first()

Returns the first field in the table.

last()

Returns the last field in the table.

name()

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.

next()

Returns the next field object.

pos()

Returns the position of the field in the table. This is an integer starting from 1.

prefixed()

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.

prev()

Returns the previous field object.

schema()

Returns the table schema to which this field is attached.

table()

Returns the table name for this field.

table_name()

Same as above. This returns the table name.

table_object()

Returns the table object which is a DB::Object::Tables object.

type()

Returns the field type such as jsonb, Cjson>, varchar, integer, etc.

AUTHOR

Jacques Deguest <jack@deguest.jp>

SEE ALSO

perl

COPYRIGHT & LICENSE

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:

Around line 217:

You forgot a '=back' before '=head1'