App-AltSQL

 view release on metacpan or  search on metacpan

lib/App/AltSQL.pm  view on Meta::CPAN

=item B<%d>

The current database or '(none)'

=item B<%h>

The hostname the model is connected to

=item B<%%>

An escaped percent sign

=item B<%c{...}>

A L<Term::ANSIColor> color name.  The value will be passed directly to the C<color> method.

=item B<%e{...}>

A block to be eval'ed.  You may use $self to refer to the L<App::AltSQL::Term> object

=item B<%t{...}>

lib/App/AltSQL/Model/MySQL.pm  view on Meta::CPAN

	O    => '%t{%b}',
	R    => '%t{%k}',
	r    => '%t{%I}',
	m    => '%t{%M}',
	s    => '%t{%S}',
	P    => '%t{%p}',
);

=cut

Take a .my.cnf prompt format and convert it into Term escape options

Reference:
http://www.thegeekstuff.com/2010/02/mysql_ps1-6-examples-to-make-your-mysql-prompt-like-angelina-jolie/

=cut

sub parse_prompt {
	my $self = shift;

	my $parsed_prompt = $self->prompt;

lib/App/AltSQL/Plugin/Dump/Format/csv.pm  view on Meta::CPAN

package App::AltSQL::Plugin::Dump::Format::csv;

use Moose::Role;

sub format {
    my ($self, %params) = @_;

    my $table_data = $params{table_data};

    # make headers for the csv file
    my $csv = join( ",", map{ escape($_->{name}) } @{ $table_data->{columns} } ) . "\n";

    # print out the rows
    for my $row (@{ $table_data->{rows} }) {
        $csv .= join( ",", map{ escape($_) } @$row ) . "\n";
    }

    return $csv;
}

sub escape {
    my ($value) = @_;
    return '' if !defined $value;
    $value =~ s/"/""/g;
    return '"' . $value . '"';
}

1;

lib/App/AltSQL/Plugin/Dump/Format/html.pm  view on Meta::CPAN


sub format {
    my ($self, %params) = @_;

    my $table_data = $params{table_data};

    # ehhh prob shouldn't put this here but couldn't resist.
    my $css = 'table{margin: 1em 1em 1em 2em;background: whitesmoke;border-collapse: collapse;}table th, table td{border: 1px gainsboro solid;padding: 0.2em;}table th{background: gainsboro;text-align: left;}';

    my $html  = "<style>$css</style><table>";
       $html .= '<tr>' . join( '', map{ '<th>' . escape($_->{name}) . '</th>' } @{ $table_data->{columns} } ) . "</tr>";

    for my $row (@{ $table_data->{rows} }) {
        $html .=  '<tr>' . join( '', map {'<td>' . escape($_) . '</td>' } @$row ) . '</tr>';
    }

    $html .= '</table>';

    return $html;
}

sub escape {
    my ($value) = @_;
    return '' if !defined $value;
    $value =~ s/</&lt/g;
    $value =~ s/>/&gt/g;
    return $value;
}

1;

lib/App/AltSQL/Plugin/Dump/Format/sql.pm  view on Meta::CPAN


sub format {
    my ($self, %params) = @_;

    my $table_data = $params{table_data};

    # todo: add a create table once we have the datatypes in table data

    # todo: add support for non multi column insert for sqlite3
    my $sql =  'INSERT INTO table (' .
        join( ',', map{ escape($_->{name}, 'column') } @{ $table_data->{columns} } ) . ') VALUES';

    for my $row (@{ $table_data->{rows} }) {
        $sql .=  '(' . join( ',', map {escape($_)} @$row ) . '),';
    }

    # change last trailing comma with semicolon
    $sql =~ s/,$/;/;

    return $sql;
}

sub escape {
    my ($value, $type) = @_;

    return 'NULL' if !defined $value;

    if (!$type || $type ne 'column') {
        $value =~ s/'/''/g;
        return "'$value'";
    }

    return "`$value`";

lib/App/AltSQL/Term/Plugin/SyntaxHighlight.pm  view on Meta::CPAN

my @input_highlighting = (
	{
		color => 'yellow',
		words => [qw(
			action add after aggregate all alter as asc auto_increment avg avg_row_length
			both by
			cascade change character check checksum column columns comment constraint create cross
			current_date current_time current_timestamp
			data database databases day day_hour day_minute day_second
			default delayed delay_key_write delete desc describe distinct distinctrow drop
			enclosed escape escaped explain
			fields file first flush for foreign from full function
			global grant grants group
			having heap high_priority hosts hour hour_minute hour_second
			identified ignore index infile inner insert insert_id into isam
			join
			key keys kill last_insert_id leading left limit lines load local lock logs long 
			low_priority
			match max_rows middleint min_rows minute minute_second modify month myisam
			natural no
			on optimize option optionally order outer outfile



( run in 0.406 second using v1.01-cache-2.11-cpan-c21f80fb71c )