diff --git a/content/influxdb/v2.0/reference/api/client-libraries/go.md b/content/influxdb/v2.0/reference/api/client-libraries/go.md index 65e17ad4c..2e5d6fe54 100644 --- a/content/influxdb/v2.0/reference/api/client-libraries/go.md +++ b/content/influxdb/v2.0/reference/api/client-libraries/go.md @@ -19,7 +19,7 @@ If just getting started, see [Get started with InfluxDB](/v2.0/get-started/). ## Before you begin -1. Install Go 1.3 or later](https://golang.org/doc/install) +1. [Install Go 1.3 or later](https://golang.org/doc/install). 2. Download the client package in your $GOPATH and build the package. ```sh @@ -30,12 +30,11 @@ If just getting started, see [Get started with InfluxDB](/v2.0/get-started/). go build ``` 3. Ensure that InfluxDB is running and you can connect to it. - If running InfluxDB locally, visit http://localhost:9999. - If using InfluxDB Cloud, visit your [InfluxDB Cloud URL](/v2.0/cloud/urls). + For information about what URL to use to connect to InfluxDB OSS or InfluxDB Cloud, see [InfluxDB URLs](/v2.0/reference/urls/). ## Boilerplate for the InfluxDB Go Client Library -Use the Go library to write and query data to and from InfluxDB. +Use the Go library to write and query data from InfluxDB. In your Go program, import the necessary packages and specify the entry point of your executable program. @@ -54,20 +53,20 @@ import ( Next, define variables for your InfluxDB [bucket](/v2.0/organizations/buckets/), [organization](/v2.0/organizations/), and [token](/v2.0/security/tokens/). ```go -bucket := "" -org := "" -token := "" -//variable to store the url of your local or InfluxDB Cloud instance -url := "" +bucket := "example-bucket" +org := "example-org" +token := "example-token" +// Store the URL of your InfluxDB instance +url := "http://localhost:9999" ``` -To write data, create the the InfluxDB Go Client and pass in our named parameters: `url` and `token`. +To write data, create the the InfluxDB Go Client and pass in the `url` and `token` parameters. ```go client := influxdb2.NewClient(url, token) ``` -Create a **write client** with the `WriteApiBlocking` method and pass in your other named parameters: `org` and `bucket`. +Create a **write client** with the `WriteApiBlocking` method and pass in the `org` and `bucket` parameters. ```go writeApi := client.WriteApiBlocking(org, bucket) @@ -76,7 +75,7 @@ writeApi := client.WriteApiBlocking(org, bucket) To query data, create an InfluxDB **query client** and pass in your InfluxDB `org`. ```go - queryApi := client.QueryApi(org) +queryApi := client.QueryApi(org) ``` ## Write data to InfluxDB with Go @@ -98,11 +97,11 @@ client.Close() ### Complete example write script ```go func main() { - bucket := "" - org := "" - token := "" - //variable to store the url of your local or InfluxDB Cloud instance - url := "" + bucket := "example-bucket" + org := "example-org" + token := "example-token" + // Store the URL of your InfluxDB instance + url := "http://localhost:9999" // Create new client with default option for server url authenticate by token client := influxdb2.NewClient(url, token) // User blocking write client for writes to desired bucket @@ -121,7 +120,7 @@ client.Close() ## Query data from InfluxDB with Go Use the Go library to query data to InfluxDB. -Create a flux query and supply your `bucket` parameter. +Create a Flux query and supply your `bucket` parameter. ```js from(bucket:"") diff --git a/content/influxdb/v2.0/reference/api/client-libraries/js.md b/content/influxdb/v2.0/reference/api/client-libraries/js.md index e6d02969f..15aa02c8e 100644 --- a/content/influxdb/v2.0/reference/api/client-libraries/js.md +++ b/content/influxdb/v2.0/reference/api/client-libraries/js.md @@ -19,11 +19,10 @@ If just getting started, see [Get started with InfluxDB](/v2.0/get-started/). ## Before you begin -1. Install [NodeJS](https://nodejs.org/en/download/package-manager/): +1. Install [NodeJS](https://nodejs.org/en/download/package-manager/). 2. Ensure that InfluxDB is running and you can connect to it. - If running InfluxDB locally, visit http://localhost:9999. - If using InfluxDB Cloud, visit your [InfluxDB Cloud URL](/v2.0/cloud/urls). + For information about what URL to use to connect to InfluxDB OSS or InfluxDB Cloud, see [InfluxDB URLs](/v2.0/reference/urls/). ## Easiest way to get started 1. Clone the [examples directory](https://github.com/influxdata/influxdb-client-js/tree/master/examples) in the [influxdb-client-js](https://github.com/influxdata/influxdb-client-js) repo. @@ -60,8 +59,8 @@ yarn install npm run browser ``` -## Boilerplate for the InfluxDB Javascript Client Lbrary -Use the Javascript library to write and query data to and from InfluxDB. +## Boilerplate for the InfluxDB Javascript Client Library +Use the Javascript library to write data to and query data from InfluxDB. To write a data point to InfluxDB using the JavaScript library, import the latest InfluxDB Javascript library in your script. @@ -74,16 +73,17 @@ Next, define constants for your InfluxDB [bucket](/v2.0/organizations/buckets/), ```js const proxy = '/influx' -const token = '' -const org = '' -const bucket = '' +const token = 'example-token' +const org = 'example-org' +const bucket = 'example-bucket' ``` -Instantiate the InfluxDB JavaScript Client and pass in our named parameters: `proxy` and `token`. +Instantiate the InfluxDB JavaScript Client and pass in the`proxy` and `token` parameters. ```js const InfluxDB = new InfluxDB({proxy, token}) ``` + ## Write data to InfluxDB with JavaScript Use the Javascript library to write data to InfluxDB. @@ -92,6 +92,7 @@ Use the `getWriteApi` method of the InfluxDB client to create a **write client** ```js const writeApi = InfluxDB.getWriteApi(org, bucket) ``` + The `useDefaultTags` method instructs the write api to use default tags when writing points. Create a [point](/v2.0/reference/glossary/#point) and write it to InfluxDB using the `writePoint` method. The `tag` and `floatField` methods add key value pairs for the tags and fields, respectively. Close the client to flush all pending writes and finish. ```js diff --git a/content/influxdb/v2.0/reference/api/client-libraries/python.md b/content/influxdb/v2.0/reference/api/client-libraries/python.md index 2fe4b2703..731fc3812 100644 --- a/content/influxdb/v2.0/reference/api/client-libraries/python.md +++ b/content/influxdb/v2.0/reference/api/client-libraries/python.md @@ -49,8 +49,8 @@ Next, we define a few variables with the name of your [bucket](/v2.0/organizatio bucket = "" org = "" token = "" -#variable to store the url of your local or InfluxDB Cloud instance -url="" +# Store the URL of your InfluxDB instance +url="http://localhost:9999" ``` Instantiate the client. The `InfluxDBClient` object takes three named parameters: `url`, `org`, and `token`. Pass in the named parameters. @@ -86,8 +86,8 @@ from influxdb_client.client.write_api import SYNCHRONOUS bucket = "" org = "" token = "" -#variable to store the url of your local or InfluxDB Cloud instance -url="" +# Store the URL of your InfluxDB instance +url="http://localhost:9999" client = influxdb_client.InfluxDBClient( url=url, @@ -108,13 +108,13 @@ To query data, instantiate the **query client**. query_api = client.query_api() ``` -Next, create a flux query. +Next, create a Flux query. ```python query = ‘ from(bucket:"my-bucket")\ |> range(start: -10m)\ -|> filter(fn:(r) => r._measurement == “my_measurement”)\ -|> filter(fn: (r) => r.location == Prague")\ +|> filter(fn:(r) => r._measurement == "my_measurement")\ +|> filter(fn: (r) => r.location == "Prague")\ |> filter(fn:(r) => r._field == "temperature" )‘ ``` @@ -127,6 +127,7 @@ result = client.query_api().query(org=org, query=query) Iterate through the tables and records in the Flux Object. Use the `get_value()` method to return values. Use the `get_field()` method to return fields. + ```python results = [] for table in result: @@ -155,8 +156,8 @@ print(results) query_api = client.query_api() query = ‘ from(bucket:"my-bucket")\ |> range(start: -10m)\ -|> filter(fn:(r) => r._measurement == “my_measurement”)\ -|> filter(fn: (r) => r.location == Prague")\ +|> filter(fn:(r) => r._measurement == "my_measurement")\ +|> filter(fn: (r) => r.location == "Prague")\ |> filter(fn:(r) => r._field == "temperature" )‘ result = client.query_api().query(org=org, query=query) results = []