Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop: (49 commits)
  specify next release
  remove remnants of phpunit
  fix property name
  use builtin memory assertion
  use builtin method to disable memory limit
  use comparator\property instead of anonymous classes
  simplify specifications usage in the documentation
  update changelog
  fix constructor
  use named constructors
  fix CS config
  fix example
  simplify documentation
  update changelog as it now requires specification 4.1
  remove phpunit
  move phpunit tests to blackbox
  remove logger tests
  use concrete classes instead of mocks
  typo
  fix generating column name with a multibyte string length above 63
  ...
  • Loading branch information
Baptouuuu committed Jul 14, 2024
2 parents 5ed45c6 + 8264837 commit e71b05f
Show file tree
Hide file tree
Showing 91 changed files with 1,809 additions and 2,005 deletions.
88 changes: 18 additions & 70 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ jobs:
MYSQL_DATABASE: example
ports:
- 3306
postgres:
image: postgres:16
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: example
ports:
- 5432
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -36,6 +44,7 @@ jobs:
run: php blackbox.php
env:
DB_PORT: ${{ job.services.mariadb.ports[3306] }}
POSTGRES_DB_PORT: ${{ job.services.postgres.ports[5432] }}
coverage:
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -52,6 +61,14 @@ jobs:
MYSQL_DATABASE: example
ports:
- 3306
postgres:
image: postgres:16
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: example
ports:
- 5432
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -70,76 +87,7 @@ jobs:
env:
ENABLE_COVERAGE: 'true'
DB_PORT: ${{ job.services.mariadb.ports[3306] }}
- uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
phpunit:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
php-version: ['8.2', '8.3']
dependencies: ['lowest', 'highest']
name: 'PHPUnit'
services:
mariadb:
image: mariadb:10
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: example
ports:
- 3306
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
coverage: none
- name: Composer
uses: "ramsey/composer-install@v2"
with:
dependency-versions: ${{ matrix.dependencies }}
- name: PHPUnit
run: vendor/bin/phpunit
env:
DB_PORT: ${{ job.services.mariadb.ports[3306] }}
coverage_phpunit:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
php-version: ['8.2', '8.3']
dependencies: ['lowest', 'highest']
name: 'Coverage PHPUnit'
services:
mariadb:
image: mariadb:10
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: example
ports:
- 3306
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
coverage: xdebug
- name: Composer
uses: "ramsey/composer-install@v2"
with:
dependency-versions: ${{ matrix.dependencies }}
- name: PHPUnit
run: vendor/bin/phpunit --coverage-clover=coverage.clover
env:
BLACKBOX_SET_SIZE: 1
DB_PORT: ${{ job.services.mariadb.ports[3306] }}
POSTGRES_DB_PORT: ${{ job.services.postgres.ports[5432] }}
- uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/composer.lock
/vendor
/.phpunit.result.cache
/.phpunit.cache
/.cache
/tmp
1 change: 0 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
return Innmind\CodingStandard\CodingStandard::config([
'properties',
'fixtures',
'tests',
'src',
]);
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Changelog

## 3.0.0 - 2024-07-14

### Added

- `Formal\AccessLayer\Driver`
- `Formal\AccessLayer\Query\MultipleInsert`
- `Formal\AccessLayer\Table\Column\Type::uuid()`
- `Formal\AccessLayer\Table\Column\Type::bool()`
- `Formal\AccessLayer\Connection\Lazy::of()`
- `Formal\AccessLayer\Row::new()`
- `Formal\AccessLayer\Row\Value::of()`

### Changed

- Requires `innmind/specification:~4.1`
- `Formal\AccessLayer\Query::sql()` now has a `Driver` argument
- `Formal\AccessLayer\Query\Insert::into()` only accepts 1 `Row`, for multiple rows use `MultipleInsert` instead
- `Formal\AccessLayer\Connection\Lazy` constructor is now private, use `::of()` instead
- `Formal\AccessLayer\Row` constructor is now private, use `::new()` instead
- `Formal\AccessLayer\Row\Value` constructor is now private, use `::of()` instead
- `Formal\AccessLayer\Table\Column` constructor is now private, use `::of()` instead
- `Formal\AccessLayer\Table\Column\Name` constructor is now private, use `::of()` instead
- `Formal\AccessLayer\Table\Name` constructor is now private, use `::of()` instead

### Removed

- `Formal\AccessLayer\Query\Delete::join()`
- `Formal\AccessLayer\Query\Update::join()`

## 2.17.0 - 2024-05-29

### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use Formal\AccessLayer\{
use Innmind\Url\Url;
use Innmind\Immutable\Sequence;

$connection = new Lazy(static fn() => PDO::of(Url::of('mysql://user:[email protected]:3306/database_name')));
$connection = Lazy::of(static fn() => PDO::of(Url::of('mysql://user:[email protected]:3306/database_name')));

$rows = $connection(SQL::of('SELECT * FROM `some_table`'));
$rows; // instanceof Sequence<Row>
Expand Down
3 changes: 1 addition & 2 deletions blackbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

require 'vendor/autoload.php';

\ini_set('memory_limit', '-1');

use Innmind\BlackBox\{
Application,
Runner\Load,
Runner\CodeCoverage,
};

