All Projects β†’ yiisoft β†’ Active Record

yiisoft / Active Record

Licence: bsd-3-clause
Active Record database abstraction layer

Projects that are alternatives of or similar to Active Record

Rein
Database constraints made easy for ActiveRecord.
Stars: ✭ 657 (+1427.91%)
Mutual labels:  activerecord, database
Tech Refrigerator
🍰 기술 냉μž₯κ³ μž…λ‹ˆλ‹€. πŸ›’ 기술 λ©΄μ ‘ , 전곡 μ‹œν—˜ , 지식 함양 λ“± λΆ„λͺ… 도움될 κ±°μ˜ˆμš”! 🀟
Stars: ✭ 699 (+1525.58%)
Mutual labels:  hacktoberfest, database
Faker
Faker is a pure Elixir library for generating fake data.
Stars: ✭ 673 (+1465.12%)
Mutual labels:  hacktoberfest, database
Zero downtime migrations
Zero downtime migrations with ActiveRecord 3+ and PostgreSQL
Stars: ✭ 513 (+1093.02%)
Mutual labels:  activerecord, database
Db Mysql
Stars: ✭ 22 (-48.84%)
Mutual labels:  hacktoberfest, database
Memento
Simple + Powerful interface to the Mnesia Distributed Database πŸ’Ύ
Stars: ✭ 597 (+1288.37%)
Mutual labels:  hacktoberfest, database
Polo
Polo travels through your database and creates sample snapshots so you can work with real world data in development.
Stars: ✭ 695 (+1516.28%)
Mutual labels:  activerecord, database
Isolator
Detect non-atomic interactions within DB transactions
Stars: ✭ 362 (+741.86%)
Mutual labels:  hacktoberfest, activerecord
Ftl
The Pi-hole FTL engine
Stars: ✭ 776 (+1704.65%)
Mutual labels:  hacktoberfest, database
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 7,712 (+17834.88%)
Mutual labels:  hacktoberfest, database
Cockroach
CockroachDB - the open source, cloud-native distributed SQL database.
Stars: ✭ 22,700 (+52690.7%)
Mutual labels:  hacktoberfest, database
Activerecord Sqlserver Adapter
SQL Server Adapter For Rails
Stars: ✭ 910 (+2016.28%)
Mutual labels:  activerecord, database
Database consistency
The tool to find inconsistency between models schema and database constraints.
Stars: ✭ 418 (+872.09%)
Mutual labels:  activerecord, database
Laravel Translatable
A Laravel package for multilingual models
Stars: ✭ 624 (+1351.16%)
Mutual labels:  hacktoberfest, database
Mongo Seeding
The ultimate solution for populating your MongoDB database.
Stars: ✭ 375 (+772.09%)
Mutual labels:  hacktoberfest, database
Tidb
TiDB is an open source distributed HTAP database compatible with the MySQL protocol
Stars: ✭ 29,871 (+69367.44%)
Mutual labels:  hacktoberfest, database
5e Database
Database for the D&D 5th Edition API
Stars: ✭ 354 (+723.26%)
Mutual labels:  hacktoberfest, database
Lbadd
LBADD: An experimental, distributed SQL database
Stars: ✭ 362 (+741.86%)
Mutual labels:  hacktoberfest, database
Phpauth
PHPAuth is a secure PHP Authentication class that easily integrates into any site.
Stars: ✭ 748 (+1639.53%)
Mutual labels:  hacktoberfest, database
Active record doctor
Identify database issues before they hit production.
Stars: ✭ 865 (+1911.63%)
Mutual labels:  activerecord, database

Yii ActiveRecord Library


This package provides ActiveRecord library. It is used in Yii Framework but is supposed to be usable separately.

Latest Stable Version Total Downloads Build status Code Coverage Mutation testing badge type-coverage

Support databases:

