i-excellent/yii2-pgsql-schema 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

i-excellent/yii2-pgsql-schema

Composer 安装命令:

composer require i-excellent/yii2-pgsql-schema

包简介

PostgreSQL schemas for Yii2, with fields jsonb, json

README 文档

README

Improved PostgreSQL schemas for Yii2.

Supports follow types for ActiveRecord models:

Latest Stable Version License

Limitation

When you use this extension you can't specify the PDO type by using an array: [value, type],

e.g. ['name' => 'John', 'profile' => [$profile, \PDO::PARAM_LOB]].

See the issue #7481

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist i-excellent/yii2-pgsql-schema

or add

"i-excellent/yii2-pgsql-schema": "~1.0"

to the require section of your composer.json file.

Configuration

Once the extension is installed, add following code to your application configuration:

return [
    //...
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'pgsql:host=localhost;dbname=<database>',
            'username' => 'postgres',
            'password' => '<password>',
            'schemaMap' => [
                'pgsql'=> 'excellent\pgsql\Schema',
            ],
        ],
    ],
];

Configure Model's rules

/**
 * @property string[] $attribute1 array of string
 * @property array $attribute2 associative array or just array
 * @property integer|string|\DateTime $attribute3 for more information about the type see \Yii::$app->formatter->asDatetime()
 */
class Model extends ActiveRecord
{
    //...
    public function rules()
    {
        return [
            [['attribute1'], 'each', 'rule' => ['string']],
            [['attribute2'], 'safe'],
        ];
    }
}

Usage

You can then save array, json and timestamp types in database as follows:

/**
 * @var ActiveRecord $model
 */
$model->attribute1 = ['some', 'values', 'of', 'array'];
$model->attribute2 = ['some' => 'values', 'of' => 'array'];
$model->save();

and then use them in your code

/**
 * @var ActiveRecord $model
 */
$model = Model::findOne($pk);
$model->attribute1; // is array
$model->attribute2; // is associative array (decoded json)

Composite types

License

MIT

统计信息

  • 总下载量: 28
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-12-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固