All Projects → Tigrov → yii2-pgsql

Tigrov / yii2-pgsql

Licence: MIT license
Improved PostgreSQL schemas for Yii2

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to yii2-pgsql

yii2-stat
Yii2 Multi Web Statistic Module (yametrika, google-analytic, own db-counter)
Stars: ✭ 18 (-47.06%)
Mutual labels:  yii2, yii2-extension
Yii2 Translate Manager
Translation Manager
Stars: ✭ 221 (+550%)
Mutual labels:  yii2, yii2-extension
Yii2 Enhanced Gii
Enhanced Yii2 Gii (generator) that generates related Models & CRUD
Stars: ✭ 183 (+438.24%)
Mutual labels:  yii2, yii2-extension
Balance
Balance accounting (bookkeeping) system based on debit and credit principle
Stars: ✭ 162 (+376.47%)
Mutual labels:  yii2, yii2-extension
yii2-mailqueue
Yii2 mail queue component for yii2-swiftmailer.
Stars: ✭ 15 (-55.88%)
Mutual labels:  yii2, yii2-extension
Crontab
Yii2 extension for crontab support
Stars: ✭ 170 (+400%)
Mutual labels:  yii2, yii2-extension
yii2-newsletter
Module for saving user contacts from newsletter form to database
Stars: ✭ 17 (-50%)
Mutual labels:  yii2, yii2-extension
Yii2 Wx
这可能是yii2中最好用的微信SDK🔥🔥🔥
Stars: ✭ 148 (+335.29%)
Mutual labels:  yii2, yii2-extension
content
Content management system for Yii2
Stars: ✭ 54 (+58.82%)
Mutual labels:  yii2, yii2-extension
yii2-lets-talk
With this extension you can open chat with someone in popular messengers using the link on your website.
Stars: ✭ 15 (-55.88%)
Mutual labels:  yii2, yii2-extension
Yii2 Workflow
A simple workflow engine for Yii2
Stars: ✭ 157 (+361.76%)
Mutual labels:  yii2, yii2-extension
behavior-trait
Allows handling events via inline declared methods, which can be added by traits
Stars: ✭ 18 (-47.06%)
Mutual labels:  yii2, yii2-extension
Yii2 Comments
Comments module for Yii2
Stars: ✭ 155 (+355.88%)
Mutual labels:  yii2, yii2-extension
ar-search
Provides unified search model for Yii ActiveRecord
Stars: ✭ 31 (-8.82%)
Mutual labels:  yii2, yii2-extension
Yii2 Assets Auto Compress
Automatic compilation of js + css + html
Stars: ✭ 147 (+332.35%)
Mutual labels:  yii2, yii2-extension
Ar Softdelete
Soft delete behavior for ActiveRecord
Stars: ✭ 188 (+452.94%)
Mutual labels:  yii2, yii2-extension
Yii2fullcalendar
JQuery Fullcalendar Yii2 Extension
Stars: ✭ 120 (+252.94%)
Mutual labels:  yii2, yii2-extension
Yii2 Rbac
RBAC Manager for Yii 2
Stars: ✭ 128 (+276.47%)
Mutual labels:  yii2, yii2-extension
install
basic script for project installation
Stars: ✭ 17 (-50%)
Mutual labels:  yii2, yii2-extension
yii2-translatable
Translatable behavior aggregates logic of linking translations to the primary model
Stars: ✭ 15 (-55.88%)
Mutual labels:  yii2, yii2-extension

yii2-pgsql

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

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].