2017 © Pedro Peláez
 

library sqli

A Laravel Artisan SQL Interactive Interface

image

pragmarx/sqli

A Laravel Artisan SQL Interactive Interface

  • Thursday, March 19, 2015
  • by AntonioCarlosRibeiro
  • Repository
  • 2 Watchers
  • 58 Stars
  • 448 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 2 Open issues
  • 7 Versions
  • 11 % Grown

The README.md

sqli

Latest Stable Version License Downloads, (*1)

A Laravel 4 & 5 Artisan SQL Interactive Interface, plus a handful of Artisan commands to execute SQL queries., (*2)

sqli

It's like tinker for SQL, just run, (*3)

php artisan sqli

And execute whatever sql query you like in your sql:, (*4)

postgresql:laravel> select email from users;

And you should see it this way:, (*5)

+----+------------------------------+
| id | email                        |
+----+------------------------------+
|  1 | arnold@schwarzenegger.com    |
|  2 | danny@devito.com             |
+----+------------------------------+
Executed in 0.0602 seconds.

You can get a list of your tables by running:, (*6)

postgresql:laravel> tables count

count option is optional:, (*7)

+--------------+-----------------------------+-----------+
| table_schema | table_name                  | row_count |
+--------------+-----------------------------+-----------+
| public       | firewall                    | 2         |
| public       | migrations                  | 3         |
| public       | sessions                    | 1         |
| public       | users                       | 1         |
| public       | actors                      | 3431326   |
| public       | movies                      | 1764727   |
+--------------+-----------------------------+-----------+

You can view a list of databases:, (*8)

postgresql:laravel> databases

+-----------------+--------+--------------------------+-----------+
| Connection Name | Driver | Database                 | Host      |
+-----------------+--------+--------------------------+-----------+
| postgres        | pgsql  | production               | localhost |
| tracker         | mysql  | tracker                  | localhost |
+-----------------+--------+--------------------------+-----------+

You can change your current database connection by:, (*9)

postgresql:laravel> database mysql
mysql:staging>

You can list all commands by executing, (*10)

postgresql:laravel> help

+----------+------------------------------------------------------------------------------+
| command  | description                                                                  |
+----------+------------------------------------------------------------------------------+
| quit     | Exit interface.                                                              |
| tables   | List all tables. Use "tables count" to list with row count.                  |
| help     | Show this help.                                                              |
| database | Change the current database connection. Usage: "database [connection name]". |
+----------+------------------------------------------------------------------------------+

To exit, just type CTRL-C, CTRL-D or quit., (*11)

Other Artisan Commands

You don't need to enter sqli to execute commands, you have access to the most common DML commands via direct Artisan commands:, (*12)

select
insert
update
delete

A special DML command, to execute whatever else you may needd:, (*13)

sql

And a command for listing tables:, (*14)

tables

Syntax

The syntax could not be simpler, just execute, (*15)

php artisan select email, first_name, last_name from users

And you should get a result like:, (*16)

+----+------------------------------+----------------+----------------+
| id | email                        | first_name     | last_name      |
+----+------------------------------+----------------+----------------+
|  1 | arnold@schwarzenegger.com    | Arnold         | Schwarzenegger |
|  2 | danny@devito.com             | Danny          | DeVito         |
+----+------------------------------+----------------+----------------+

Create a very small alias for Artisan:, (*17)

alias a='php artisan'

And it'll be as if you where in your sql interface:, (*18)

a select * from posts where post_id < 100

a update posts set author_id = 1

a delete from posts

a sql call removeOldPosts()

Command 'table'

The command, (*19)

php artisan tables --count

Will give you a list of your tables with an optional row count:, (*20)

+--------------+-----------------------------+-----------+
| table_schema | table_name                  | row_count |
+--------------+-----------------------------+-----------+
| public       | firewall                    | 2         |
| public       | migrations                  | 3         |
| public       | sessions                    | 1         |
| public       | users                       | 1         |
| public       | actors                      | 3431326   |
| public       | movies                      | 1764727   |
+--------------+-----------------------------+-----------+

Too many columns aren't good to look at?

Use the less command to help you with that:, (*21)

a select * from users | less -S

Should give you a scrollable view of your table:, (*22)

