定制 tigrov/yii2-pgsql 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

tigrov/yii2-pgsql

最新稳定版本:1.4.4

Composer 安装命令:

composer require tigrov/yii2-pgsql

包简介

Improved PostgreSQL schemas for Yii2

README 文档

README

Improved PostgreSQL schemas for Yii2.

Yii 2.0.14 and above supports array and json DB types.

Supports follow types for ActiveRecord models:

Latest Stable Version Build Status

Limitation

Since version 1.2.0 requires Yii 2.0.14 and above.
You can use version 1.1.11 if you have Yii 2.0.13 and below.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist tigrov/yii2-pgsql 

or add

"tigrov/yii2-pgsql": "~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'=> 'tigrov\pgsql\Schema', ], ], ], ];

Specify the desired types for a table

CREATE TABLE public.model ( id serial NOT NULL, attribute1 text[], attribute2 jsonb, attribute3 timestamp DEFAULT now(), CONSTRAINT model_pkey PRIMARY KEY (id) );

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', 'attribute3'], '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->attribute3 = new \DateTime('now'); $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) $model->attribute3; // is \DateTime

Composite types

License

MIT

统计信息

  • 总下载量: 64.19k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 36
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 34
  • Watchers: 5
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固