A Laravel Artisan SQL Interactive Interface

Overview

sqli

Latest Stable Version License Downloads

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

sqli

It's like tinker for SQL, just run

php artisan sqli

And execute whatever sql query you like in your sql:

postgresql:laravel> select email from users;

And you should see it this way:

+----+------------------------------+
| id | email                        |
+----+------------------------------+
|  1 | [email protected]    |
|  2 | [email protected]             |
+----+------------------------------+
Executed in 0.0602 seconds.

You can get a list of your tables by running:

postgresql:laravel> tables count

count option is optional:

+--------------+-----------------------------+-----------+
| 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:

postgresql:laravel> databases

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

You can change your current database connection by:

postgresql:laravel> database mysql
mysql:staging>

You can list all commands by executing

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.

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:

select
insert
update
delete

A special DML command, to execute whatever else you may needd:

sql

And a command for listing tables:

tables

Syntax

The syntax could not be simpler, just execute

php artisan select email, first_name, last_name from users

And you should get a result like:

+----+------------------------------+----------------+----------------+
| id | email                        | first_name     | last_name      |
+----+------------------------------+----------------+----------------+
|  1 | [email protected]    | Arnold         | Schwarzenegger |
|  2 | [email protected]             | Danny          | DeVito         |
+----+------------------------------+----------------+----------------+

Create a very small alias for Artisan:

alias a='php artisan'

And it'll be as if you where in your sql interface:

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

php artisan tables --count

Will give you a list of your tables with an optional row count:

+--------------+-----------------------------+-----------+
| 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:

a select * from users | less -S

Should give you a scrollable view of your table:

+----+------------------------------+-------------+-----------+--------------------------------------------+---------------------+---------------------+--------------------------------------------------------------+---------------------+----------------+----------------+----------------------------+----------------------------+--------------------------------------------------------------+-----------+-------------+-----------+-----------+-------------+------------+--------------+------------------+-------------------+-----------------+-------------------+-----------------+-----------------+
| 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 | [email protected]    |             | 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 | [email protected]           |             |           |                                            |                     |                     |                                                              |                     | Clint          | Eastwood       | 2014-03-29 18:38:39.998522 | 2014-03-29 18:26:17.402382 |                                                              |           |             |           |           |             |            |              |                  |                   |                 |                   |                 |                 |
| 41 | [email protected]              |             |           |                                            |                     |                     |                                                              |                     | 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:

a insert "into users (email, first_name, last_name, created_at, updated_at) values ('[email protected]', 'Clint', 'Eastwood', 'NOW', 'NOW')"

or just the parts that have them:

a insert into users "(email, first_name, last_name, created_at, updated_at)" values "('[email protected]', 'Clint', 'Eastwood', 'NOW', 'NOW')"

But you can also escape them with \

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.

Installation

Requirements

  • Laravel 4.1+ / Laravel 5+

Installing

Require the package using Composer:

composer require pragmarx/sqli

Add the service provider to your app/config/app.php:

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

Author

Antonio Carlos Ribeiro

License

sqli is licensed under the BSD 3-Clause License - see the LICENSE file for details

Contributing

Pull requests and issues are more than welcome.

You might also like...
👀 Manage your views in Laravel projects through artisan
👀 Manage your views in Laravel projects through artisan

Artisan View This package adds a handful of view-related commands to Artisan in your Laravel project. Generate blade files that extend other views, sc

Dispatch Laravel jobs via Artisan
Dispatch Laravel jobs via Artisan

This package can register jobs as Artisan commands. All you need to do is let your job implement the empty ArtisanDispatchable interface.

📦 Adds Laravel Packages Support to Lumen and Vendor Publish Artisan Command.
📦 Adds Laravel Packages Support to Lumen and Vendor Publish Artisan Command.

Laravel Package Support for Lumen: Makes Lumen compatible with Laravel Packages. You can use any Laravel Packages in Lumen by installing Larasupport Package.

Generate services in Laravel with the artisan command
Generate services in Laravel with the artisan command

Laravel Service Generator Quickly generate services for your projects! Table of Contents Features Installation Usage Generate services Generate servic

An artisan command for using multiple environment configurations in Laravel 5

Laravel 5 env An artisan command for managing multiple .env of your Laravel 5 app. Installation Copy EnvCommand.php to app/Console/Commands/ of your L

Package for Laravel that gives artisan commands to setup and edit environment files.
Package for Laravel that gives artisan commands to setup and edit environment files.

Setup and work with .env files in Laravel from the command line NOTE: This doesn't work with Laravel 5 since .env files were changed. This is for Lara

A nice GUI for Laravel Artisan, ready out of the box, configurable and handy for non-CLI experienced developers.

Artisan UI A nice GUI for Laravel Artisan, ready out of the box, configurable and handy for non-CLI experienced developers. Supported commands must be

A bookmarkable, searchable cheatsheet for all of Laravel's default Artisan commands.

artisan.page A bookmarkable, searchable cheatsheet for all of Laravel's default Artisan commands. Generation The generation of the manifest files is d

