Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into improve-psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed May 10, 2024
2 parents 8ece1dd + 25de1a6 commit 1c1fb28
Show file tree
Hide file tree
Showing 23 changed files with 166 additions and 212 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
- Bug #828: Fix `float` type when use `AbstractCommand::getRawSql()` method (@Tigrov)
- Enh #829: Rename `batchInsert()` to `insertBatch()` in `DMLQueryBuilderInterface` and `CommandInterface`
and change parameters from `$table, $columns, $rows` to `$table, $rows, $columns = []` (@Tigrov)
- Enh #834: Refactor `AbstractCommand::insertBatch()`, add `Quoter::getRawTableName()` to `QuoterInterface` (@Tigrov)
- Chg #836: Remove `AbstractDMLQueryBuilder::getTypecastValue()` method (@Tigrov)
- Chg #837: Remove `$table` parameter from `normalizeColumnNames()` and `getNormalizeColumnNames()` methods
of `AbstractDMLQueryBuilder` class (@Tigrov)
- Chg #838: Remove `SchemaInterface::TYPE_JSONB` constant (@Tigrov)
- Chg #839: Remove `TableSchemaInterface::compositeForeignKey()` method (@Tigrov)
- Chg #840: Remove parameter `$withColumn` from `QuoterInterface::getTableNameParts()` method (@Tigrov)
- Enh #840: Remove `Quoter::unquoteParts()` method (@Tigrov)
- Chg #841: Remove `$rawSql` parameter from `AbstractCommand::internalExecute()` method
and `AbstractPdoCommand::internalExecute()` method (@Tigrov)
- Enh #842: Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method (@Tigrov)

## 1.3.0 March 21, 2024

Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
<h1 align="center">Yii Database</h1>
</p>

