2017 © Pedro Peláez
 

yii2-extension yii2-pgsql-schema

PostgreSQL schemas for Yii2, with fields jsonb, json

image

i-excellent/yii2-pgsql-schema

PostgreSQL schemas for Yii2, with fields jsonb, json

  • Sunday, December 17, 2017
  • by i-excellent
  • Repository
  • 1 Watchers
  • 1 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 11 % Grown

The README.md

yii2-pgsql

Improved PostgreSQL schemas for Yii2., (*1)

Supports follow types for ActiveRecord models:, (*2)

Latest Stable Version License, (*3)

Limitation

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

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

See the issue #7481, (*6)

Installation

The preferred way to install this extension is through composer., (*7)

Either run, (*8)

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

or add, (*9)

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

to the require section of your composer.json file., (*10)

Configuration

Once the extension is installed, add following code to your application configuration:, (*11)

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, (*12)

/**
 * @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:, (*13)

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

and then use them in your code, (*14)

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

Composite types, (*15)

License

MIT, (*16)

The Versions

17/12 2017

dev-master

9999999-dev

PostgreSQL schemas for Yii2, with fields jsonb, json

  Sources   Download

MIT

The Requires

 

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

17/12 2017

1.0.2

1.0.2.0

PostgreSQL schemas for Yii2, with fields jsonb, json

  Sources   Download

MIT

The Requires

 

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

17/12 2017

v1.0.1

1.0.1.0

PostgreSQL schemas for Yii2, with fields jsonb, json

  Sources   Download

MIT

The Requires

 

extension json postgresql postgres yii2 array datetime timestamp bit pgsql