+----+------------------------------+-------------+-----------+--------------------------------------------+---------------------+---------------------+--------------------------------------------------------------+---------------------+----------------+----------------+----------------------------+----------------------------+--------------------------------------------------------------+-----------+-------------+-----------+-----------+-------------+------------+--------------+------------------+-------------------+-----------------+-------------------+-----------------+-----------------+
| id | email                        | permissions | activated | activation_code                            | activated_at        | last_login          | persist_code                                                 | reset_password_code | first_name     | last_name      | created_at                 | updated_at                 | password                                                     | gender_id | middle_name | nick_name | birth_day | birth_month | birth_year | early_signup | imported_from_id | registration_time | registration_ip | registrated_by_id | activation_time | beta_invitation |
+----+------------------------------+-------------+-----------+--------------------------------------------+---------------------+---------------------+--------------------------------------------------------------+---------------------+----------------+----------------+----------------------------+----------------------------+--------------------------------------------------------------+-----------+-------------+-----------+-----------+-------------+------------+--------------+------------------+-------------------+-----------------+-------------------+-----------------+-----------------+
| 38 | arnold@schwarzenegger.com    |             | 1         | V38ScwjCORUvCpuhjkieR4KbnQSlVbhFHujmsyVvN8 | 2014-02-16 14:07:59 | 2014-03-27 18:59:56 | $2y$10$POQ18Kc5JXftOtJswQujBO0PAQ4cfqsSXLKckn9aZOM4VgaExRDHa |                     | Arnold         | Schwarzenegger | 2014-03-29 18:38:39.998522 | 2014-03-27 18:59:56        | $2y$10$5S3KaI6PPHnySECVRwRcferQdiJZP6QgX5adxK7z/WPlxP386HW0e |           |             |           | 31        | 10          |            |              |                  |                   |                 |                   |                 |                 |
| 40 | clint@eastwood.com           |             |           |                                            |                     |                     |                                                              |                     | Clint          | Eastwood       | 2014-03-29 18:38:39.998522 | 2014-03-29 18:26:17.402382 |                                                              |           |             |           |           |             |            |              |                  |                   |                 |                   |                 |                 |
| 41 | paul@newman.com              |             |           |                                            |                     |                     |                                                              |                     | Paul           | Newman         | 2014-03-29 18:38:39.998522 | 2014-03-29 18:32:22.489968 |                                                              |           |             |           |           |             |            |              |                  |                   |                 |                   |                 |                 |
+----+------------------------------+-------------+-----------+--------------------------------------------+---------------------+---------------------+--------------------------------------------------------------+---------------------+----------------+----------------+----------------------------+----------------------------+--------------------------------------------------------------+-----------+-------------+-----------+-----------+-------------+------------+--------------+------------------+-------------------+-----------------+-------------------+-----------------+-----------------+

Drawbacks

When passing arguments to scripts Linux based systems may remove quotes and misunderstand your parentheses in queries, you if you need to use them you'll have to double quote it:, (*23)

a insert "into users (email, first_name, last_name, created_at, updated_at) values ('clint@eastwood.com', 'Clint', 'Eastwood', 'NOW', 'NOW')"

or just the parts that have them:, (*24)

a insert into users "(email, first_name, last_name, created_at, updated_at)" values "('clint@eastwood.com', 'Clint', 'Eastwood', 'NOW', 'NOW')"

But you can also escape them with \, (*25)

a update users set created_at = \'NOW\'

Command Line Completion

All SQL commands, connections, tables names and columns are present in completion, just use TAB to complete your commands., (*26)

Installation

Requirements

  • Laravel 4.1+ / Laravel 5+

Installing

Require the package using Composer:, (*27)

composer require pragmarx/sqli

Add the service provider to your app/config/app.php:, (*28)

'PragmaRX\Sqli\Vendor\Laravel\ServiceProvider',

Author

Antonio Carlos Ribeiro, (*29)

License

sqli is licensed under the BSD 3-Clause License - see the LICENSE file for details, (*30)

Contributing

Pull requests and issues are more than welcome., (*31)

The Versions

19/03 2015

dev-master

9999999-dev

A Laravel Artisan SQL Interactive Interface

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel sql query artisan sqli repl

19/03 2015

v1.0.1

1.0.1.0

A Laravel Artisan SQL Interactive Interface

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel sql query artisan sqli repl

17/03 2015

v1.0.0

1.0.0.0

A Laravel Artisan SQL Interactive Interface

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel sql query artisan sqli repl

18/02 2015

v0.5.4

0.5.4.0

A Laravel 4 Artisan SQL Interactive Interface

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel sql query artisan sqli

31/03 2014

v0.5.2

0.5.2.0

A Laravel 4 Artisan SQL Interactive Interface

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by eRobin

laravel sql query artisan sqli

31/03 2014

v0.5.1

0.5.1.0

A Laravel 4 Artisan SQL Interactive Interface

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by eRobin

laravel sql query artisan sqli

29/03 2014

v0.5.0

0.5.0.0

Laravel 4 Blade on Select

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by eRobin

laravel select blacklist whitelist