Laravel API architecture builder based on artisan commands.

🧑‍🔬 API-Formula Laravel API architecture builder based on artisan commands. This package provides a nice and fluent way to generate combined control

Comments
  • Correção falta de dois pontos no arquivo json (

    Correção falta de dois pontos no arquivo json ("pragmarx/sqli" "0.*") da...

    ... linha 169 do readme.php

    Correção da falta de dois pontos entre as informações do json. Errado - "pragmarx/sqli" "0." Correto - "pragmarx/sqli":"0."

    opened by angelorubin 10
  • Installing on Laravel 5.1 gives pusher message

    Installing on Laravel 5.1 gives pusher message

    After installing with Composer on Laravel 5.1 every artisan command fails and keep giving the message:

    Environment variable not set: PUSHER_KEY

    Service provider has been correctly added.

    After removing with Composer everything works fine again.

    opened by cliffordjames 2
  • Cannot call abstract method Illuminate\Support\ServiceProvider::register()

    Cannot call abstract method Illuminate\Support\ServiceProvider::register()

    I'm on Laravel 4.2 btw. This packagist never worked, but I left it installed then suddenly it started causing this exception. Removing it fixed this problem:

    PHP Fatal error:  Cannot call abstract method Illuminate\Support\ServiceProvider::register() in /home/michael/www/sae/vendor/pragmarx/sqli/src/Vendor/Laravel/ServiceProvider.php on line 92
    PHP Stack trace:
    PHP   1. {main}() /home/michael/www/sae/artisan:0
    PHP   2. require_once() /home/michael/www/sae/artisan:30
    PHP   3. require() /home/michael/www/sae/bootstrap/start.php:95
    PHP   4. Illuminate\Foundation\ProviderRepository->load() /home/michael/www/sae/vendor/laravel/framework/src/Illuminate/Foundation/start.php:210
    PHP   5. Illuminate\Foundation\Application->register() /home/michael/www/sae/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:81
    PHP   6. PragmaRX\SqlI\Vendor\Laravel\ServiceProvider->register() /home/michael/www/sae/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:317
    {"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Cannot call abstract method Illuminate\\Support\\ServiceProvider::register()","file":"\/home\/michael\/www\/sae\/vendor\/pragmarx\/sqli\/src\/Vendor\/Laravel\/ServiceProvider.php","line":92}}
    
    opened by carcinocron 1
Owner
Antonio Carlos Ribeiro
Antonio Carlos Ribeiro
📝 Artisan Menu - Use Artisan via an elegant console GUI

?? Artisan Menu Use Artisan via an elegant console GUI Features Run built-in and custom Artisan commands from a console GUI Prompts to enter required

Jordan Hall 148 Nov 29, 2022
Create Laravel views (blade template) using 'php artisan' command-line interface

About LaraBit Have you ever wonder to create Laravel views (Blade Templates) using the same type of artisan commands that you usually use to create ne

Ragib MRB 5 Oct 15, 2021
This package is to add a web interface for Laravel 5 and earlier Artisan.

Nice Artisan This package is to add a web interface for Laravel 5 and earlier Artisan. Installation Add Nice Artisan to your composer.json file : For

null 218 Nov 29, 2022
Interactive Make Command for Laravel

Interactive Make for Laravel 5.4 Getting Started To get started you need to install the package with Composer: composer require laracademy/interactive

Laracademy 352 Dec 16, 2022
Make db:seed interactive

Make db:seed interactive Often forget what your seeder classes are called? This package can make db:seed interactive so you can see a list and choose

Craig Morris 28 Dec 9, 2022
Laravel Query Helper was developed for laravel 7.2+ to help you optimize sql queries

Laravel Query Helper Laravel Query Helper was developed for laravel 7.2+ to help you optimize sql queries, this package will contain all advanced SQL

Syrian Open Source 15 Nov 20, 2022
An extended laravel eloquent WHERE method to work with sql LIKE operator.

Laravel Eloquent WhereLike An extended laravel eloquent WHERE method to work with sql LIKE operator. Inspiration The idea of this package comes from o

Touhidur Rahman 33 Aug 6, 2022
Log executed Laravel SQL queries and their line number and more

A lightweight laravel package for logging executed SQL queries, line number and more

Md.Harun-Ur-Rashid 31 Dec 21, 2022
Sqlcommenter is a plugin/middleware/wrapper to augment SQL statements from laravel

sqlcommenter is a plugin/middleware/wrapper to augment SQL statements from laravel with comments that can be used later to correlate user code with SQL statements.

Google 7 Jul 14, 2022
Projeto de um sistema de pedidos de uma Pizzaria. Feito durante o curso "SQL - Básico ao Avançado" Dísponível na Udemy pelo instrutor Matheus Baptisti

PJ-Pizzaria Este projeto é um sistema de pedidos de uma Pizzaria. O objeto de estudo aqui é a conexão de PHP + BD, PHP e a WEB, Regras de negócio comp

João Pedro Sassi Granado 2 Nov 29, 2021