[![Latest Stable Version](https://poser.pugx.org/yiisoft/db/v/stable.png)](https://packagist.org/packages/yiisoft/db)
[![Total Downloads](https://poser.pugx.org/yiisoft/db/downloads.png)](https://packagist.org/packages/yiisoft/db)
[![Build status](https://github.com/yiisoft/db/workflows/build/badge.svg)](https://github.com/yiisoft/db/actions?query=workflow%3Abuild)
[![codecov](https://codecov.io/gh/yiisoft/db/branch/master/graph/badge.svg?token=pRr4gci2qj)](https://codecov.io/gh/yiisoft/db)
[![static analysis](https://github.com/yiisoft/db/actions/workflows/static.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db/actions/workflows/static.yml)
[![type-coverage](https://shepherd.dev/github/yiisoft/db/coverage.svg)](https://shepherd.dev/github/yiisoft/db)

Yii Database is a framework-agnostic package to work with different types of databases,
such as [MariaDB], [MSSQL], [MySQL], [Oracle], [PostgreSQL], and [SQLite].
such as [MariaDB], [MSSQL], [MySQL], [Oracle], [PostgreSQL] and [SQLite].

Using the package, you can perform common database tasks such as creating, reading, updating, and deleting
records in a database table, as well as executing raw SQL queries.
Expand Down Expand Up @@ -35,13 +42,6 @@ similar to the way you would use ORM (Object-Relational Mapping) frameworks like
[PostgreSQL]: https://www.postgresql.org
[SQLite]: https://www.sqlite.org

[![Latest Stable Version](https://poser.pugx.org/yiisoft/db/v/stable.png)](https://packagist.org/packages/yiisoft/db)
[![Total Downloads](https://poser.pugx.org/yiisoft/db/downloads.png)](https://packagist.org/packages/yiisoft/db)
[![Build status](https://github.com/yiisoft/db/workflows/build/badge.svg)](https://github.com/yiisoft/db/actions?query=workflow%3Abuild)
[![codecov](https://codecov.io/gh/yiisoft/db/branch/master/graph/badge.svg?token=pRr4gci2qj)](https://codecov.io/gh/yiisoft/db)
[![static analysis](https://github.com/yiisoft/db/actions/workflows/static.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db/actions/workflows/static.yml)
[![type-coverage](https://shepherd.dev/github/yiisoft/db/coverage.svg)](https://shepherd.dev/github/yiisoft/db)

## Requirements

- PHP 8.0 or higher.
Expand Down
36 changes: 33 additions & 3 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Upgrading Instructions for Yii Database
# Yii Database Upgrading Instructions

The following upgrading instructions are cumulative. That is, if you want to upgrade from version A to version C and
there is version B between A and C, you need to following the instructions for both A and B.
> **!!!IMPORTANT!!!**
>
> The following upgrading instructions are *cumulative*. That is,
> if you want to upgrade from version A to version C and there is
> version B between A and C, you need to following the instructions
> for both A and B.
## Upgrade from 1.x to 2.x

Expand Down Expand Up @@ -54,3 +58,29 @@ $values = [
/** @var ConnectionInterface $db */
$db->createCommand()->insertBatch('user', $values)->execute();
```

### New methods in `QuoterInterface`

- `QuoterInterface::getRawTableName()` - returns the raw table name without quotes.

### Remove methods

- `AbstractDMLQueryBuilder::getTypecastValue()`
- `TableSchemaInterface::compositeForeignKey()`
- `Quoter::unquoteParts()`

### Remove deprecated parameters

- `$table` from `AbstractDMLQueryBuilder::normalizeColumnNames()` method
- `$table` from `AbstractDMLQueryBuilder::getNormalizeColumnNames()` method
- `$withColumn` from `QuoterInterface::getTableNameParts()` method
- `$rawSql` from `AbstractCommand::internalExecute()` method
- `$rawSql` from `AbstractPdoCommand::internalExecute()` method

### Remove deprecated constants

- `SchemaInterface::TYPE_JSONB`

### Other changes

- Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method
8 changes: 1 addition & 7 deletions docs/guide/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ Yii DB supports the following databases out of the box:
- [PostgreSQL](https://www.postgresql.org/) of versions **9.6 - 15**.
- [SQLite](https://www.sqlite.org/) of version **3.3 and above**.

## Requirements

- PHP 8.0 or higher.

## Installation

To install Yii DB, you must select the driver you want to use and install it with [Composer](https://getcomposer.org/).
To install Yii DB, you must select the driver you want to use and install it with [Composer](https://getcomposer.org).

For [MSSQL](https://github.com/yiisoft/db-mssql):

Expand Down Expand Up @@ -61,8 +57,6 @@ For [SQLite](https://github.com/yiisoft/db-sqlite):
composer require yiisoft/db-sqlite
```

## Prerequisites

## Configure schema cache

First, you need to [configure database schema cache](schema/cache.md).
Expand Down
10 changes: 2 additions & 8 deletions docs/guide/pt-BR/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ Yii DB suporta os seguintes bancos de dados prontos para uso:
- [PostgreSQL](https://www.postgresql.org/) das versões **9.6 - 15**.
- [SQLite](https://www.sqlite.org/) da versão **3.3 e superior**.

## Requerimentos
## Installation

- PHP 8.0 or higher.

## Instalação

Para instalar o Yii DB, você deve selecionar o driver que deseja usar e instalá-lo com o [Composer](https://getcomposer.org/).
Para instalar o Yii DB, você deve selecionar o driver que deseja usar e instalá-lo com o [Composer](https://getcomposer.org).

Para [MSSQL](https://github.com/yiisoft/db-mssql):

Expand Down Expand Up @@ -61,8 +57,6 @@ Para [SQLite](https://github.com/yiisoft/db-sqlite):
composer require yiisoft/db-sqlite
```

## Pré-requisitos

## Configurar cache de esquema

Primeiro, você precisa [configurar o cache do esquema do banco de dados](schema/cache.md).
Expand Down
64 changes: 63 additions & 1 deletion docs/internals.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,68 @@
# Internals

- [Testing](./testing.md)
## Unit testing

This package can be tested globally or individually for each DBMS.

- [MSSQL](https://github.com/yiisoft/db-mssql)
- [MySQL/MariaDB](https://github.com/yiisoft/db-mysql)
- [Oracle](https://github.com/yiisoft/db-oracle)
- [PostgreSQL](https://github.com/yiisoft/db-pgsql)
- [SQLite](https://github.com/yiisoft/db-sqlite)

### Github actions

All our packages have github actions by default, so you can test your [contribution](https://github.com/yiisoft/db/blob/master/.github/CONTRIBUTING.md) in the cloud.

> Note: We recommend pull requesting in draft mode until all tests pass.
### Docker images

For greater ease it is recommended to use Docker containers for each DBMS, for this you can use the [docker-compose.yml](https://docs.docker.com/compose/compose-file/) file that in the root directory of each package.

- [MSSQL 2022](https://github.com/yiisoft/db-mssql/blob/master/docker-compose.yml)
- [MySQL 8](https://github.com/yiisoft/db-mysql/blob/master/docker-compose.yml)
- [MariaDB 10.11](https://github.com/yiisoft/db-mysql/blob/master/docker-compose-mariadb.yml)
- [Oracle 21](https://github.com/yiisoft/db-oracle/blob/master/docker-compose.yml)
- [PostgreSQL 15](https://github.com/yiisoft/db-pgsql/blob/master/docker-compose.yml)

For running the Docker containers you can use the following command:

```shell
docker compose up -d
```

### Global testing

The package is tested with [PHPUnit](https://phpunit.de/). To run tests:

1. Run all Docker containers for each DBMS.
2. Install the dependencies of the project with composer.
3. Run the tests.

```shell
./vendor/bin/phpunit
```

### Individual testing

The package is tested with [PHPUnit](https://phpunit.de/). To run tests:

1. Run the Docker container for the dbms you want to test.
2. Install the dependencies of the project with composer.
3. Run the tests.

```shell
./vendor/bin/phpunit --testsuite=Pgsql
```

Suites available:

- Mssql
- Mysql
- Oracle
- Pgsql
- Sqlite

## Static analysis

Expand Down
63 changes: 0 additions & 63 deletions docs/testing.md

This file was deleted.

15 changes: 3 additions & 12 deletions src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,7 @@ public function batchInsert(string $table, array $columns, iterable $rows): stat

public function insertBatch(string $table, iterable $rows, array $columns = []): static
{
$table = $this->getQueryBuilder()->quoter()->quoteSql($table);

/** @psalm-var string[] $columns */
foreach ($columns as &$column) {
$column = $this->getQueryBuilder()->quoter()->quoteSql($column);
}

unset($column);
$table = $this->getQueryBuilder()->quoter()->getRawTableName($table);

$params = [];
$sql = $this->getQueryBuilder()->insertBatch($table, $rows, $columns, $params);
Expand Down Expand Up @@ -563,12 +556,10 @@ abstract protected function internalGetQueryResult(int $queryMode): mixed;
/**
* Executes a prepared statement.
*
* @param string|null $rawSql Deprecated. Use `null` value. Will be removed in version 2.0.0.
*
* @throws Exception
* @throws Throwable
*/
abstract protected function internalExecute(string|null $rawSql): void;
abstract protected function internalExecute(): void;

/**
* Check if the value has a given flag.
Expand Down Expand Up @@ -596,7 +587,7 @@ protected function queryInternal(int $queryMode): mixed
$isReadMode = $this->isReadMode($queryMode);
$this->prepare($isReadMode);

$this->internalExecute(null);
$this->internalExecute();

/** @psalm-var mixed $result */
$result = $this->internalGetQueryResult($queryMode);
Expand Down
6 changes: 2 additions & 4 deletions src/Driver/Pdo/AbstractPdoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,10 @@ protected function getQueryMode(int $queryMode): string
*
* It's a wrapper around {@see PDOStatement::execute()} to support transactions and retry handlers.
*
* @param string|null $rawSql Deprecated. Use `null` value. Will be removed in version 2.0.0.
*
* @throws Exception
* @throws Throwable
*/
protected function internalExecute(string|null $rawSql): void
protected function internalExecute(): void
{
$attempt = 0;

Expand All @@ -202,7 +200,7 @@ protected function internalExecute(string|null $rawSql): void
&& $this->db->getTransaction() === null
) {
$this->db->transaction(
fn () => $this->internalExecute($rawSql),
fn () => $this->internalExecute(),
$this->isolationLevel
);
} else {
Expand Down
7 changes: 5 additions & 2 deletions src/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,11 @@ public function where(array|string|ExpressionInterface|null $condition, array $p
return $this;
}

public function withQuery(QueryInterface|string $query, string $alias, bool $recursive = false): static
{
public function withQuery(
QueryInterface|string $query,
ExpressionInterface|string $alias,
bool $recursive = false
): static {
$this->withQueries[] = ['query' => $query, 'alias' => $alias, 'recursive' => $recursive];
return $this;
}
Expand Down
9 changes: 7 additions & 2 deletions src/Query/QueryPartsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,15 @@ public function where(array|string|ExpressionInterface|null $condition, array $p
* Prepends an SQL statement using `WITH` syntax.
*
* @param QueryInterface|string $query The SQL statement to append using `UNION`.
* @param string $alias The query alias in `WITH` construction.
* @param ExpressionInterface|string $alias The query alias in `WITH` construction.
* To specify the alias in plain SQL, you may pass an instance of {@see ExpressionInterface}.
* @param bool $recursive Its `true` if using `WITH RECURSIVE` and `false` if using `WITH`.
*/
public function withQuery(QueryInterface|string $query, string $alias, bool $recursive = false): static;
public function withQuery(
QueryInterface|string $query,
ExpressionInterface|string $alias,
bool $recursive = false
): static;

/**
* Specifies the `WITH` query clause for the query.
Expand Down
Loading

0 comments on commit 1c1fb28

Please sign in to comment.