Giter VIP home page Giter VIP logo

yii2-scalable-behavior's Introduction

Scalable Database Schema

Key-Value storage is a very simplistic, but very powerful model. Use this behavior to expand your Yii 2 model without changing the structure.

Data can be queried and saved with "virtual attributes". These are stored serialized in a configured table column.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist cakebake/yii2-scalable-behavior "*"

or add

"cakebake/yii2-scalable-behavior": "*"

to the require section of your composer.json file.

Preparation

Create a column in your desired table. It is recommended to use the type "text" or "longtext" in order to save as much data as possible.

Usage

Once the extension is installed, simply use it in your model by adding:

    use cakebake\behaviors\ScalableBehavior;

    public function behaviors()
    {
        return [
            ...
            'scaleable' => [
                'class' => ScalableBehavior::className(),
                'scalableAttribute' => 'value', // The owner object's attribute / the column of the corresponding table, which are used as storage for the virtual attributes
                'virtualAttributes' => ['about_me', 'birthday'] // Definition of virtual attributes that are added to the owner object
            ],
            ...
        ];
    }

Now we can proceed similarly with the virtual attributes like normal.

    public function rules()
    {
        return [
            ['about_me', 'required'],
            ['about_me', 'string'],
            ['birthday', 'string', 'max' => 60],
        ];
    }

Piece of advice

This technique should be used only for metadata. Improper use may change the application performance negatively.

yii2-scalable-behavior's People

Contributors

cakebake avatar

Watchers

Nikolya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.