Skip to content
Permalink
Browse files

Merge pull request #21 from shadowhand/fix/insert-multi-factory

Add multi-line insert support to factory
  • Loading branch information...
shadowhand committed May 23, 2017
2 parents 1df7726 + 3caefa8 commit b9b041f951216115cbd84e079c029d5f2b658e11
Showing with 23 additions and 3 deletions.
  1. +2 −0 README.md
  2. +4 −2 src/InsertMultipleQuery.php
  3. +8 −0 src/QueryFactory.php
  4. +9 −1 tests/QueryFactoryTest.php
@@ -148,6 +148,8 @@ print_r($insert->params());
// ["first-token", "second-token"]
```

**Note:** There are no extensions for multi-line insert queries.

### UPDATE

```php
@@ -10,11 +10,13 @@ class InsertMultipleQuery implements Statement
/**
* Create a new multi-line insert query.
*/
public static function make(string $table, array $columns): InsertMultipleQuery
public static function make(string $table, array $columns = []): InsertMultipleQuery
{
$query = new static();
$query->table($table);
$query->columns($columns);
if ($columns) {
$query->columns($columns);
}
return $query;
}
@@ -44,6 +44,14 @@ public function insert(...$params): InsertQuery
return InsertQuery::make(...$params);
}
/**
* Create a new INSERT query with multiple values.
*/
public function insertMultiple(...$params): InsertMultipleQuery
{
return InsertMultipleQuery::make(...$params);
}
/**
* Create a new UPDATE query.
*/
@@ -22,6 +22,7 @@ public function testFactory(
string $engine,
string $selectClass,
string $insertClass,
string $insertMultipleClass,
string $updateClass,
string $deleteClass,
string $identifierClass
@@ -30,12 +31,14 @@ public function testFactory(
$select = $factory->select();
$insert = $factory->insert('users', []);
$insertMultiple = $factory->insertMultiple('users', ['username']);
$update = $factory->update('users', []);
$delete = $factory->delete('users');
$identifier = $factory->identifier();
$this->assertInstanceOf($selectClass, $select);
$this->assertInstanceOf($insertClass, $insert);
$this->assertInstanceOf($insertMultipleClass, $insertMultiple);
$this->assertInstanceOf($updateClass, $update);
$this->assertInstanceOf($deleteClass, $delete);
$this->assertInstanceOf($identifierClass, $identifier);
@@ -47,11 +50,12 @@ public function testFactory(
public function dataFactory()
{
return [
// engine, select, insert, update, delete, identifier
// engine, select, insert, multi-insert, update, delete, identifier
'MySQL' => [
'mysql',
SelectQuery::class,
InsertQuery::class,
InsertMultipleQuery::class,
UpdateQuery::class,
DeleteQuery::class,
MySQL\Identifier::class,
@@ -60,6 +64,7 @@ public function dataFactory()
'pgsql',
SelectQuery::class,
Postgres\InsertQuery::class,
InsertMultipleQuery::class,
Postgres\UpdateQuery::class,
Postgres\DeleteQuery::class,
Common\Identifier::class,
@@ -68,6 +73,7 @@ public function dataFactory()
'sqlsrv',
SelectQuery::class,
InsertQuery::class,
InsertMultipleQuery::class,
UpdateQuery::class,
DeleteQuery::class,
SqlServer\Identifier::class,
@@ -76,6 +82,7 @@ public function dataFactory()
'sqlite',
SelectQuery::class,
InsertQuery::class,
InsertMultipleQuery::class,
UpdateQuery::class,
DeleteQuery::class,
Common\Identifier::class,
@@ -84,6 +91,7 @@ public function dataFactory()
'',
SelectQuery::class,
InsertQuery::class,
InsertMultipleQuery::class,
UpdateQuery::class,
DeleteQuery::class,
Common\Identifier::class,

0 comments on commit b9b041f

Please sign in to comment.
You can’t perform that action at this time.