close
The Wayback Machine - https://web.archive.org/web/20200911061837/https://github.com/yiisoft/db-sqlite
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Image Image

Yii DataBase SQLite Extension


This package provides SQLite extension for Yii DataBase library. It is used in Yii Framework but is supposed to be usable separately.

Latest Stable Version Total Downloads Scrutinizer Code Quality Code Coverage

Support version

PHP Sqlite Version CI-Actions
7.4 - 8.0 3:latest Build status Mutation testing badge static analysis type-coverage

Installation

The package could be installed via composer:

composer require yiisoft/db-sqlite

Configuration

Di-Container:

use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Yiisoft\Aliases\Aliases;
use Yiisoft\Cache\ArrayCache;
use Yiisoft\Cache\CacheInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Sqlite\Connection;
use Yiisoft\Log\Logger;
use Yiisoft\Log\Target\File\FileRotator;
use Yiisoft\Log\Target\File\FileRotatorInterface;
use Yiisoft\Log\Target\File\FileTarget;
use Yiisoft\Profiler\Profiler;

return [
    ContainerInterface::class => static function (ContainerInterface $container) {
        return $container;
    },

    Aliases::class => [
        '@root' => dirname(__DIR__, 1), // directory / packages.
        '@runtime' => '@root/runtime' 
    ],

    CacheInterface::class => static function () {
        return new Cache(new ArrayCache());
    },

    FileRotatorInterface::class => static function () {
        return new FileRotator(10);
    },

    LoggerInterface::class => static function (ContainerInterface $container) {
        $aliases = $container->get(Aliases::class);
        $fileRotator = $container->get(FileRotatorInterface::class);

        $fileTarget = new FileTarget(
            $aliases->get('@runtime/logs/app.log'),
            $fileRotator
        );

        $fileTarget->setLevels(
            [
                LogLevel::EMERGENCY,
                LogLevel::ERROR,
                LogLevel::WARNING,
                LogLevel::INFO,
                LogLevel::DEBUG
            ]
        );

        return new Logger(['file' => $fileTarget]);
    },

    Profiler::class => static function (ContainerInterface $container) {
        return new Profiler($container->get(LoggerInterface::class));
    },

    ConnectionInterface::class  => static function (ContainerInterface $container) use ($params) {
        $connection = new Connection(
            $container->get(CacheInterface::class),
            $container->get(LoggerInterface::class),
            $container->get(Profiler::class),
            $params['yiisoft/db-sqlite']['dsn'],
        );

        return $connection;
    }
];

Params.php

protected function params(): array
{
    return [
        'yiisoft/db-sqlite' => [
            'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3',
        ]
    ];
}

Unit testing

The package is tested with PHPUnit. To run tests:

./vendor/bin/phpunit

Note: You must have SQLITE installed to run the tests, it supports all SQLITE version 3.

Mutation testing

The package tests are checked with Infection mutation framework. To run it:

./vendor/bin/infection

Static analysis

The code is statically analyzed with Psalm. To run static analysis:

./vendor/bin/psalm

About

SQLite support for Yii

Topics

Resources

Releases

No releases published

Sponsor this project

  •  
Learn more about GitHub Sponsors

Packages

No packages published
You can’t perform that action at this time.