| 1 | package Daje::Database::Model::Super::Common::Base; | ||
| 2 | use Mojo::Base 'Daje::Database::Model::Super::Common::Defaults', -base, -signatures; | ||
| 3 | use v5.42; | ||
| 4 | |||
| 5 | # Autogenerated class Thu Jun 26 17:06:45 2025 | ||
| 6 | # Any manual changes to this class will be overwritten next time its generated | ||
| 7 | |||
| 8 | use Data::Dumper; | ||
| 9 | |||
| 10 | has 'db'; | ||
| 11 | |||
| 12 | sub load_from_index($self, $table, $select, $condition ) { | ||
| 13 | my $result->{result} = 0; | ||
| 14 | my $load = $self->db->select( | ||
| 15 | $table, | ||
| 16 | $select, | ||
| 17 | $condition | ||
| 18 | ); | ||
| 19 | $result->{data} = {}; | ||
| 20 | $result->{data} = $load->hash if $load and $load->rows > 0; | ||
| 21 | $result->{result} = 1; | ||
| 22 | return $result; | ||
| 23 | |||
| 24 | } | ||
| 25 | |||
| 26 | sub load_pk($self, $table, $select, $primary_key_name, $primary_key) { | ||
| 27 | my $result->{result} = 0; | ||
| 28 | my $load = $self->db->select( | ||
| 29 | $table, | ||
| 30 | $select, | ||
| 31 | {$primary_key_name => $primary_key} | ||
| 32 | ); | ||
| 33 | $result->{data} = {}; | ||
| 34 | $result->{data} = $load->hash if $load and $load->rows > 0; | ||
| 35 | $result->{result} = 1; | ||
| 36 | |||
| 37 | return $result; | ||
| 38 | }; | ||
| 39 | |||
| 40 | sub load_fkey($self, $table, $select, $foreign_key_name, $foreign_key) { | ||
| 41 | my $result->{result} = 0; | ||
| 42 | my $load = $self->db->select( | ||
| 43 | $table, | ||
| 44 | $select, | ||
| 45 | {$foreign_key_name => $foreign_key} | ||
| 46 | ); | ||
| 47 | $result->{data} = []; | ||
| 48 | $result->{data} = $load->hashes if $load and $load->rows > 0; | ||
| 49 | $result->{result} = 1; | ||
| 50 | return $result; | ||
| 51 | } | ||
| 52 | |||
| 53 | sub load_a_list($self, $table, $select, $key_value) { | ||
| 54 | my $result->{result} = 0; | ||
| 55 | my $load = $self->db->select( | ||
| 56 | $table, | ||
| 57 | $select, | ||
| 58 | $key_value | ||
| 59 | ); | ||
| 60 | $result->{data} = []; | ||
| 61 | $result->{data} = $load->hashes if $load and $load->rows > 0; | ||
| 62 | $result->{result} = 1; | ||
| 63 | return $result; | ||
| 64 | } | ||
| 65 | |||
| 66 | sub load_a_full_list($self, $table, $select) { | ||
| 67 | my $result->{result} = 0; | ||
| 68 | my $load = $self->db->select( | ||
| 69 | $table, | ||
| 70 | $select | ||
| 71 | ); | ||
| 72 | $result->{data} = []; | ||
| 73 | $result->{data} = $load->hashes if $load and $load->rows > 0; | ||
| 74 | $result->{result} = 1; | ||
| 75 | return $result; | ||
| 76 | } | ||
| 77 | |||
| 78 | sub insert($self, $table, $data, $primary_key_name) { | ||
| 79 | my $result->{result} = 0; | ||
| 80 | $data = $self->insert_defaults($data); | ||
| 81 | my $primary_key = $self->db->insert( | ||
| 82 | $table, $data, | ||
| 83 | { returning => $primary_key_name } | ||
| 84 | ); | ||
| 85 | $result->{data} = {}; | ||
| 86 | $result->{data} = $primary_key->hash | ||
| 87 | if $primary_key and $primary_key->rows > 0; | ||
| 88 | $result->{result} = 1; | ||
| 89 | return $result; | ||
| 90 | } | ||
| 91 | |||
| 92 | sub update($self, $table, $data, $keys) { | ||
| 93 | my $result->{result} = 0; | ||
| 94 | $data = $self->update_defaults($data); | ||
| 95 | $self->db->update($table, $data, $keys); | ||
| 96 | $result->{result} = 1; | ||
| 97 | return $result; | ||
| 98 | } | ||
| 99 | |||
| 100 | sub delete($self, $table, $keys) { | ||
| 101 | my $result->{result} = 0; | ||
| 102 | $self->db->delete($table, $keys); | ||
| 103 | $result->{result} = 1; | ||
| 104 | return $result; | ||
| 105 | } | ||
| 106 | |||
| 107 | sub super_select($self, $table, $select, $conditions, $data ) { | ||
| 108 | my $result->{result} = 0; | ||
| 109 | |||
| 110 | my $stmt = qq{ | ||
| 111 | SELECT $select FROM $table WHERE $conditions | ||
| 112 | }; | ||
| 113 | |||
| 114 | my $load = $self->db->query($stmt, $data); | ||
| 115 | $result->{data} = []; | ||
| 116 | $result->{data} = $load->hashes if $load and $load->rows > 0; | ||
| 117 | $result->{result} = 1; | ||
| 118 | return $result; | ||
| 119 | } | ||
| 120 | 1; | ||
| 121 |