| 1 | package Eve::PgSql; | ||
| 2 | |||
| 3 | 9 | ▶ | use parent qw(Eve::Class); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 9 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 9 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 9 | ▶ | use Eve::PgSqlConnection; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 9 | ▶ | use Eve::PgSqlFunction; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 0 | ▶ | use Eve::PgSqlType::Array; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 11 | use Eve::PgSqlType::Bigint; | ||
| 12 | use Eve::PgSqlType::Boolean; | ||
| 13 | use Eve::PgSqlType::Double; | ||
| 14 | use Eve::PgSqlType::DoubleArray; | ||
| 15 | use Eve::PgSqlType::Geometry; | ||
| 16 | use Eve::PgSqlType::Integer; | ||
| 17 | use Eve::PgSqlType::IntegerArray; | ||
| 18 | use Eve::PgSqlType::Interval; | ||
| 19 | use Eve::PgSqlType::Smallint; | ||
| 20 | use Eve::PgSqlType::Text; | ||
| 21 | use Eve::PgSqlType::Timestamp; | ||
| 22 | use Eve::PgSqlType::TimestampWithTimeZone; | ||
| 23 | |||
| 24 | =head1 NAME | ||
| 25 | |||
| 26 | B<Eve::PgSql> - the PostgreSQL factory. | ||
| 27 | |||
| 28 | =head1 SYNOPSIS | ||
| 29 | |||
| 30 | use Eve::PgSql; | ||
| 31 | |||
| 32 | # Construct a factory instance | ||
| 33 | my $pgsql = Eve::PgSql->new( | ||
| 34 | database => $database, | ||
| 35 | host => $host, | ||
| 36 | port => $port, | ||
| 37 | user => $user, | ||
| 38 | password => $password, | ||
| 39 | schema => $schema); | ||
| 40 | |||
| 41 | # Create a function instance | ||
| 42 | my $foo = $pgsql->get_function( | ||
| 43 | name => 'foo', | ||
| 44 | input_list => [ | ||
| 45 | {'bar' => $pgsql->get_bigint()}, | ||
| 46 | {'foo' => $pgsql->get_smallint()}], | ||
| 47 | output_list => [ | ||
| 48 | {'baz' => $pgsql->get_text()}, | ||
| 49 | {'bam' => $pgsql->get_timestamp_with_timezome()}]); | ||
| 50 | |||
| 51 | =head1 DESCRIPTION | ||
| 52 | |||
| 53 | B<Eve::PgSql> is a factory providing services to interact with | ||
| 54 | PostgreSQL databases and common dependencies between these services. | ||
| 55 | |||
| 56 | =head3 Constructor arguments | ||
| 57 | |||
| 58 | =over 4 | ||
| 59 | |||
| 60 | =item C<database> | ||
| 61 | |||
| 62 | =item C<host> | ||
| 63 | |||
| 64 | =item C<port> | ||
| 65 | |||
| 66 | =item C<user> | ||
| 67 | |||
| 68 | =item C<password> | ||
| 69 | |||
| 70 | =item C<schema> | ||
| 71 | |||
| 72 | =back | ||
| 73 | |||
| 74 | By default all arguments are C<undef> so the database adapter will | ||
| 75 | attempt to use standard PostgreSQL environment variables. | ||
| 76 | |||
| 77 | =head1 METHODS | ||
| 78 | |||
| 79 | =head2 B<init()> | ||
| 80 | |||
| 81 | =cut | ||
| 82 | |||
| 83 | sub init { | ||
| 84 | my ($self, %arg_hash) = @_; | ||
| 85 | Eve::Support::arguments( | ||
| 86 | \%arg_hash, | ||
| 87 | my ($database, $host, $port, $user, $password, $schema) = (\undef) x 6); | ||
| 88 | |||
| 89 | $self->{'database'} = $database; | ||
| 90 | $self->{'host'} = $host; | ||
| 91 | $self->{'port'} = $port; | ||
| 92 | $self->{'user'} = $user; | ||
| 93 | $self->{'password'} = $password; | ||
| 94 | $self->{'schema'} = $schema; | ||
| 95 | |||
| 96 | return; | ||
| 97 | } | ||
| 98 | |||
| 99 | =head2 B<get_connection()> | ||
| 100 | |||
| 101 | A PostgreSQL connection lazy loader service. | ||
| 102 | |||
| 103 | =cut | ||
| 104 | |||
| 105 | sub get_connection { | ||
| 106 | my $self = shift; | ||
| 107 | |||
| 108 | if (not exists $self->{'_connection'}) { | ||
| 109 | $self->{'_connection'} = Eve::PgSqlConnection->new( | ||
| 110 | database => $self->database, | ||
| 111 | host => $self->host, | ||
| 112 | port => $self->port, | ||
| 113 | user => $self->user, | ||
| 114 | password => $self->password, | ||
| 115 | schema => $self->schema); | ||
| 116 | } | ||
| 117 | |||
| 118 | return $self->_connection; | ||
| 119 | } | ||
| 120 | |||
| 121 | =head2 B<get_function()> | ||
| 122 | |||
| 123 | A PostgreSQL stored function prototype service. | ||
| 124 | |||
| 125 | =head3 Arguments | ||
| 126 | |||
| 127 | =over 4 | ||
| 128 | |||
| 129 | =item C<name> | ||
| 130 | |||
| 131 | a stored function name | ||
| 132 | |||
| 133 | =item C<input_list> | ||
| 134 | |||
| 135 | an optional list of input parameters, each of which is specified as a | ||
| 136 | structure like | ||
| 137 | |||
| 138 | {'parameter_name' => $parameter_type} | ||
| 139 | |||
| 140 | where the C<$parameter_type> is a B<Eve::PgSqlType> derivative. | ||
| 141 | |||
| 142 | =item C<output_list> | ||
| 143 | |||
| 144 | an optional list of output parameters specified, just like the | ||
| 145 | C<input_list> argument. | ||
| 146 | |||
| 147 | =back | ||
| 148 | |||
| 149 | =cut | ||
| 150 | |||
| 151 | sub get_function { | ||
| 152 | my $self = shift; | ||
| 153 | |||
| 154 | return Eve::PgSqlFunction->new(connection => $self->get_connection, @_); | ||
| 155 | } | ||
| 156 | |||
| 157 | =head2 B<get_bigint()> | ||
| 158 | |||
| 159 | A PostgreSQL bigint type lazy loader service. | ||
| 160 | |||
| 161 | =cut | ||
| 162 | |||
| 163 | sub get_bigint { | ||
| 164 | my $self = shift; | ||
| 165 | |||
| 166 | if (not exists $self->{'_bigint'}) { | ||
| 167 | $self->{'_bigint'} = Eve::PgSqlType::Bigint->new(); | ||
| 168 | } | ||
| 169 | |||
| 170 | return $self->_bigint; | ||
| 171 | } | ||
| 172 | |||
| 173 | =head2 B<get_boolean()> | ||
| 174 | |||
| 175 | A PostgreSQL boolean type lazy loader service. | ||
| 176 | |||
| 177 | =cut | ||
| 178 | |||
| 179 | sub get_boolean { | ||
| 180 | my $self = shift; | ||
| 181 | |||
| 182 | if (not exists $self->{'_boolean'}) { | ||
| 183 | $self->{'_boolean'} = Eve::PgSqlType::Boolean->new(); | ||
| 184 | } | ||
| 185 | |||
| 186 | return $self->_boolean; | ||
| 187 | } | ||
| 188 | |||
| 189 | =head2 B<get_double()> | ||
| 190 | |||
| 191 | A PostgreSQL double precision floating point type lazy loader service. | ||
| 192 | |||
| 193 | =cut | ||
| 194 | |||
| 195 | sub get_double { | ||
| 196 | my $self = shift; | ||
| 197 | |||
| 198 | if (not exists $self->{'_double'}) { | ||
| 199 | $self->{'_double'} = Eve::PgSqlType::Double->new(); | ||
| 200 | } | ||
| 201 | |||
| 202 | return $self->_double; | ||
| 203 | } | ||
| 204 | |||
| 205 | =head2 B<get_double_array()> | ||
| 206 | |||
| 207 | A PostgreSQL double precision array type lazy loader service. | ||
| 208 | |||
| 209 | =cut | ||
| 210 | |||
| 211 | sub get_double_array { | ||
| 212 | my $self = shift; | ||
| 213 | |||
| 214 | if (not exists $self->{'_double_array'}) { | ||
| 215 | $self->{'_double_array'} = Eve::PgSqlType::DoubleArray->new(); | ||
| 216 | } | ||
| 217 | |||
| 218 | return $self->_double_array; | ||
| 219 | } | ||
| 220 | |||
| 221 | =head2 B<get_geometry()> | ||
| 222 | |||
| 223 | A PostGIS geometry type lazy loader service. | ||
| 224 | |||
| 225 | =cut | ||
| 226 | |||
| 227 | sub get_geometry { | ||
| 228 | my $self = shift; | ||
| 229 | |||
| 230 | if (not exists $self->{'_geometry'}) { | ||
| 231 | $self->{'_geometry'} = Eve::PgSqlType::Geometry->new(); | ||
| 232 | } | ||
| 233 | |||
| 234 | return $self->_geometry; | ||
| 235 | } | ||
| 236 | |||
| 237 | =head2 B<get_integer()> | ||
| 238 | |||
| 239 | A PostgreSQL integer type lazy loader service. | ||
| 240 | |||
| 241 | =cut | ||
| 242 | |||
| 243 | sub get_integer { | ||
| 244 | my $self = shift; | ||
| 245 | |||
| 246 | if (not exists $self->{'_integer'}) { | ||
| 247 | $self->{'_integer'} = Eve::PgSqlType::Integer->new(); | ||
| 248 | } | ||
| 249 | |||
| 250 | return $self->_integer; | ||
| 251 | } | ||
| 252 | |||
| 253 | =head2 B<get_integer_array()> | ||
| 254 | |||
| 255 | A PostgreSQL integer array type lazy loader service. | ||
| 256 | |||
| 257 | =cut | ||
| 258 | |||
| 259 | sub get_integer_array { | ||
| 260 | my $self = shift; | ||
| 261 | |||
| 262 | if (not exists $self->{'_integer_array'}) { | ||
| 263 | $self->{'_integer_array'} = Eve::PgSqlType::IntegerArray->new(); | ||
| 264 | } | ||
| 265 | |||
| 266 | return $self->_integer_array; | ||
| 267 | } | ||
| 268 | |||
| 269 | =head2 B<get_interval()> | ||
| 270 | |||
| 271 | A PostgreSQL interval type lazy loader service. | ||
| 272 | |||
| 273 | =cut | ||
| 274 | |||
| 275 | sub get_interval { | ||
| 276 | my $self = shift; | ||
| 277 | |||
| 278 | if (not exists $self->{'_interval'}) { | ||
| 279 | $self->{'_interval'} = Eve::PgSqlType::Interval->new(); | ||
| 280 | } | ||
| 281 | |||
| 282 | return $self->_interval; | ||
| 283 | } | ||
| 284 | |||
| 285 | =head2 B<get_smallint()> | ||
| 286 | |||
| 287 | A PostgreSQL smallint type lazy loader service. | ||
| 288 | |||
| 289 | =cut | ||
| 290 | |||
| 291 | sub get_smallint { | ||
| 292 | my $self = shift; | ||
| 293 | |||
| 294 | if (not exists $self->{'_smallint'}) { | ||
| 295 | $self->{'_smallint'} = Eve::PgSqlType::Smallint->new(); | ||
| 296 | } | ||
| 297 | |||
| 298 | return $self->_smallint; | ||
| 299 | } | ||
| 300 | |||
| 301 | =head2 B<get_text()> | ||
| 302 | |||
| 303 | A PostgreSQL text type lazy loader service. | ||
| 304 | |||
| 305 | =cut | ||
| 306 | |||
| 307 | sub get_text { | ||
| 308 | my $self = shift; | ||
| 309 | |||
| 310 | if (not exists $self->{'_text'}) { | ||
| 311 | $self->{'_text'} = Eve::PgSqlType::Text->new(); | ||
| 312 | } | ||
| 313 | |||
| 314 | return $self->_text; | ||
| 315 | } | ||
| 316 | |||
| 317 | =head2 B<get_timestamp_with_time_zone()> | ||
| 318 | |||
| 319 | A PostgreSQL timestamp with time zone type lazy loader service. | ||
| 320 | |||
| 321 | =cut | ||
| 322 | |||
| 323 | sub get_timestamp_with_time_zone { | ||
| 324 | my $self = shift; | ||
| 325 | |||
| 326 | if (not exists $self->{'_timestamp_with_time_zone'}) { | ||
| 327 | $self->{'_timestamp_with_time_zone'} = | ||
| 328 | Eve::PgSqlType::TimestampWithTimeZone->new(); | ||
| 329 | } | ||
| 330 | |||
| 331 | return $self->_timestamp_with_time_zone; | ||
| 332 | } | ||
| 333 | |||
| 334 | =head2 B<get_timestamp_without_time_zone()> | ||
| 335 | |||
| 336 | A PostgreSQL timestamp without time zone type lazy loader service. | ||
| 337 | |||
| 338 | =cut | ||
| 339 | |||
| 340 | sub get_timestamp_without_time_zone { | ||
| 341 | my $self = shift; | ||
| 342 | |||
| 343 | if (not exists $self->{'_timestamp_without_time_zone'}) { | ||
| 344 | $self->{'_timestamp_without_time_zone'} = | ||
| 345 | Eve::PgSqlType::Timestamp->new(); | ||
| 346 | } | ||
| 347 | |||
| 348 | return $self->_timestamp_without_time_zone; | ||
| 349 | } | ||
| 350 | |||
| 351 | =head2 B<get_array()> | ||
| 352 | |||
| 353 | A PostgreSQL array type lazy loader service. | ||
| 354 | |||
| 355 | =cut | ||
| 356 | |||
| 357 | sub get_array { | ||
| 358 | my $self = shift; | ||
| 359 | |||
| 360 | if (not exists $self->{'_array'}) { | ||
| 361 | $self->{'_array'} = | ||
| 362 | Eve::PgSqlType::Array->new(); | ||
| 363 | } | ||
| 364 | |||
| 365 | return $self->_array; | ||
| 366 | } | ||
| 367 | |||
| 368 | =head1 SEE ALSO | ||
| 369 | |||
| 370 | =over 4 | ||
| 371 | |||
| 372 | =item L<Eve::PgSqlConnection> | ||
| 373 | |||
| 374 | =item L<Eve::PgSqlFunction> | ||
| 375 | |||
| 376 | =item L<Eve::PgSqlType> | ||
| 377 | |||
| 378 | =item L<Eve::PgSqlType::Array> | ||
| 379 | |||
| 380 | =item L<Eve::PgSqlType::Bigint> | ||
| 381 | |||
| 382 | =item L<Eve::PgSqlType::Integer> | ||
| 383 | |||
| 384 | =item L<Eve::PgSqlType::Interval> | ||
| 385 | |||
| 386 | =item L<Eve::PgSqlType::Smallint> | ||
| 387 | |||
| 388 | =item L<Eve::PgSqlType::Text> | ||
| 389 | |||
| 390 | =item L<Eve::PgSqlType::TimestampWithTimeZone> | ||
| 391 | |||
| 392 | =back | ||
| 393 | |||
| 394 | =head1 LICENSE AND COPYRIGHT | ||
| 395 | |||
| 396 | Copyright 2012 Igor Zinovyev. | ||
| 397 | |||
| 398 | This program is free software; you can redistribute it and/or modify it | ||
| 399 | under the terms of either: the GNU General Public License as published | ||
| 400 | by the Free Software Foundation; or the Artistic License. | ||
| 401 | |||
| 402 | See http://dev.perl.org/licenses/ for more information. | ||
| 403 | |||
| 404 | |||
| 405 | =head1 AUTHOR | ||
| 406 | |||
| 407 | =over 4 | ||
| 408 | |||
| 409 | =item L<Sergey Konoplev|mailto:gray.ru@gmail.com> | ||
| 410 | |||
| 411 | =item L<Igor Zinovyev|mailto:zinigor@gmail.com> | ||
| 412 | |||
| 413 | =back | ||
| 414 | |||
| 415 | =cut | ||
| 416 | |||
| 417 | 1; | ||