tigrov/yii2-pgsql
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:
array, Yii 2.0.14 and above supportsarrayDB typejson, Yii 2.0.14 and above supportsjsonDB typecomposite, https://www.postgresql.org/docs/current/static/rowtypes.htmldomain, https://www.postgresql.org/docs/current/static/sql-createdomain.html- fixes type
bit, issue #7682 - converts Postgres types
timestamp,dateandtimeto PHP type\DateTimeand vice versa.
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
License
tigrov/yii2-pgsql 适用场景与选型建议
tigrov/yii2-pgsql 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 70.85k 次下载、GitHub Stars 达 34, 最近一次更新时间为 2016 年 10 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「postgresql」 「array」 「extension」 「pgsql」 「postgres」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tigrov/yii2-pgsql 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tigrov/yii2-pgsql 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tigrov/yii2-pgsql 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
SilverStripe now has tentative support for PostgreSQL ('Postgres')
A set of useful PHP classes.
Dibi is Database Abstraction Library for PHP
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
统计信息
- 总下载量: 70.85k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 36
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-10-21