package Daje::Generate::Templates::Perl;
use Mojo::Base -base;

our $VERSION = '0.01';

1;

__DATA__

@@ class
use v5.40;
use feature 'class';
no warnings 'experimental::class';

# Autogenerated class <<date>>
# Any manual changes to this class will be overwritten next time its generated

class <<name_space>><<classname>> :isa(<<base_name_space>><<base_class_name>>) {

    <<fields>>

    <<pkey>>
    <<fkey>>
    <<insert>>
    <<update>>
    <<select>>
    <<methods>>
};

@@ fields_method
field $fields :reader = "<<select_fields>>";
    field $primary_key_name :reader = "<<primary_key>>";
    field $table_name :reader = "<<table_name>>";
@@ method

    method <<method_name>> (<<parameters>>) {
        <<method_content>>
    };


@@ baseclass
use v5.40;
use feature 'class';
no warnings 'experimental::class';

# Autogenerated class <<date>>
# Any manual changes to this class will be overwritten next time its generated

class <<base_name_space>>Base {
    field $db :param :reader;

    method load_pk($table, $select, $primary_key_name, $primary_key) {
        my $result->{result} = 1;
        try{
            my $load = $self->db->select(
                $table,
                    [$select],
                    {$primary_key_name => $primary_key}
            );
            $result->{data};
            $result->{data} = $load->hash if $load and $load->rows > 0;
        } catch ($e) {
            $result->{result} = 0;
            $result->{data} = "";
            $result->{error} = $e;
        };
        return $result;
    };

    method load__fkey($table, $select, $foreign_key_name, $foreign_key) {
        my $result->{result} = 1;
        try {
            my $load = $db->select(
                $table,
                    [$select],
                {$foreign_key_name => $foreign_key}
            );
            $result->{data};
            $result->{data} = $load->hashes if $load and $load->rows > 0;
        } catch ($e) {
            $result->{result} = 0;
            $result->{data} = "";
            $result->{error} = $e;
        };
        return $result;
    }

    method load_a_list($table, $select, $key_value) {
        my $result->{result} = 1;
         try {
            my $load = $db->select(
                $table,
                    [$select],
                {$key_value}
            );
            $result->{data};
            $result->{data} = $load->hashes if $load and $load->rows > 0;
        } catch ($e) {
            $result->{result} = 0;
            $result->{data} = "";
            $result->{error} = $e;
        };

        return $result;
    }

    method insert($table, $data) {
        my $result->{result} = 1;
        try {
            $db->insert($table, $data);
        } catch ($e) {
            $result->{error} = $e;
            $result->{result} = 0;
        };
        return $result;
    }

    method update($table, $data, $keys) {
        my $result->{result} = 1;
        try {
            $db->update($table, $data, $keys);
        } catch ($e) {
            $result->{error} = $e;
            $result->{result} = 0;
        };
        return $result;
    }

};

@@ interface
use v5.40;
use feature 'class';
no warnings 'experimental::class';

# Autogenerated class <<date>>
# This class is generated once. Any over rides or special methods should be put here

class <<interface>><<classname>> :isa(<<name_space>><<classname>>) {


};
@@ load_from_pkey
method load_pkey($<<primary_key>>) {

        my $result = $self->load_pk(
            $table_name,
            $fields,
            $primary_key_name,
            $<<primary_key>>
        );
        return $result;
    }
@@ load_from_fkey
method load_<<foreign_key>>($<<foreign_key>> ) {

        my $result = $self->load__fkey(
            $table_name,
            $fields,
            '<<foreign_key>>',
            $<<foreign_key>>
        );
        return $result;
    }
@@ load_list
method load_list($key_value) {
        my $result = $self->load_a_list(
            $table_name,
            $fields,
            $key_value
        );
        return $result;
    }
@@ insert_data
method insert_<<table_name>>($data) {
        my $result = $self->insert($table_name, $data);
        return $result;
    }
@@ update_data
method update_<<table_name>>($data, $keys) {
        my $result = $self->update($table_name, $data, $keys)
        return $result;
    }

@@ pod_text

#################### pod generated by Pod::Autopod - keep this line to make pod updates possible ####################

=head1 NAME

Daje::Generate::Templates::Perl


=head1 DESCRIPTION

Autogenerated class <<date>>
Any manual changes to this class will be overwritten next time its generated


=head1 REQUIRES

L<feature> 

L<v5.40> 

L<feature> 

L<v5.40> 

L<feature> 

L<v5.40> 

L<v5.40> 


=head1 METHODS


=cut

