Skip to content
This repository was archived by the owner on Aug 13, 2023. It is now read-only.

Commit b4c3831

Browse files
committed
add magick functions with helped trait
1 parent 5d05f5e commit b4c3831

4 files changed

Lines changed: 44 additions & 39 deletions

File tree

src/Database/Instruction.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Deimos\Database;
4+
5+
trait Instruction
6+
{
7+
public function query()
8+
{
9+
$query = $this;
10+
11+
return $this->database->transaction()->call(function ($database) use ($query)
12+
{
13+
/**
14+
* @var Database $database
15+
*/
16+
return $database
17+
->queryInstruction($query)
18+
->rowCount();
19+
});
20+
}
21+
}

src/Database/Queries/Delete.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@
44

55
use Deimos\Database\Database;
66
use Deimos\QueryBuilder\Instruction;
7-
use Deimos\QueryBuilder\QueryBuilder;
87

8+
/**
9+
* Class Delete
10+
*
11+
* @package Deimos\Database\Queries
12+
*
13+
* @method int delete()
14+
*/
915
class Delete extends Instruction\Delete
1016
{
1117

18+
use \Deimos\Database\Instruction
19+
{
20+
query as delete;
21+
}
22+
1223
/**
1324
* @var Database
1425
*/
@@ -25,22 +36,4 @@ public function __construct(Database $database)
2536
$this->database = $database;
2637
}
2738

28-
/**
29-
* @return int
30-
*/
31-
public function delete()
32-
{
33-
$query = $this;
34-
35-
return $this->database->transaction()->call(function ($database) use ($query)
36-
{
37-
/**
38-
* @var Database $database
39-
*/
40-
return $database
41-
->queryInstruction($query)
42-
->rowCount();
43-
});
44-
}
45-
4639
}

src/Database/Queries/Query.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Deimos\Database\Connection;
66
use Deimos\Database\Database;
77
use Deimos\QueryBuilder\Instruction\Select;
8-
use Deimos\QueryBuilder\QueryBuilder;
98

109
class Query extends Select
1110
{

src/Database/Queries/Update.php

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@
44

55
use Deimos\Database\Database;
66
use Deimos\QueryBuilder\Instruction;
7-
use Deimos\QueryBuilder\QueryBuilder;
87

8+
/**
9+
* Class Update
10+
*
11+
* @package Deimos\Database\Queries
12+
*
13+
* @method int update()
14+
*/
915
class Update extends Instruction\Update
1016
{
1117

18+
use \Deimos\Database\Instruction {
19+
query as update;
20+
}
21+
1222
/**
1323
* @var Database
1424
*/
@@ -25,22 +35,4 @@ public function __construct(Database $database)
2535
$this->database = $database;
2636
}
2737

28-
/**
29-
* @return int
30-
*/
31-
public function update()
32-
{
33-
$query = $this;
34-
35-
return $this->database->transaction()->call(function ($database) use ($query)
36-
{
37-
/**
38-
* @var Database $database
39-
*/
40-
return $database
41-
->queryInstruction($query)
42-
->rowCount();
43-
});
44-
}
45-
4638
}

0 commit comments

Comments
 (0)