App-AltSQL
view release on metacpan or search on metacpan
lib/App/AltSQL.pm view on Meta::CPAN
package App::AltSQL;
=encoding utf-8
=head1 NAME
App::AltSQL - A drop in replacement to the MySQL prompt with a pluggable Perl interface
=head1 SYNOPSIS
./altsql -h <host> -u <username> -D <database> -p<password>
altsql> select * from film limit 4;
âââââââââââ¤âââââââââââââââââââ¤ââââââââââââââââââââââââââââ
â film_id â title â description
âââââââââââªâââââââââââââââââââªââââââââââââââââââââââââââââ
â 1 â ACADEMY DINOSAUR â A Epic Drama of a Feminist
â 2 â ACE GOLDFINGER â A Astounding Epistle of a D
â 3 â ADAPTATION HOLES â A Astounding Reflection of
â 4 â AFFAIR PREJUDICE â A Fanciful Documentary of a
âââââââââââ§âââââââââââââââââââ§ââââââââââââââââââââââââââââ
4 rows in set (0.00 sec)
=head1 DESCRIPTION
AltSQL is a way to improve your user experience with C<mysql>, C<sqlite3>, C<psql> and other tools that Perl has L<DBI> drivers for. Currently written for MySQL only, the long term goal of this project is to provide users of the various SQL-based da...
There are a few key issues that this programmer has had with using the mysql client every day. After looking for alternatives and other ways to fix the problems, reimplementing the client in Perl seemed like the easiest approach, and lent towards th...
=over 4
=item Ctrl-C kills the program
All of the shells that we used on a daily basis allow you to abandon the half-written statement on the prompt by typing Ctrl-C. Spending all day in shells, you expect this behavior to be consistent, but you do this in mysql and you will be thrown to...
=item Wide output wraps
We are grateful that mysql at least uses ASCII art for table formatting (unlike C<sqlite3> for some reason). But there are some tables that I work with that have many columns, with long names (it's often easier to keep adding columns to a table over...
Suffice it to say, it's a much better experience if, just like with C<git diff>, wide output is left wide, and you are optionally able to scroll horizontally with your arrow keys like you wanted in the first place.
=item Color
Most other modern programs we developers use on a daily basis (vim, ls, top, git, tmux, screen) offer to provide additional context to you via color. By consistently setting colors on a variable type or file type, programs can convey to us additiona...
=item Unicode Box characters
The usage of '|', '+' and '-' for drawing tables and formatting data seems a bit antiquated. Other tools are adopting Unicode characters, and most programmers are now using terminal programs that support Unicode and UTF8 encoding natively. The Unic...
=back
I've thought of a number of other features, but so too have my coworkers and friends. Most people I've spoken with have ideas for future features. Next time you're using your DB shell and find yourself irritated at a feature or bug in the software ...
=head1 CONFIGURATION
The command line arguments inform how to connect to the database, whereas the configuration file(s) provide behavior and features of the UI.
=head2 Command Line
The following options are available.
=over 4
=item -h HOSTNAME | --host HOSTNAME
=item -u USERNAME | --user USERNAME
=item -p | --password=PASSWORD | -pPASSWORD
=item --port PORT
=item -D DATABASE | --database DATABASE
Basic connection parameters to the MySQL database.
=item --A | --no-auto-rehash
By default, upon startup and whenever the database is changed, the C<information_schema> tables will be read to perform tab completion. Disable this behavior to get a faster startup time (but no tab complete).
=back
=head2 Config File
We are using L<Config::Any> for finding and parsing the configuration file. You may use any format you'd like to write it so long as it's support in C<Config::Any>.
=over 4
=item /etc/altsql.(yml|cnf|ini|js|pl)
=item ~/.altsql.(yml|cnf|ini|js|pl)
Write your configuration file to either the system or the local configuration locations. The local file will inherit from the global configuration but with local modifications. For purposes of this example I'll be writing out the config in YAML, bu...
=back
---
prompt: 'altsql> '
plugins:
- Tail
- Dump
view_plugins:
- Color
- UnicodeBox
App::AltSQL::View::Plugin::Color:
header_text:
default: red
cell_text:
is_null: blue
is_primary_key: bold
is_number: yellow
App::AltSQL::View::Plugin::UnicodeBox:
style: heavy_header
split_lines: 1
plain_ascii: 0
This is the default configuration, and currently encompasses all the configurable settings. This should be future safe; as you can see, plugins may use this file for their own variables as there are namespaced sections.
=over 4
=item B<prompt>
prompt: "%u@%h[%d]> "
# 'username@hostname[database]> '
prompt: "%c{red}%u%c{reset} %t{%F %T}> '
# 'username' (in red) ' YYYY-MM-DD HH:MM:SS> '
Provide a custom prompt. The following variables will be interpolated:
=over 4
=item B<%u>
The username used to connect to the model
=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{...}>
The argument to this option will be passed to L<DateTime> C<strftime> for the current time
=back
=item B<plugins>
An array of plugin names for the main namespace.
=item B<view_plugins>
An array of View plugin names to be applied to each View object created
=back
=head1 EXTENDING
As mentioned above, one key point of this project is to make it easy for people to extend. For this reason, I've built it on L<Moose> and offer a L<MooseX::Object::Pluggable> interface. If you extend C<App::AltSQL>, you may want to know about the f...
=cut
use Moose;
use Getopt::Long qw(GetOptionsFromArray);
use Params::Validate;
use Data::Dumper;
use Config::Any;
use Hash::Union qw(union);
our $VERSION = 0.05;
our $| = 1;
# Don't emit 'Wide character in output' warnings
( run in 0.959 second using v1.01-cache-2.11-cpan-6aa56a78535 )