Packages PHP Versions CI-Actions
[db-mssql] 7.4 - 8.0 2017 - 2019 Build status Mutation testing badge Code Coverage
[db-mysql] 7.4 - 8.0 5.7 - 8.0 Build status Mutation testing badge Code Coverage
[db-oracle] 7.4 - 8.0 11c - 12c Build status Mutation testing badge Code Coverage
[db-pgsql] 7.4 - 8.0 9.0 - 13.0 Build status Mutation testing badge Code Coverage
[db-sqlite] 7.4 - 8.0 3:latest Build status Mutation testing badge Code Coverage
[db-redis] 7.4 - 8.0 4.0 - 6.0 Build status Mutation testing badge Code Coverage

Installation

The package could be installed via composer:

composer require yiisoft/active-record

Note: You must install the repository of the implementation to use.

Example:

composer require yiisoft/db-mysql

Configuration container di autowired

web.php:

<?php

declare(strict_types=1);

use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Sqlite\Connection as SqliteConnection;

/**
 * config ConnectionInterface::class
 */
return [
    ConnectionInterface::class => [
        '__class' => SqliteConnection::class,
        '__construct()' => [
            'dsn' => $params['yiisoft/db-sqlite']['dsn'],
        ]
    ]
];

params.php

<?php

declare(strict_types=1);

return [
    'yiisoft/db-sqlite' => [
        'dsn' => 'sqlite:' . dirname(__DIR__) . '/runtime/yiitest.sq3',
    ]
]

defined your active record, example User.php:

<?php

declare(strict_types=1);

namespace App\Entity;

use Yiisoft\ActiveRecord\ActiveRecord;

/**
 * Entity User.
 *
 * Database fields:
 * @property int $id
 * @property string $username
 * @property string $email
 **/
final class User extends ActiveRecord
{
    public function tableName(): string
    {
        return '{{%user}}';
    }
}

in controler or action:

<?php

declare(strict_types=1);

namespace App\Action;

use App\Entity\User;
use Psr\Http\Message\ResponseInterface;

final class Register
{
    public function register(
        User $user
    ): ResponseInterface {
        /** Connected AR by di autowired. */
        $user->setAttribute('username', 'yiiliveext');
        $user->setAttribute('email', '[email protected]');
        $user->save();
    }
}

Configuration factory di

web.php:

<?php

declare(strict_types=1);

use Yiisoft\ActiveRecord\ActiveRecordFactory;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Sqlite\Connection as SqliteConnection;
use Yiisoft\Factory\Definitions\Reference;

/**
 * config SqliteConnection::class
 */
return [
    SqliteConnection::class => [
        '__class' => SqliteConnection::class,
        '__construct()' => [
            'dsn' => $params['yiisoft/db-sqlite']['dsn'],
        ]
    ],

    ActiveRecordFactory::class => [
        '__class' => ActiveRecordFactory::class,
        '__construct()' => [
            null,
            [ConnectionInterface::class => Reference::to(SqliteConnection::class)],
        ]
    ]
];

params.php

<?php

declare(strict_types=1);

return [
    'yiisoft/db-sqlite' => [
        'dsn' => 'sqlite:' . dirname(__DIR__) . '/runtime/yiitest.sq3',
    ]
]

defined your active record, example User.php:

<?php

declare(strict_types=1);

namespace App\Entity;

use Yiisoft\ActiveRecord\ActiveRecord;

/**
 * Entity User.
 *
 * Database fields:
 * @property int $id
 * @property string $username
 * @property string $email
 **/
final class User extends ActiveRecord
{
    public function tableName(): string
    {
        return '{{%user}}';
    }
}

in controler or action:

<?php

declare(strict_types=1);

namespace App\Action;

use App\Entity\User;
use Psr\Http\Message\ResponseInterface;
use Yiisoft\ActiveRecord\ActiveRecordFactory;

final class Register
{
    public function register(
        ActiveRecordFactory $arFactory
    ): ResponseInterface {
        /** Connected AR by factory di. */
        $user = $arFactory->createAR(User::class);

        $user->setAttribute('username', 'yiiliveext');
        $user->setAttribute('email', '[email protected]');
        $user->save();
    }
}

Unit testing

The package is tested with PHPUnit. To run tests:

./vendor/bin/phpunit

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

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

License

The Yii ActiveRecord Library is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].