| 1 | package SQL::Engine::Operation; | ||
| 2 | |||
| 3 | use 5.014; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use registry; | ||
| 9 | use routines; | ||
| 10 | |||
| 11 | use Data::Object::Class; | ||
| 12 | use Data::Object::ClassHas; | ||
| 13 | |||
| 14 | our $VERSION = '0.02'; # VERSION | ||
| 15 | |||
| 16 | # ATTRIBUTES | ||
| 17 | |||
| 18 | has bindings => ( | ||
| 19 | is => 'ro', | ||
| 20 | isa => 'HashRef', | ||
| 21 | req => 1 | ||
| 22 | ); | ||
| 23 | |||
| 24 | has statement => ( | ||
| 25 | is => 'ro', | ||
| 26 | isa => 'Str', | ||
| 27 | req => 1 | ||
| 28 | ); | ||
| 29 | |||
| 30 | # METHODS | ||
| 31 | |||
| 32 | method parameters(Maybe[HashRef] $values) { | ||
| 33 | my $bindings = $self->bindings; | ||
| 34 | my @binddata = map $values->{$bindings->{$_}}, sort(keys(%$bindings)); | ||
| 35 | |||
| 36 | return wantarray ? (@binddata) : [@binddata]; | ||
| 37 | } | ||
| 38 | |||
| 39 | 1; | ||
| 40 | |||
| 41 | =encoding utf8 | ||
| 42 | |||
| 43 | =head1 NAME | ||
| 44 | |||
| 45 | SQL::Engine::Operation - SQL Operation | ||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | =head1 ABSTRACT | ||
| 50 | |||
| 51 | SQL Statement Operation | ||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | =head1 SYNOPSIS | ||
| 56 | |||
| 57 | use SQL::Engine::Operation; | ||
| 58 | |||
| 59 | my $operation = SQL::Engine::Operation->new( | ||
| 60 | statement => 'SELECT * FROM "tasks" WHERE "reporter" = ? AND "assigned" = ?', | ||
| 61 | bindings => { | ||
| 62 | 0 => 'user_id', | ||
| 63 | 1 => 'user_id' | ||
| 64 | } | ||
| 65 | ); | ||
| 66 | |||
| 67 | # my @bindings = $operation->parameters({ | ||
| 68 | # user_id => 123 | ||
| 69 | # }); | ||
| 70 | |||
| 71 | =cut | ||
| 72 | |||
| 73 | =head1 DESCRIPTION | ||
| 74 | |||
| 75 | This package provides SQL Statement Operation. | ||
| 76 | |||
| 77 | =cut | ||
| 78 | |||
| 79 | =head1 LIBRARIES | ||
| 80 | |||
| 81 | This package uses type constraints from: | ||
| 82 | |||
| 83 | L<Types::Standard> | ||
| 84 | |||
| 85 | =cut | ||
| 86 | |||
| 87 | =head1 ATTRIBUTES | ||
| 88 | |||
| 89 | This package has the following attributes: | ||
| 90 | |||
| 91 | =cut | ||
| 92 | |||
| 93 | =head2 bindings | ||
| 94 | |||
| 95 | bindings(HashRef) | ||
| 96 | |||
| 97 | This attribute is read-only, accepts C<(HashRef)> values, and is required. | ||
| 98 | |||
| 99 | =cut | ||
| 100 | |||
| 101 | =head2 statement | ||
| 102 | |||
| 103 | statement(Str) | ||
| 104 | |||
| 105 | This attribute is read-only, accepts C<(Str)> values, and is required. | ||
| 106 | |||
| 107 | =cut | ||
| 108 | |||
| 109 | =head1 METHODS | ||
| 110 | |||
| 111 | This package implements the following methods: | ||
| 112 | |||
| 113 | =cut | ||
| 114 | |||
| 115 | =head2 parameters | ||
| 116 | |||
| 117 | parameters(Maybe[HashRef] $values) : ArrayRef | ||
| 118 | |||
| 119 | The parameters method returns positional bind values for use with statement | ||
| 120 | handlers. | ||
| 121 | |||
| 122 | =over 4 | ||
| 123 | |||
| 124 | =item parameters example #1 | ||
| 125 | |||
| 126 | # given: synopsis | ||
| 127 | |||
| 128 | my $bindings = $operation->parameters({ | ||
| 129 | user_id => 123 | ||
| 130 | }); | ||
| 131 | |||
| 132 | # [123, 123] | ||
| 133 | |||
| 134 | =back | ||
| 135 | |||
| 136 | =cut | ||
| 137 | |||
| 138 | =head1 AUTHOR | ||
| 139 | |||
| 140 | Al Newkirk, C<awncorp@cpan.org> | ||
| 141 | |||
| 142 | =head1 LICENSE | ||
| 143 | |||
| 144 | Copyright (C) 2011-2019, Al Newkirk, et al. | ||
| 145 | |||
| 146 | This is free software; you can redistribute it and/or modify it under the terms | ||
| 147 | of the The Apache License, Version 2.0, as elucidated in the L<"license | ||
| 148 | file"|https://github.com/iamalnewkirk/sql-engine/blob/master/LICENSE>. | ||
| 149 | |||
| 150 | =head1 PROJECT | ||
| 151 | |||
| 152 | L<Wiki|https://github.com/iamalnewkirk/sql-engine/wiki> | ||
| 153 | |||
| 154 | L<Project|https://github.com/iamalnewkirk/sql-engine> | ||
| 155 | |||
| 156 | L<Initiatives|https://github.com/iamalnewkirk/sql-engine/projects> | ||
| 157 | |||
| 158 | L<Milestones|https://github.com/iamalnewkirk/sql-engine/milestones> | ||
| 159 | |||
| 160 | L<Contributing|https://github.com/iamalnewkirk/sql-engine/blob/master/CONTRIBUTE.md> | ||
| 161 | |||
| 162 | L<Issues|https://github.com/iamalnewkirk/sql-engine/issues> | ||
| 163 | |||
| 164 | =cut |