Skip to content
This repository has been archived by the owner on Aug 5, 2023. It is now read-only.

Added precision to 'write' request #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 39 additions & 37 deletions aioinflux/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,24 @@ def __init__(self, resp):

class InfluxDBClient:
def __init__(
self,
host: str = 'localhost',
port: int = 8086,
path: str = '/',
mode: str = 'async',
output: str = 'json',
db: Optional[str] = None,
database: Optional[str] = None,
ssl: bool = False,
*,
unix_socket: Optional[str] = None,
username: Optional[str] = None,
password: Optional[str] = None,
timeout: Optional[Union[aiohttp.ClientTimeout, float]] = None,
loop: Optional[asyncio.AbstractEventLoop] = None,
redis_opts: Optional[dict] = None,
cache_expiry: int = 86400,
**kwargs
self,
host: str = 'localhost',
port: int = 8086,
path: str = '/',
mode: str = 'async',
output: str = 'json',
db: Optional[str] = None,
database: Optional[str] = None,
ssl: bool = False,
*,
unix_socket: Optional[str] = None,
username: Optional[str] = None,
password: Optional[str] = None,
timeout: Optional[Union[aiohttp.ClientTimeout, float]] = None,
loop: Optional[asyncio.AbstractEventLoop] = None,
redis_opts: Optional[dict] = None,
cache_expiry: int = 86400,
**kwargs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore original indentation

):
"""
:class:`~aioinflux.client.InfluxDBClient` holds information necessary
Expand Down Expand Up @@ -243,14 +243,14 @@ async def ping(self) -> dict:

@runner
async def write(
self,
data: Union[PointType, Iterable[PointType]],
measurement: Optional[str] = None,
db: Optional[str] = None,
precision: Optional[str] = None,
rp: Optional[str] = None,
tag_columns: Optional[Iterable] = None,
**extra_tags,
self,
data: Union[PointType, Iterable[PointType]],
measurement: Optional[str] = None,
db: Optional[str] = None,
precision: Optional[str] = None,
rp: Optional[str] = None,
tag_columns: Optional[Iterable] = None,
**extra_tags,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore original indentation

) -> bool:
"""Writes data to InfluxDB.
Input can be:
Expand Down Expand Up @@ -286,13 +286,15 @@ async def write(
"""
if not self._session:
await self.create_session()
if precision is not None:
# FIXME: Implement. Related issue: aioinflux/pull/13
raise NotImplementedError("'precision' parameter is not supported yet")
if precision and precision not in {"ns", "u", "ms", "s", "m", "h"}:
raise NotImplementedError("'precision' must must be one of "
"the following: 'ns', 'u', 'ms', 's', 'm', 'h'")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably raise ValueError instead

data = serialization.serialize(data, measurement, tag_columns, **extra_tags)
params = {'db': db or self.db}
if rp:
params['rp'] = rp
if precision:
params["precision"] = precision
url = self.url.format(endpoint='write')
async with self._session.post(url, params=params, data=data) as resp:
if resp.status == 204:
Expand All @@ -301,14 +303,14 @@ async def write(

@runner
async def query(
self,
q: AnyStr,
*,
epoch: str = 'ns',
chunked: bool = False,
chunk_size: Optional[int] = None,
db: Optional[str] = None,
use_cache: bool = False,
self,
q: AnyStr,
*,
epoch: str = 'ns',
chunked: bool = False,
chunk_size: Optional[int] = None,
db: Optional[str] = None,
use_cache: bool = False,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore original indentation

) -> Union[AsyncGenerator[ResultType, None], ResultType]:
"""Sends a query to InfluxDB.
Please refer to the InfluxDB documentation for all the possible queries:
Expand Down