https://github.com/xp-forge/sql
SQL Subcommand
https://github.com/xp-forge/sql
command-line php sql xp-framework
Last synced: 4 months ago
JSON representation
SQL Subcommand
- Host: GitHub
- URL: https://github.com/xp-forge/sql
- Owner: xp-forge
- Created: 2017-05-30T08:55:55.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-10-05T11:14:37.000Z (over 1 year ago)
- Last Synced: 2025-04-24T01:47:21.070Z (about 1 year ago)
- Topics: command-line, php, sql, xp-framework
- Language: PHP
- Size: 35.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
Awesome Lists containing this project
README
SQL subcommand
==============
[](https://github.com/xp-forge/sql/actions)
[](https://github.com/xp-framework/core)
[](https://github.com/xp-framework/core/blob/master/LICENCE.md)
[](http://php.net/)
[](http://php.net/)
[](https://packagist.org/packages/xp-forge/sql)
SQL command line tool using XP database drivers.
## Installation
```bash
$ composer global require xp-forge/sql 'dev-master'
```
## Usage
```bash
$ xp help sql
@FileSystemCL<./src/main/php>
Runs SQL statements
════════════════════════════════════════════════════════════════════════
> Execute a single SQL statement and print the results
$ xp sql 'sqlite://./test.db' 'select * from test'
> Change output mode by appending -m and one of csv, vert
$ xp sql 'sqlite://./test.db' 'select * from test;-m csv'
> Read SQL statement from standard input using "-"
$ cat statement.sql | xp sql 'sqlite://./test.db' -
> Use named connections as configured in connections.ini.
$ xp sql dev-db 'select * from account where id = 1'
The file connections.ini is per-user and can be found in one of:
> %LOCALAPPDATA%/Xp-forge.sql/ on Windows
> $XDG_CONFIG_HOME/xp-forge.sql/ inside an XDG environment
> $HOME/.xp-forge.sql/ otherwise
Invoking without arguments shows a list of available drivers.
```
*The `-m [vert,csv]` syntax is inspired by SQSH, see http://manpages.ubuntu.com/manpages/precise/man1/sqsh.1.html*
## Drivers
```bash
$ xp sql
@FileSystemCL<./src/main/php>
Available drivers via rdbms.DefaultDrivers
════════════════════════════════════════════════════════════════════════
> mysql+x: rdbms.mysqlx.MySqlxConnection
Connection to MySQL Databases
> mysql+std: rdbms.mysql.MySQLConnection
Connection to MySQL Databases via ext/mysql
> sybase+x: rdbms.tds.SybasexConnection
Connection to Sybase Databases via TDS 5.0
> mssql+x: rdbms.tds.MsSQLxConnection
Connection to MSSQL Databases via TDS 7.0
> sqlite+3: rdbms.sqlite3.SQLite3Connection
Connection to SQLite 3.x Databases via ext/sqlite3
```
## Examples
```bash
$ xp sql 'sqlite://./test.db' 'create table test (
id integer primary key autoincrement,
name varchar
)'
Query OK, 0 rows affected (0.02 sec)
$ xp sql 'sqlite://./test.db' 'insert into test (name) values ("Timm")'
Query OK, 1 rows affected (0.02 sec)
$ xp sql 'sqlite://./test.db' 'select * from test where id = 1'
id: 1
name: "Timm"
1 rows in set (0.00 sec)
```