The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

SQL::Load::Method

SYNOPSIS

    my $sql = q{
        -- [find]
        SELECT * FROM users WHERE id = ?;
        
        -- [find-by-email]
        SELECT * FROM users WHERE email = ?;        
    };

    my $method = SQL::Load::Method->new($sql);
    
    # SELECT * FROM users WHERE id = ?;
    print $method->name('find');
    
    # SELECT * FROM users WHERE email = ?;
    print $method->name('find-by-email');
    

DESCRIPTION

SQL::Load::Method contains useful methods to SQL::Load, method load from SQL::Load returns a reference.

METHODS

new

    my $method = SQL::Load::Method->new($sql);

construct a new SQL::Load::Method.

default

    $method->default;
    

returns the first SQL or SQL named as default.

name

    # -- # name
    # -- [name]
    # -- (name)

    $method->name('name');
    

returns SQL by name.

next

    while (my $sql = $method->next) {
        print $sql;
    }
    

returns the next SQL like an iterator.

at

    $method->at(1);
    

returns the SQL by position in the list, starting with 1.

first

    $method->first;
    

returns first the SQL.

last

    $method->last;
    

returns last the SQL.

replace

    $method->replace('value', 'new_value')->name('find');
    $method->replace(value => 'new_value')->first;
    $method->replace('value1', 'new_value1', 'value2', 'new_value2')->at(1);
    $method->replace(value1 => 'new_value1', value2 => 'new_value2')->last;
    

replaces values and returns the reference itself.

SEE ALSO

SQL::Load.

AUTHOR

Lucas Tiago de Moraes, lucastiagodemoraes@gmail.com.

COPYRIGHT AND LICENSE

This software is copyright (c) 2022 by Lucas Tiago de Moraes.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.