Application::new($argv)
->disableMemoryLimit()
->codeCoverage(
CodeCoverage::of(
__DIR__.'/src/',
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"php": "~8.2",
"innmind/immutable": "~4.0|~5.0",
"innmind/url": "~4.0",
"innmind/specification": "^3.0.1",
"innmind/specification": "~4.1",
"psr/log": "~3.0"
},
"autoload": {
Expand All @@ -34,7 +34,6 @@
}
},
"require-dev": {
"phpunit/phpunit": "~10.2",
"vimeo/psalm": "~5.13",
"innmind/black-box": "^5.6.1",
"innmind/coding-standard": "~2.0"
Expand Down
9 changes: 8 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '2'
services:
mariadb:
image: mariadb:10
Expand All @@ -7,3 +6,11 @@ services:
MYSQL_DATABASE: example
ports:
- '3306:3306'
postgres:
image: postgres:16
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: example
ports:
- '5432:5432'
4 changes: 2 additions & 2 deletions documentation/connections/lazy.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use Formal\AccessLayer\{
};
use Innmind\Url\Url;

$connection = new Lazy(
$connection = Lazy::of(
static fn() => PDO::of(
Url::of('mysql://user:[email protected]:3306/database_name'),
),
);
```

By passing a callable to the constructor allows you to use [whatever implementation](own.md) of a `Connection` you wish to lazy load.
By passing a callable to the constructor it allows you to use [whatever implementation](own.md) of a `Connection` you wish to lazy load.
12 changes: 4 additions & 8 deletions documentation/connections/own.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@ use Sentry\ClientInterface;

final class Sentry implements Connection
{
private Connection $connection;
private ClientInterface $sentry;

public function __construct(Connection $connection, ClientInterface $sentry)
{
$this->connection = $connection;
$this->sentry = $sentry;
}
public function __construct(
private Connection $connection,
private ClientInterface $sentry,
) {}

public function __invoke(Query $query): Sequence
{
Expand Down
33 changes: 27 additions & 6 deletions documentation/connections/pdo.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,35 @@ This is the basic connection from this library which is a simple abstraction on

To build an instance of it you only need the dsn to your database:

```php
use Formal\AccessLayer\Connection\PDO;
use Innmind\Url\Url;
=== "MySQL/MariaDB"
```php
use Formal\AccessLayer\Connection\PDO;
use Innmind\Url\Url;

$connection = PDO::of(Url::of('mysql://user:[email protected]:3306/database_name?charset=utf8mb4'));
```
$connection = PDO::of(
Url::of('mysql://user:[email protected]:3306/database_name?charset=utf8mb4')
);
```

When executing a [query](../queries/sql.md) through this connection it will return a [deferred `Sequence`](https://innmind.github.io/Immutable/SEQUENCE.html#defer) of rows. This means that the rows returned from the database are only loaded once you iterate over the sequence. (Queries with the named constructor `::onDemand()` will return a lazy `Sequence`).
=== "PostgreSQL"
```php
use Formal\AccessLayer\Connection\PDO;
use Innmind\Url\Url;

$connection = PDO::of(
Url::of('pgsql://user:[email protected]:5432/database_name?charset=utf8mb4')
);
```

=== "SQLite"
```php
use Formal\AccessLayer\Connection\PDO;
use Innmind\Url\Url;

$connection = PDO::of(Url::of('sqlite:///path/to/database/file.sq3'));
```

When executing a [query](../queries/sql.md) through this connection it will return a [deferred `Sequence`](http://innmind.github.io/Immutable/structures/sequence/#defer) of rows. This means that the rows returned from the database are only loaded once you iterate over the sequence. (Queries with the named constructor `::onDemand()` will return a lazy `Sequence`).

!!! note ""
As soon as you instanciate the class it will open a connection to the database, if you want to open it upon first query take a look at the [`Lazy` connection](lazy.md).
44 changes: 22 additions & 22 deletions documentation/queries/create_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use Formal\AccessLayer\{
};

$create = CreateTable::named(
new Name('users'),
new Column(
new Column\Name('username'),
Name::of('users'),
Column::of(
Column\Name::of('username'),
Column\Type::varchar(),
),
new Column(
new Column\Name('name'),
Column::of(
Column\Name::of('name'),
Column\Type::varchar(),
),
);
Expand All @@ -31,13 +31,13 @@ use Formal\AccessLayer\{
};

$create = CreateTable::ifNotExists(
new Name('users'),
new Column(
new Column\Name('username'),
Name::of('users'),
Column::of(
Column\Name::of('username'),
Column\Type::varchar(),
),
new Column(
new Column\Name('name'),
Column::of(
Column\Name::of('name'),
Column\Type::varchar(),
),
);
Expand All @@ -52,34 +52,34 @@ You can specify the primary key of the table like so:

```php
$create = CreateTable::named(
new Name('users'),
new Column(
new Column\Name('id'),
Name::of('users'),
Column::of(
Column\Name::of('id'),
Column\Type::int(),
),
);
$create = $create->primaryKey(new Column\Name('id'));
$create = $create->primaryKey(Column\Name::of('id'));
$connection($create);
```

### Foreign key

```php
$create = CreateTable::named(
new Name('address'),
new Column(
new Column\Name('user'),
Name::of('address'),
Column::of(
Column\Name::of('user'),
Column\Type::int(),
),
new Column(
new Column\Name('address'),
Column::of(
Column\Name::of('address'),
Column\Type::text(),
),
);
$create = $create->foreignKey(
new Column\Name('user'),
new Name('users'),
new Column\Name('id'),
Column\Name::of('user'),
Name::of('users'),
Column\Name::of('id'),
);
$connection($create);
```
Expand Down
Loading

0 comments on commit e71b05f

Please sign in to comment.