-
-
Notifications
You must be signed in to change notification settings - Fork 34
Improve README #503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Improve README #503
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,32 +2,29 @@ | |
| <a href="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/yiisoft" target="_blank"> | ||
| <img src="https://yiisoft.github.io/docs/images/yii_logo.svg" height="100px" alt="Yii"> | ||
| </a> | ||
| <h1 align="center">Yii ActiveRecord</h1> | ||
| <h1 align="center">Yii Active Record</h1> | ||
| <br> | ||
| </p> | ||
|
|
||
| [](https://packagist.org/packages/yiisoft/active-record) | ||
| [](https://packagist.org/packages/yiisoft/active-record) | ||
| [](https://codecov.io/gh/yiisoft/active-record) | ||
| [](https://codecov.io/gh/yiisoft/active-record) | ||
| [](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/active-record/master) | ||
| [](https://github.com/yiisoft/active-record/actions/workflows/static.yml?query=branch%3Amaster) | ||
| [](https://shepherd.dev/github/yiisoft/active-record) | ||
| [](https://shepherd.dev/github/yiisoft/active-record) | ||
|
|
||
| This package provides [ActiveRecord] library. | ||
| It is used in [Yii Framework] but is supposed to be usable separately. | ||
| This package provides [Active Record pattern](https://en.wikipedia.org/wiki/Active_record_pattern) implementation. | ||
|
|
||
| [ActiveRecord]: https://en.wikipedia.org/wiki/Active_record_pattern | ||
| [Yii Framework]: https://www.yiiframework.com/ | ||
| Supported databases: | ||
|
|
||
| ## Support databases | ||
|
|
||
| | Packages | Versions | CI-Actions | | ||
| |-----------------------------------------------------|-----------------|------------| | ||
| | [[db-mssql]](https://github.com/yiisoft/db-mssql) | **2017 - 2022** |[](https://github.com/yiisoft/db-mssql/actions?query=workflow%3Abuild) [](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-mssql/master) [](https://codecov.io/gh/yiisoft/db-mssql)| | ||
| | [[db-mysql]](https://github.com/yiisoft/db-mysql) | **5.7 - 8.0** |[](https://github.com/yiisoft/db-mysql/actions?query=workflow%3Abuild) [](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-mysql/master) [](https://codecov.io/gh/yiisoft/db-mysql)| | ||
| | [[db-oracle]](https://github.com/yiisoft/db-oracle) | **12 - 21** |[](https://github.com/yiisoft/db-oracle/actions?query=workflow%3Abuild) [](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-oracle/master) [](https://codecov.io/gh/yiisoft/db-oracle)| | ||
| | [[db-pgsql]](https://github.com/yiisoft/db-pgsql) | **9.0 - 16.0** |[](https://github.com/yiisoft/db-pgsql/actions?query=workflow%3Abuild) [](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-pgsql/master) [](https://codecov.io/gh/yiisoft/db-pgsql)| | ||
| | [[db-sqlite]](https://github.com/yiisoft/db-sqlite) | **3:latest** |[](https://github.com/yiisoft/db-sqlite/actions?query=workflow%3Abuild) [](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-sqlite/master) [](https://codecov.io/gh/yiisoft/db-sqlite)| | ||
| | Packages | Build status | | ||
| |------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| | [Microsft SQL Server](https://github.com/yiisoft/db-mssql) | [](https://github.com/yiisoft/active-record/actions/workflows/db-mssql.yml?query=branch%3Amaster) | | ||
| | [MySQL](https://github.com/yiisoft/db-mysql) | [](https://github.com/yiisoft/active-record/actions/workflows/db-mysql.yml?query=branch%3Amaster) | | ||
| | [Oracle](https://github.com/yiisoft/db-oracle) | [](https://github.com/yiisoft/active-record/actions/workflows/db-oracle.yml?query=branch%3Amaster) | | ||
| | [PostgreSQL](https://github.com/yiisoft/db-pgsql) | [](https://github.com/yiisoft/active-record/actions/workflows/db-pgsql.yml?query=branch%3Amaster) | | ||
| | [SQLite](https://github.com/yiisoft/db-sqlite) | [](https://github.com/yiisoft/active-record/actions/workflows/db-sqlite.yml?query=branch%3Amaster) | | ||
|
|
||
| ## Requirements | ||
|
|
||
|
|
@@ -41,96 +38,21 @@ The package could be installed with [Composer](https://getcomposer.org): | |
| composer require yiisoft/active-record | ||
| ``` | ||
|
|
||
| **Note: You must install the repository of the implementation to use.** | ||
|
|
||
| Example: | ||
|
|
||
| ```shell | ||
| composer require yiisoft/db-sqlite | ||
| ``` | ||
|
|
||
| ## Configure container with database connection | ||
|
|
||
| Add the following code to the configuration files, for example: | ||
|
|
||
| `config/common/di/db.php`: | ||
|
|
||
| ```php | ||
| use Yiisoft\Db\Connection\ConnectionInterface; | ||
| use Yiisoft\Db\Sqlite\Connection; | ||
| use Yiisoft\Db\Sqlite\Driver; | ||
|
|
||
| return [ | ||
| ConnectionInterface::class => [ | ||
| 'class' => Connection::class, | ||
| '__construct()' => [ | ||
| 'driver' => new Driver($params['yiisoft/db-sqlite']['dsn']), | ||
| ], | ||
| ] | ||
| ]; | ||
| ``` | ||
| > [!IMPORTANT] | ||
| > See also [installation notes](https://github.com/yiisoft/db/?tab=readme-ov-file#documentation) for `yiisoft/db` | ||
| > package. | ||
|
|
||
| `config/common/params.php`: | ||
| After installing `yiisoft/active-record`, you also need to configure a database connection: | ||
|
|
||
| ```php | ||
| return [ | ||
| 'yiisoft/db-sqlite' => [ | ||
| 'dsn' => 'sqlite:' . dirname(__DIR__) . '/runtime/yiitest.sq3', | ||
| ] | ||
| ] | ||
| ``` | ||
| 1. Configure the connection, follow [Yii Database](https://github.com/yiisoft/db/blob/master/docs/guide/en/README.md) | ||
| guide. | ||
| 2. [Define the Database Connection for Active Record](docs/define-connection.md) | ||
|
|
||
| For more information about how to configure the connection, follow [Yii Database](https://github.com/yiisoft/db/blob/master/docs/guide/en/README.md). | ||
| ## General usage | ||
|
|
||
| `config/common/bootstrap.php`: | ||
| Defined your active record class (for more information, follow [Create Active Record Model](docs/create-model.md) guide): | ||
|
|
||
| ```php | ||
| use Psr\Container\ContainerInterface; | ||
| use Yiisoft\Db\Connection\ConnectionProvider; | ||
| use Yiisoft\Db\Connection\ConnectionInterface; | ||
|
|
||
| return [ | ||
| static function (ContainerInterface $container): void { | ||
| ConnectionProvider::set($container->get(ConnectionInterface::class)); | ||
| } | ||
| ]; | ||
| ``` | ||
|
|
||
| Be sure to include `bootstrap.php` file using `config-plugin` in `extra` section of `composer.json` (see [yiisoft/config](https://github.com/yiisoft/config)): | ||
|
|
||
| ``` | ||
| "extra": { | ||
| "config-plugin": { | ||
| "bootstrap": "common/bootstrap.php" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Or if you use `config-plugin-file` in `extra` section of `composer.json` as follows: | ||
|
|
||
| ``` | ||
| "extra": { | ||
| "config-plugin-file": "configuration.php" | ||
| } | ||
| ``` | ||
|
|
||
| add the line `'bootstrap' => 'common/bootstrap.php',` to `configuration.php` file: | ||
|
|
||
| ```php | ||
| return [ | ||
| 'config-plugin' => [ | ||
| 'bootstrap' => 'common/bootstrap.php', | ||
| ], | ||
| ]; | ||
| ``` | ||
|
|
||
| See other ways to [define the DB connection](docs/define-connection.md) for Active Record. | ||
|
|
||
| ## Defined your active record class | ||
|
|
||
| ```php | ||
| use Yiisoft\ActiveRecord\ActiveRecord; | ||
|
|
||
| /** | ||
| * Entity User. | ||
| * | ||
|
|
@@ -140,7 +62,7 @@ use Yiisoft\ActiveRecord\ActiveRecord; | |
| * @property string $email | ||
| **/ | ||
| #[\AllowDynamicProperties] | ||
| final class User extends ActiveRecord | ||
| final class User extends \Yiisoft\ActiveRecord\ActiveRecord | ||
| { | ||
| public function tableName(): string | ||
| { | ||
|
|
@@ -149,49 +71,39 @@ final class User extends ActiveRecord | |
| } | ||
| ``` | ||
|
|
||
| For more information, follow [Create Active Record Model](docs/create-model.md). | ||
|
|
||
| ## Usage | ||
|
|
||
| Now you can use the Active Record: | ||
| Now you can use the active record: | ||
|
|
||
| ```php | ||
| use App\Entity\User; | ||
|
|
||
| // Creating a new record | ||
| $user = new User(); | ||
| $user->set('username', 'yiiliveext'); | ||
| $user->set('email', '[email protected]'); | ||
| $user->set('username', 'alexander-pushkin'); | ||
| $user->set('email', '[email protected]'); | ||
| $user->save(); | ||
| ``` | ||
|
|
||
| Using with `ActiveRecord::query()`: | ||
|
|
||
| ```php | ||
| use App\Entity\User; | ||
| use Yiisoft\ActiveRecord\ActiveQuery; | ||
|
|
||
| $user = User::query()->where(['id' => 1])->one(); | ||
| // Retrieving a record | ||
| $user = User::query()->findByPk(1); | ||
|
|
||
| // Read properties | ||
| $username = $user->get('username'); | ||
| $email = $user->get('email'); | ||
| ``` | ||
|
|
||
| ## Documentation | ||
|
|
||
| - [Define the Database Connection for Active Record](docs/define-connection.md); | ||
| - [Create Active Record Model](docs/create-model.md); | ||
| - [Define Active Record Relations](docs/define-relations.md); | ||
| - [Extending Functionality With Traits](docs/traits/traits.md); | ||
| - [Using Dependency Injection With Active Record Model](docs/using-di.md); | ||
| - [Optimistic Locking](docs/optimistic-locking.md); | ||
| - [Internals](docs/internals.md). | ||
| - [Define the Database Connection for Active Record](docs/define-connection.md) | ||
| - [Create Active Record Model](docs/create-model.md) | ||
| - [Define Active Record Relations](docs/define-relations.md) | ||
| - [Extending Functionality With Traits](docs/traits/traits.md) | ||
| - [Using Dependency Injection With Active Record Model](docs/using-di.md) | ||
| - [Optimistic Locking](docs/optimistic-locking.md) | ||
| - [Internals](docs/internals.md) | ||
|
|
||
| If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that. | ||
| You may also check out other [Yii Community Resources](https://www.yiiframework.com/community). | ||
| If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place | ||
| for that. You may also check out other [Yii Community Resources](https://www.yiiframework.com/community). | ||
|
|
||
| ## License | ||
|
|
||
| The Yii Active Record Library is free software. It is released under the terms of the BSD License. | ||
| The Yii Active Record is free software. It is released under the terms of the BSD License. | ||
| Please see [`LICENSE`](./LICENSE.md) for more information. | ||
|
|
||
| Maintained by [Yii Software](https://www.yiiframework.com/). | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.