2017 © Pedro Peláez
 

yii2-extension yii2-pgsql

Improved PostgreSQL schemas for Yii2

image

tigrov/yii2-pgsql

Improved PostgreSQL schemas for Yii2

  • Friday, March 2, 2018
  • by Tigros
  • Repository
  • 5 Watchers
  • 21 Stars
  • 5,494 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 19 Versions
  • 22 % Grown

The README.md

yii2-pgsql

Improved PostgreSQL schemas for Yii2., (*1)

Yii 2.0.14 and above supports array and json DB types., (*2)

Supports follow types for ActiveRecord models: * array, Yii 2.0.14 and above supports array DB type * json, Yii 2.0.14 and above supports json DB type * composite, https://www.postgresql.org/docs/current/static/rowtypes.html * domain, https://www.postgresql.org/docs/current/static/sql-createdomain.html * fixes type bit, issue #7682 * converts Postgres types timestamp, date and time to PHP type \DateTime and vice versa., (*3)

Latest Stable Version Build Status, (*4)

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

Installation

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

Either run, (*7)

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

or add, (*8)

"tigrov/yii2-pgsql": "~1.0"

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

Configuration

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

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

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

Composite types, (*15)

License

MIT, (*16)

The Versions

02/03 2018

dev-master

9999999-dev

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

domain extension json postgresql postgres yii2 array datetime timestamp bit pgsql composite

02/03 2018

1.3.1

1.3.1.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

domain extension json postgresql postgres yii2 array datetime timestamp bit pgsql composite

27/02 2018

1.3.0

1.3.0.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

domain extension json postgresql postgres yii2 array datetime timestamp bit pgsql composite

19/02 2018

1.2.0

1.2.0.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

domain extension json postgresql postgres yii2 array datetime timestamp bit pgsql composite

02/02 2018

1.1.11

1.1.11.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

28/01 2018

1.1.10

1.1.10.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

27/01 2018

1.1.9

1.1.9.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

09/10 2017

1.1.8

1.1.8.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

22/09 2017

1.1.7

1.1.7.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

08/09 2017

1.1.6

1.1.6.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

07/09 2017

1.1.5

1.1.5.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

05/09 2017

1.1.4

1.1.4.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

09/08 2017

1.1.3

1.1.3.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

16/07 2017

1.1.2

1.1.2.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

22/06 2017

1.1.1

1.1.1.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

07/06 2017

1.1.0

1.1.0.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

27/05 2017

1.0.2

1.0.2.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

07/05 2017

1.0.1

1.0.1.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension json postgresql postgres yii2 array datetime timestamp bit pgsql

03/05 2017

1.0.0

1.0.0.0

Improved PostgreSQL schemas for Yii2

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension json postgresql postgres yii2 array datetime timestamp bit pgsql