PHP code example of javer / influxdb-odm-bundle

1. Go to this page and download the library: Download javer/influxdb-odm-bundle 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/ */

    

javer / influxdb-odm-bundle example snippets


// config/bundles.php

return [
    // ...
    Javer\InfluxDB\Bundle\JaverInfluxDBBundle::class => ['all' => true],
];

use App\Measurement\CpuLoad;
use Javer\InfluxDB\ODM\MeasurementManager;

public function demoAction(MeasurementManager $measurementManager)
{
    $now = new DateTime();

    // Create
    $cpuLoad = new CpuLoad();
    $cpuLoad->setTime($now);
    $cpuLoad->setServerId(42);
    $cpuLoad->setCoreNumber(0);
    $cpuLoad->setLoad(3.14);
    $measurementManager->persist($cpuLoad);

    // Fetch
    $cpuLoad = $measurementManager->getRepository(CpuLoad::class)->find($now);

    // Update
    $cpuLoad->setLoad(2.54);
    $measurementManager->persist($cpuLoad);

    // Remove
    $measurementManager->remove($cpuLoad);
}

// src/Repository/CpuLoadRepository.php
namespace App\Repository;

use App\Measurement\CpuLoad;
use Javer\InfluxDB\Bundle\Repository\ServiceMeasurementRepository;
use Javer\InfluxDB\ODM\MeasurementManager;

/**
 * Remember to map this repository in the corresponding measurement repositoryClass.
 */
class CpuLoadRepository extends ServiceMeasurementRepository
{
    public function __construct(MeasurementManager $measurementManager)
    {
        parent::__construct($measurementManager, CpuLoad::class);
    }
}