PHP code example of enepochatova / influxdb-orm

1. Go to this page and download the library: Download enepochatova/influxdb-orm library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

enepochatova / influxdb-orm example snippets




namespace SomeNamespace;

use InfluxDB\ORM\Mapping\Annotations as InfluxDB;

/**
 * Class Cpu
 * @InfluxDB\Measurement(name="cpu")
 */
class Cpu
{
}



namespace SomeNamespace;

use InfluxDB\ORM\Mapping\Annotations as InfluxDB;

/**
 * Class Cpu
 * @InfluxDB\Measurement(name="cpu")
 */
class Cpu
{
    /**
     * @var float
     * @InfluxDB\Value
     */
    private $value;

    /**
     * @var int
     * @InfluxDB\Field(key="tasks")
     */
    private $tasks;

    /**
     * @var int
     * @InfluxDB\Field(key="services")
     */
    private $activeServices;

    /**
     * @var string
     * @InfluxDB\Field(key="host")
     */
    private $host;

    /**
     * @var int
     * @InfluxDB\Tag(key="category", type="int")
     */
    private $categoryId;
    
    /**
     * @var array
     * @InfluxDB\ArrayOfMetrix()
     */
    private $config;

    /**
     * Cpu constructor.
     * @param float $value
     * @param int $tasks
     * @param int $activeServices
     * @param string $host
     * @param int $categoryId
     */
    public function __construct($value, $tasks, $activeServices, $host, $categoryId, $config)
    {
        $this->value = $value;
        $this->tasks = $tasks;
        $this->activeServices = $activeServices;
        $this->host = $host;
        $this->categoryId = $categoryId;
        $this->config = $config;
    }
    
   // getters here

}




namespace SomeNamespace;


use InfluxDB\Database;
use InfluxDB\ORM\Mapping\AnnotationDriver;
use InfluxDB\ORM\Repository\BaseRepository;

class CpuRepository extends BaseRepository
{
    /**
     * CpuRepository constructor.
     * @param AnnotationDriver $annotationDriver
     * @param Database $database
     * @param string|null $precision
     * @throws \ReflectionException
     */
    public function __construct(AnnotationDriver $annotationDriver, Database $database, string $precision = null)
    {
        parent::__construct($annotationDriver, $database, Cpu::class, $precision);
    }
}



...

$cpuRepositoryInstance->write($cpuInstance);

$cpuMetrics = $cpuRepositoryInstance->findAll();
...