GithubHelp home page GithubHelp logo

yii2-clickhouse's Introduction

Yii2 ClickHouse extension

Installation

Composer

The preferred way to install this extension is through Composer.

Either run

php composer.phar require kak/clickhouse "dev-master"

or add

"kak/clickhouse": "dev-master"

to the require section of your composer.json

Configuration

   'components' => [
        'clickhouse' => [
            'class' => 'kak\clickhouse\Connection',
            'dsn' => '127.0.0.1',
            'port' => '8123',
            'username' => 'web',
            'password' => '123',
        ],
   // ...     

Usage

	   /** @var \kak\clickhouse\Connection $client */
		$client = \Yii::$app->clickhouse;
		
		$sql = 'select * from stat where counter_id=:counter_id';
		$client->createCommand($sql,[
			':counter_id' => 122
		])->queryAll();
	
			
		// insert data ORM
		$client->createCommand(null)
			->insert('stat', [
				'event_data' => date('Y-m-d'),
				'counter_id' => 122
			])
			->execute();
			

Save custom model

use yii\base\Model;
class Stat extends Model
{
    public $event_date; // Date;
    public $counter_id  = 0; // Int32,

	public function save($validate = true)
	{
		/** @var \kak\clickhouse\Connection $client */
		$client = \Yii::$app->clickhouse;
		$this->event_date = date('Y-m-d');

		if($validate && !$this->validate()){
			return false;
		}

		$attributes = $this->getAttributes();
		$client->createCommand(null)
			->insert('stat', $attributes )
			->execute();	
	}

}

ActiveRecord model

class Stat extends \kak\clickhouse\ActiveRecord 
{
	
    public static function tableName()
    {
        return 'stat';
    }
    
    // use relation in mysql
    
    public function getUser()
    {
    	return $this->hasOne(User::className(),['id' => 'user_id']);
    }

}


@TODO ActiveQuery, QueryBuilder, Gii, tab profile panel

yii2-clickhouse's People

Contributors

alexander-emelyanov avatar sanchezzzhak avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jaggman

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.