Skip to content

Commit

Permalink
chore: more database name
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Jul 24, 2020
1 parent 7a65755 commit b047c33
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 44 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ when you use sqlite in PHPUnit and you need MySQL version sql, you can set drive
```php
// eloquent-dumper.php
return [
// Supported: "pdo", "mysql", "sqlite", "postgres", "mssql"
'driver' => env('ELOQUENT_DUMPER_GRAMMAR', 'mysql'),
/*
* Supported: "pdo", "mysql", "sqlite", "pgsql", "sqlsrv"
*/
'driver' => env('ELOQUENT_DUMPER_GRAMMAR', 'pdo'),
];
```
## How to use
Expand Down
2 changes: 1 addition & 1 deletion config/eloquent-dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return [
/*
* Supported: "pdo", "mysql", "sqlite", "postgres", "mssql"
* Supported: "pdo", "mysql", "sqlite", "pgsql", "sqlsrv"
*/
'grammar' => env('ELOQUENT_DUMPER_GRAMMAR', 'pdo'),
];
4 changes: 3 additions & 1 deletion src/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

class Dumper
{
const PDO = 'pdo';
const NONE = 'none';
const PDO = 'pdo';
const MYSQL = 'mysql';
const SQLITE = 'sqlite';
const POSTGRES = 'postgres';
const PGSQL = 'pgsql';
const SQLSERVER = 'sqlserver';
const SQLSRV = 'sqlsrv';
const MSSQL = 'mssql';

/**
Expand Down
17 changes: 11 additions & 6 deletions src/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

namespace Recca0120\EloquentDumper\Grammars;

use Recca0120\EloquentDumper\Dumper;

abstract class Grammar
{
private static $lookup = [
'mysql' => MySqlGrammar::class,
'none' => NoneGrammar::class,
'postgres' => PostgresGrammar::class,
'sqlite' => SQLiteGrammar::class,
'sqlserver' => SqlServerGrammar::class,
'mssql' => SqlServerGrammar::class,
Dumper::NONE => NoneGrammar::class,
Dumper::PDO => PdoGrammar::class,
Dumper::MYSQL => MySqlGrammar::class,
Dumper::SQLITE => SQLiteGrammar::class,
Dumper::POSTGRES => PostgresGrammar::class,
Dumper::PGSQL => PostgresGrammar::class,
Dumper::SQLSERVER => SqlServerGrammar::class,
Dumper::SQLSRV => SqlServerGrammar::class,
Dumper::MSSQL => SqlServerGrammar::class,
];

/**
Expand Down
54 changes: 20 additions & 34 deletions tests/DumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ public function test_it_should_convert_to_none_quote_sql(Builder $query, $expect
{
$dumper = $this->givenDumper(Dumper::NONE);

$query->from('users')->whereIn('id', [1, 2, 3, 4, 5]);
$query->from('users')->whereIn('id', [1, null, false, 'foo']);

$this->assertSql($expected, $dumper, $query);
}

public function noneGrammarProvider()
{
return [
[$this->mysql(), 'select * from users where id in (1, 2, 3, 4, 5)'],
[$this->sqlite(), 'select * from users where id in (1, 2, 3, 4, 5)'],
[$this->postgres(), 'select * from users where id in (1, 2, 3, 4, 5)'],
[$this->sqlServer(), 'select * from users where id in (1, 2, 3, 4, 5)'],
[$this->mysql(), 'select * from users where id in (1, NULL, 0, \'foo\')'],
[$this->sqlite(), 'select * from users where id in (1, NULL, 0, \'foo\')'],
[$this->postgres(), 'select * from users where id in (1, NULL, 0, \'foo\')'],
[$this->sqlServer(), 'select * from users where id in (1, NULL, 0, \'foo\')'],
];
}

Expand All @@ -90,18 +90,18 @@ public function test_it_should_convert_to_mysql_version_sql(Builder $query, $exp
{
$dumper = $this->givenDumper(Dumper::MYSQL);

$query->from('users')->whereIn('id', [1, 2, 'App\User', 'don\'t be late']);
$query->from('users')->whereIn('id', [1, null, false, 'foo', 'App\User', 'don\'t be late']);

$this->assertSql($expected, $dumper, $query);
}

public function mySQLGrammarProvider()
{
return [
[$this->mysql(), "select * from `users` where `id` in (1, 2, 'App\\\\User', 'don\'t be late')"],
[$this->sqlite(), "select * from `users` where `id` in (1, 2, 'App\\\\User', 'don\'t be late')"],
[$this->postgres(), "select * from `users` where `id` in (1, 2, 'App\\\\User', 'don\'t be late')"],
[$this->sqlServer(), "select * from `users` where `id` in (1, 2, 'App\\\\User', 'don\'t be late')"],
[$this->mysql(), 'select * from `users` where `id` in (1, NULL, 0, \'foo\', \'App\\\\User\', \'don\\\'t be late\')'],
[$this->sqlite(), 'select * from `users` where `id` in (1, NULL, 0, \'foo\', \'App\\\\User\', \'don\\\'t be late\')'],
[$this->postgres(), 'select * from `users` where `id` in (1, NULL, 0, \'foo\', \'App\\\\User\', \'don\\\'t be late\')'],
[$this->sqlServer(), 'select * from `users` where `id` in (1, NULL, 0, \'foo\', \'App\\\\User\', \'don\\\'t be late\')'],
];
}

Expand All @@ -114,18 +114,18 @@ public function test_it_should_convert_to_sqlite_version_sql(Builder $query, $ex
{
$dumper = $this->givenDumper(Dumper::SQLITE);

$query->from('users')->whereIn('id', [1, 2, 'App\User', 'don\'t be late']);
$query->from('users')->whereIn('id', [1, null, false, 'foo', 'App\User', 'don\'t be late']);

$this->assertSql($expected, $dumper, $query);
}

public function sqliteGrammarProvider()
{
return [
[$this->mysql(), 'select * from "users" where "id" in (1, 2, \'App\\User\', \'don\'\'t be late\')'],
[$this->sqlite(), 'select * from "users" where "id" in (1, 2, \'App\\User\', \'don\'\'t be late\')'],
[$this->postgres(), 'select * from "users" where "id" in (1, 2, \'App\\User\', \'don\'\'t be late\')'],
[$this->sqlServer(), 'select * from "users" where "id" in (1, 2, \'App\\User\', \'don\'\'t be late\')'],
[$this->mysql(), 'select * from "users" where "id" in (1, NULL, 0, \'foo\', \'App\\User\', \'don\'\'t be late\')'],
[$this->sqlite(), 'select * from "users" where "id" in (1, NULL, 0, \'foo\', \'App\\User\', \'don\'\'t be late\')'],
[$this->postgres(), 'select * from "users" where "id" in (1, NULL, 0, \'foo\', \'App\\User\', \'don\'\'t be late\')'],
[$this->sqlServer(), 'select * from "users" where "id" in (1, NULL, 0, \'foo\', \'App\\User\', \'don\'\'t be late\')'],
];
}

Expand All @@ -138,35 +138,21 @@ public function test_it_should_convert_to_postgres_version_sql(Builder $query, $
{
$dumper = $this->givenDumper(Dumper::POSTGRES);

$query->from('users')->whereIn('id', [1, 2, 'App\User', 'don\'t be late']);
$query->from('users')->whereIn('id', [1, null, false, 'foo', 'App\User', 'don\'t be late']);

$this->assertSql($expected, $dumper, $query);
}

public function postgresGrammarProvider()
{
return [
[$this->mysql(), 'select * from "users" where "id" in (1, 2, \'App\\\\User\', \'don\'\'t be late\')'],
[$this->sqlite(), 'select * from "users" where "id" in (1, 2, \'App\\\\User\', \'don\'\'t be late\')'],
[$this->postgres(), 'select * from "users" where "id" in (1, 2, \'App\\\\User\', \'don\'\'t be late\')'],
[$this->sqlServer(), 'select * from "users" where "id" in (1, 2, \'App\\\\User\', \'don\'\'t be late\')'],
[$this->mysql(), 'select * from "users" where "id" in (1, NULL, 0, \'foo\', \'App\\\\User\', \'don\'\'t be late\')'],
[$this->sqlite(), 'select * from "users" where "id" in (1, NULL, 0, \'foo\', \'App\\\\User\', \'don\'\'t be late\')'],
[$this->postgres(), 'select * from "users" where "id" in (1, NULL, 0, \'foo\', \'App\\\\User\', \'don\'\'t be late\')'],
[$this->sqlServer(), 'select * from "users" where "id" in (1, NULL, 0, \'foo\', \'App\\\\User\', \'don\'\'t be late\')'],
];
}

/**
* @dataProvider sqlServerGrammarProvider
* @param Builder $query
* @param string $expected
*/
public function test_it_should_convert_to_mssql_version_sql(Builder $query, $expected)
{
$dumper = $this->givenDumper(Dumper::MSSQL);

$query->from('users')->whereIn('id', [1, 2, 3, 4, 5]);

$this->assertSql($expected, $dumper, $query);
}

/**
* @dataProvider sqlServerGrammarProvider
* @param Builder $query
Expand Down

0 comments on commit b047c33

Please sign in to comment.