Download the PHP package javer/influxdb-odm without Composer
On this page you can find all versions of the php package javer/influxdb-odm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download javer/influxdb-odm
More information about javer/influxdb-odm
Files in javer/influxdb-odm
Package influxdb-odm
Short Description Provides a PHP object mapping functionality for InfluxDB
License MIT
Homepage https://github.com/javer/influxdb-odm
Informations about the package influxdb-odm
InfluxDB Object Document Mapper (ODM)
The InfluxDB ODM is a library that provides a PHP object mapping functionality for InfluxDB.
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Open a command console, enter your project directory and execute:
Usage
The best way to understand the InfluxDB ODM is to see it in action. In this section, you'll walk through each step needed to start persisting measurements to and from InfluxDB.
Create a Measurement Class with Mapping Information
Doctrine allows you to work with InfluxDB in a much more interesting way than just fetching data back and forth as an array. Instead, Doctrine allows you to persist entire objects to InfluxDB and fetch entire objects out of InfluxDB. This works by mapping a PHP class and its properties to entries of a InfluxDB Measurement.
For Doctrine to be able to do this, you have to create "metadata", or
configuration that tells Doctrine exactly how the CpuLoad
class and its
properties should be mapped to InfluxDB. This metadata can be specified
directly inside the CpuLoad
class via annotations:
or using PHP 8 Attributes:
Create Measurement Manager
If you are not using JaverInfluxDBBundle
, you have to create an instance of MeasurementManager:
To be able to use annotations, you will have to install an extra package called doctrine/annotations
.
Using PHP 8 Attributes:
Persisting Objects to InfluxDB
Now that you have a mapped CpuLoad
measurement complete with getter and
setter methods, you're ready to persist data to InfluxDB:
Fetching Objects from InfluxDB
Fetching an object back out of InfluxDB is also possible:
When you query for a particular type of object, you always use what's known as its "repository". You can think of a repository as a PHP class whose only job is to help you fetch objects of a certain class. You can access the repository object for a measurement class via:
Once you have your repository, you have access to all sorts of helpful methods:
You can also take advantage of the useful findBy()
and findOneBy()
methods
to easily fetch objects based on multiple conditions:
Updating an Object
Once you've fetched an object from Doctrine, let's try to update it.
Please note that you cannot update value of Timestamp or Tag field, only simple Field can be updated.
Deleting an Object
Deleting an object is very similar, but requires a call to the remove()
method of the measurement manager:
Querying for Objects
As you saw above, the built-in repository class allows you to query for one or many objects based on any number of different parameters. When this is enough, this is the easiest way to query for measurements. You can also create more complex queries.
Using the Query Builder
InfluxDB ODM ships with a query "Builder" object, which allows you to construct a query for exactly which measurements you want to return. If you use an IDE, you can also take advantage of auto-completion as you type the method names. From inside a controller:
Custom Repository Classes
In the previous section, you began constructing and using more complex queries from inside a controller. In order to isolate, test and reuse these queries, it's a good idea to create a custom repository class for your measurement and add methods with your query logic there.
To do this, add the name of the repository class to your mapping definition.
You have to create the repository in the namespace indicated above. Make sure it
extends the default MeasurementRepository
. Next, add a new method -
findAllOrderedByTimeDesc()
- to the new repository class. This method will query
for all of the CpuLoad
measurements, ordered by time desc.
You can use this new method like the default finder methods of the repository:
When using a custom repository class, you still have access to the default
finder methods such as find()
and findAll()
.
All versions of influxdb-odm with dependencies
doctrine/instantiator Version ^1.3.1 || ^2.0
doctrine/persistence Version ^3.0
influxdb/influxdb-php Version ^1.0