Skip to content

Commit 029fd39

Browse files
committed
new version (from mysql git)
1 parent 125a219 commit 029fd39

26 files changed

+372
-103
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "leven-framework/dba-common",
33
"type": "library",
44
"suggest": {
5-
"leven-framework/dba-mock": "Mock a database using e.g. a local file",
5+
"leven-framework/dba-mock": "Mock a database using an array",
66
"leven-framework/dba-mysql": "PDO MySQL adapter"
77
},
88
"autoload": {

composer.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AdapterInterface.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Leven\DBA\Common;
4+
5+
use Leven\DBA\Common\Exception\DriverException;
6+
use Leven\DBA\Common\Exception\TxnNotActiveException;
7+
8+
interface AdapterInterface
9+
{
10+
11+
public function select(string $table): SelectQueryInterface;
12+
13+
/**
14+
* @throws \Leven\DBA\Common\Exception\DriverException
15+
*/
16+
public function insert(string $table, ?array $data = null): InsertQueryInterface|AdapterResponse;
17+
18+
public function update(string $table): UpdateQueryInterface;
19+
20+
public function delete(string $table): DeleteQueryInterface;
21+
22+
/**
23+
* @throws \Leven\DBA\Common\Exception\DriverException
24+
*/
25+
public function txnBegin(): static;
26+
27+
/**
28+
* @throws \Leven\DBA\Common\Exception\TxnNotActiveException
29+
* @throws DriverException
30+
*/
31+
public function txnCommit(): static;
32+
33+
/**
34+
* @throws \Leven\DBA\Common\Exception\TxnNotActiveException
35+
* @throws DriverException
36+
*/
37+
public function txnRollback(): static;
38+
}

src/AdapterResponse.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php namespace Leven\DBA\Common;
2+
3+
use ArrayIterator, ArrayObject, IteratorAggregate;
4+
5+
class AdapterResponse implements IteratorAggregate {
6+
7+
public function __construct(
8+
public readonly int $count,
9+
public readonly array $rows = [],
10+
public readonly int|string|null $lastId = null,
11+
)
12+
{
13+
}
14+
15+
public function getIterator(): ArrayIterator
16+
{
17+
$o = new ArrayObject($this->rows);
18+
return $o->getIterator();
19+
}
20+
21+
}

src/BuilderPart/ColumnTrait.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Leven\DBA\Common\BuilderPart;
4+
5+
trait ColumnTrait
6+
{
7+
8+
protected array|string $columns = [];
9+
10+
public function columns(string ...$columns): static
11+
{
12+
$this->columns = [...$this->columns, ...$columns];
13+
return $this;
14+
}
15+
16+
public function rawColumns(string $columns): static
17+
{
18+
$this->columns = $columns;
19+
return $this;
20+
}
21+
22+
}

src/BuilderPart/LimitTrait.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Leven\DBA\Common\BuilderPart;
4+
5+
trait LimitTrait
6+
{
7+
8+
protected int $limit = 0;
9+
protected int $offset = 0;
10+
11+
public function limit(int $limitOrOffset, int $limit = 0): static
12+
{
13+
if($limit !== 0) $this->offset = $limitOrOffset;
14+
$this->limit = $limit === 0 ? $limitOrOffset : $limit;
15+
16+
return $this;
17+
}
18+
19+
public function offset(int $offset): static
20+
{
21+
$this->offset = $offset;
22+
return $this;
23+
}
24+
25+
}

src/BuilderPart/OrderTrait.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Leven\DBA\Common\BuilderPart;
4+
5+
trait OrderTrait
6+
{
7+
8+
protected array $order = [];
9+
10+
public function orderAsc(string $column): static
11+
{
12+
$this->order[$column] = 'ASC';
13+
return $this;
14+
}
15+
16+
public function orderDesc(string $column): static
17+
{
18+
$this->order[$column] = 'DESC';
19+
return $this;
20+
}
21+
22+
}

src/BuilderPart/SetTrait.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Leven\DBA\Common\BuilderPart;
4+
5+
trait SetTrait
6+
{
7+
8+
protected array $data = [];
9+
10+
public function set(array|string $dataOrColumn, null|string|bool|int|float $value = null): static
11+
{
12+
if(is_array($dataOrColumn)) {
13+
$this->data = [...$this->data, ...$dataOrColumn];
14+
return $this;
15+
}
16+
17+
$this->data[$dataOrColumn] = $value;
18+
19+
return $this;
20+
}
21+
22+
}

src/BuilderPart/WhereCondition.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Leven\DBA\Common\BuilderPart;
4+
5+
class WhereCondition
6+
{
7+
8+
public function __construct(
9+
public readonly bool $isOr,
10+
public readonly string $column,
11+
public readonly null|string|bool|int|float $value,
12+
public readonly string $operand = '<=>',
13+
)
14+
{
15+
}
16+
17+
}

src/BuilderPart/WhereGroup.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Leven\DBA\Common\BuilderPart;
4+
5+
class WhereGroup
6+
{
7+
8+
use WhereTrait;
9+
10+
public function __construct(
11+
public readonly bool $isOr,
12+
)
13+
{
14+
}
15+
16+
public function getConditions(): array
17+
{
18+
return $this->conditions;
19+
}
20+
21+
}

0 commit comments

Comments
 (0)