Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 12 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
<br>
</p>

**Yii Database SQLite Extension** is a package for working with [SQLite] databases in PHP. It is a part of the [Yii Framework], which is a high-performance, component-based framework for developing modern web applications.
**Yii Database SQLite Extension** is a package for working with [SQLite]databases in PHP. It's a part of the [Yii Framework], which is a high-performance, component-based framework for developing modern web applications.

The package provides a set of classes for interacting with [SQLite] databases in PHP. It includes a database connection class, a command builder class, and a set of classes for representing database tables and rows as PHP objects.
The package provides a set of classes for interacting with [SQLite]databases in PHP. It includes a database connection class, a command builder class, and a set of classes for representing database tables and rows as PHP objects.

You can perform a variety of tasks with [SQLite] databases in PHP, such as connecting to a database, executing SQL queries, and working with database transactions. You can also use it to create and manipulate database tables and rows, and to perform advanced database operations such as joins and aggregates.

Overall, **Yii Database SQLite Extension** is a powerful tool for working with [SQLite] databases in PHP, and is well-suited for use in web applications.

It is used in [Yii Framework] but can be used separately.
It's used in [Yii Framework] but can be used separately.

[SQLite]: https://www.sqlite.org/
[Yii Framework]: https://www.yiiframework.com
Expand All @@ -28,91 +28,27 @@ It is used in [Yii Framework] but can be used separately.
[![codecov](https://codecov.io/gh/yiisoft/db-sqlite/branch/master/graph/badge.svg?token=YXUHCPPITH)](https://codecov.io/gh/yiisoft/db-sqlite)
[![StyleCI](https://github.styleci.io/repos/145220194/shield?branch=master)](https://github.styleci.io/repos/145220194?branch=master)

### Support version
## Support version

| PHP | Sqlite Version | CI-Actions
|:----:|:------------------------:|:---:|
|**8.0 - 8.2**| **3:latest**|[![build](https://github.com/yiisoft/db-sqlite/actions/workflows/build.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db-sqlite/actions/workflows/build.yml) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdb-sqlite%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-sqlite/master) [![static analysis](https://github.com/yiisoft/db-sqlite/actions/workflows/static.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db-sqlite/actions/workflows/static.yml) [![type-coverage](https://shepherd.dev/github/yiisoft/db-sqlite/coverage.svg)](https://shepherd.dev/github/yiisoft/db-sqlite)

### Installation
## Installation

The package could be installed via composer:

```php
composer require yiisoft/db-sqlite
```

### Config with [Yii Framework]
## Usage

The configuration with [container di](https://github.com/yiisoft/di) of [Yii Framework].
For config connection to SQLite database check [Connecting SQLite](https://github.com/yiisoft/db/blob/master/docs/en/connection/sqlite.md).

Also you can use any DI container which implements [PSR-11](https://www.php-fig.org/psr/psr-11/).
[Check the documentation docs](https://github.com/yiisoft/db/blob/master/docs/en/getting-started.md) to learn about usage.

db.php

```php
<?php

declare(strict_types=1);

use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Sqlite\ConnectionPDO;
use Yiisoft\Db\Sqlite\PDODriver;

/** @var array $params */

return [
ConnectionInterface::class => [
'class' => ConnectionPDO::class,
'__construct()' => [
'driver' => new PDODriver($params['yiisoft/db-sqlite']['dsn']),
]
]
];
```

params.php

```php
<?php

declare(strict_types=1);

use Yiisoft\Db\Sqlite\Dsn;

return [
'yiisoft/db-sqlite' => [
'dsn' => (new Dsn('sqlite', 'memory'))->asString(),
]
];
```

### Config without [Yii Framework]

```php
<?php

declare(strict_types=1);

use Yiisoft\Cache\ArrayCache;
use Yiisoft\Cache\Cache;
use Yiisoft\Db\Cache\SchemaCache;
use Yiisoft\Db\Sqlite\ConnectionPDO;
use Yiisoft\Db\Sqlite\Dsn;
use Yiisoft\Db\Sqlite\PDODriver;

// Or any other PSR-16 cache implementation.
$arrayCache = new ArrayCache();

// Or any other PSR-6 cache implementation.
$cache = new Cache($arrayCache);
$dsn = (new Dsn('sqlite', 'memory'))->asString();

// Or any other PDO driver.
$pdoDriver = new PDODriver($dsn);
$schemaCache = new SchemaCache($cache);
$db = new ConnectionPDO($pdoDriver, $schemaCache);
```
## Testing

### Unit testing

Expand Down Expand Up @@ -157,19 +93,19 @@ To run the checker, execute the following command:
./vendor/bin/composer-require-checker
```

### Support the project
## Support the project

[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective&logoColor=7eadf1&labelColor=555555)](https://opencollective.com/yiisoft)

### Follow updates
## Follow updates

[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)
[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter&logoColor=1DA1F2&labelColor=555555?style=flat)](https://twitter.com/yiiframework)
[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat&logo=telegram)](https://t.me/yii3en)
[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat&logo=facebook&logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)
[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat&logo=slack)](https://yiiframework.com/go/slack)

### License
## License

The Yii DataBase SQLite Extension is free software. It is released under the terms of the BSD License.
Please see [`LICENSE`](./LICENSE.md) for more information.
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/InConditionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use function str_contains;

/**
* Builds conditions for {@see `\Yiisoft\Db\QueryBuilder\Condition\InCondition`} IN operator for SQLite Server.
* Build an object of {@see `\Yiisoft\Db\QueryBuilder\Condition\InCondition`} into SQL expressions for SQLite Server.
*/
final class InConditionBuilder extends \Yiisoft\Db\QueryBuilder\Condition\Builder\InConditionBuilder
{
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/LikeConditionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;

/**
* Builds conditions for {@see `\Yiisoft\Db\QueryBuilder\Condition\LikeCondition`} LIKE operator for SQLite Server.
* Build an object of {@see `\Yiisoft\Db\QueryBuilder\Condition\LikeCondition`} into SQL expressions for SQLite Server.
*/
final class LikeConditionBuilder extends \Yiisoft\Db\QueryBuilder\Condition\Builder\LikeConditionBuilder
{
Expand Down
5 changes: 3 additions & 2 deletions src/ColumnSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
use Yiisoft\Db\Schema\AbstractColumnSchema;

/**
* Represents the metadata of a column in a database table for SQLite Server. It provides information about the column's
* name, type, size, precision, and other details.
* Represents the metadata of a column in a database table for SQLite Server.
*
* It provides information about the column's name, type, size, precision, and other details.
*
* Is used to store and retrieve metadata about a column in a database table. It's typically used in conjunction with
* the {@see TableSchema}, which represents the metadata of a database table as a whole.
Expand Down
17 changes: 16 additions & 1 deletion src/ColumnSchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,27 @@

use Yiisoft\Db\Schema\AbstractColumnSchemaBuilder;

/**
* It's a utility that provides a convenient way to create column schema for use with {@see Schema} for SQLite Server.
*
* It provides methods for specifying the properties of a column, such as its type, size, default value, and whether it
* is nullable or not. It also provides a method for creating a column schema based on the specified properties.
*
* For example, the following code creates a column schema for an integer column:
*
* ```php
* $column = (new ColumnSchemaBuilder(SchemaInterface::TYPE_INTEGER))->notNull()->defaultValue(0);
* ```
*
* Provides a fluent interface, which means that the methods can be chained together to create a column schema with
* many properties in a single line of code.
*/
final class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
{
/**
* Builds the unsigned string for column. Defaults to unsupported.
*
* @return string a string containing UNSIGNED keyword.
* @return string A string containing UNSIGNED keyword.
*/
protected function buildUnsignedString(): string
{
Expand Down
28 changes: 18 additions & 10 deletions src/CommandPDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
use function preg_match_all;
use function strpos;

/**
* Implements a database command that can be executed against a PDO (PHP Data Object) database connection for SQLite
* Server.
*/
final class CommandPDO extends AbstractCommandPDO
{
public function insertWithReturningPks(string $table, array $columns): bool|array
Expand Down Expand Up @@ -56,12 +60,13 @@ public function queryBuilder(): QueryBuilderInterface
/**
* Executes the SQL statement.
*
* This method should only be used for executing non-query SQL statement, such as `INSERT`, `DELETE`, `UPDATE` SQLs.
* This method should only be used for executing a non-query SQL statement, such as `INSERT`, `DELETE`, `UPDATE` SQLs.
* No result set will be returned.
*
* @throws Exception|Throwable execution failed.
* @throws Exception
* @throws Throwable The execution failed.
*
* @return int number of rows affected by the execution.
* @return int Number of rows affected by the execution.
*/
public function execute(): int
{
Expand Down Expand Up @@ -128,13 +133,14 @@ protected function internalExecute(string|null $rawSql): void
}

/**
* Performs the actual DB query of a SQL statement.
* Performs the actual DB query of an SQL statement.
*
* @param int $queryMode - return results as DataReader
* @param int $queryMode Return results as DataReader
*
* @throws Exception|Throwable if the query causes any problem.
* @throws Exception
* @throws Throwable If the query causes any problem.
*
* @return mixed the method execution result.
* @return mixed The method execution result.
*/
protected function queryInternal(int $queryMode): mixed
{
Expand All @@ -156,8 +162,8 @@ protected function queryInternal(int $queryMode): mixed
*/
foreach ($statements as $statement) {
/**
* @var string $statementSql
* @var array $statementParams
* @psalm-var string $statementSql
* @psalm-var array $statementParams
*/
[$statementSql, $statementParams] = $statement;
$this->setSql($statementSql)->bindValues($statementParams);
Expand All @@ -178,9 +184,11 @@ protected function queryInternal(int $queryMode): mixed
* Splits the specified SQL codes into individual SQL statements and returns them or `false` if there's a single
* statement.
*
* @param string $sql SQL codes to be split.
*
* @throws InvalidArgumentException
*
* @return array|bool (array|string)[][]|bool
* @return array|bool List of SQL statements or `false` if there's a single statement.
*
* @psalm-param array<string, string> $params
* @psalm-return false|list<array{0: string, 1: array}>
Expand Down
11 changes: 4 additions & 7 deletions src/ConnectionPDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

namespace Yiisoft\Db\Sqlite;

use PDO;
use Yiisoft\Db\Driver\PDO\AbstractConnectionPDO;
use Yiisoft\Db\Driver\PDO\CommandPDOInterface;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Schema\Quoter;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;
use Yiisoft\Db\Transaction\TransactionInterface;
use function str_starts_with;

/**
* Database connection class prefilled for SQLite Server.
* Implements a connection to a database via PDO (PHP Data Objects) for SQLite Server.
*
* @link https://www.php.net/manual/en/ref.pdo-sqlite.php
*/
final class ConnectionPDO extends AbstractConnectionPDO
{
Expand Down Expand Up @@ -57,9 +57,6 @@ public function createTransaction(): TransactionInterface
return new TransactionPDO($this);
}

/**
* @throws Exception|InvalidConfigException
*/
public function getQueryBuilder(): QueryBuilderInterface
{
if ($this->queryBuilder === null) {
Expand Down
Loading