commit
3f200c1c17
|
@ -13,8 +13,9 @@ weight: 207
|
|||
|
||||
The [Flux](/v2.0/reference/flux) `sql` package provides functions for working with SQL data sources.
|
||||
[`sql.from()`](/v2.0/reference/flux/stdlib/sql/from/) lets you query SQL data sources
|
||||
like [PostgreSQL](https://www.postgresql.org/) and [MySQL](https://www.mysql.com/)
|
||||
and use the results with InfluxDB dashboards, tasks, and other operations.
|
||||
like [PostgreSQL](https://www.postgresql.org/), [MySQL](https://www.mysql.com/),
|
||||
and [SQLite](https://www.sqlite.org/index.html), and use the results with InfluxDB
|
||||
dashboards, tasks, and other operations.
|
||||
|
||||
- [Query a SQL data source](#query-a-sql-data-source)
|
||||
- [Join SQL data with data in InfluxDB](#join-sql-data-with-data-in-influxdb)
|
||||
|
@ -37,6 +38,7 @@ To query a SQL data source:
|
|||
{{% code-tabs %}}
|
||||
[PostgreSQL](#)
|
||||
[MySQL](#)
|
||||
[SQLite](#)
|
||||
{{% /code-tabs %}}
|
||||
|
||||
{{% code-tab-content %}}
|
||||
|
@ -62,6 +64,18 @@ sql.from(
|
|||
)
|
||||
```
|
||||
{{% /code-tab-content %}}
|
||||
|
||||
{{% code-tab-content %}}
|
||||
```js
|
||||
import "sql"
|
||||
|
||||
sql.from(
|
||||
driverName: "sqlite3",
|
||||
dataSourceName: "file:test.db?cache=shared&mode=memory",
|
||||
query: "SELECT * FROM example_table"
|
||||
)
|
||||
```
|
||||
{{% /code-tab-content %}}
|
||||
{{< /code-tabs-wrapper >}}
|
||||
|
||||
_See the [`sql.from()` documentation](/v2.0/reference/flux/stdlib/sql/from/) for
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
title: Flux SQL package
|
||||
list_title: SQL package
|
||||
description: >
|
||||
The Flux SQL package provides tools for working with data in SQL databases such as MySQL and PostgreSQL.
|
||||
The Flux SQL package provides tools for working with data in SQL databases such
|
||||
as MySQL, PostgreSQL, and SQLite.
|
||||
Import the `sql` package.
|
||||
aliases:
|
||||
- /v2.0/reference/flux/functions/sql/
|
||||
|
@ -14,7 +15,8 @@ weight: 202
|
|||
v2.0/tags: [functions, sql, package, mysql, postgres]
|
||||
---
|
||||
|
||||
SQL Flux functions provide tools for working with data in SQL databases such as MySQL and PostgreSQL.
|
||||
SQL Flux functions provide tools for working with data in SQL databases such as
|
||||
MySQL, PostgreSQL, and SQLite.
|
||||
Import the `sql` package:
|
||||
|
||||
```js
|
||||
|
|
|
@ -35,20 +35,24 @@ The following drivers are available:
|
|||
|
||||
- mysql
|
||||
- postgres
|
||||
- sqlite3
|
||||
|
||||
### dataSourceName
|
||||
The connection string used to connect to the SQL database.
|
||||
The data source name (DSN) or connection string used to connect to the SQL database.
|
||||
The string's form and structure depend on the [driver](#drivername) used.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
##### Driver dataSourceName examples
|
||||
```sh
|
||||
# Postgres Driver:
|
||||
# Postgres Driver DSN
|
||||
postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full
|
||||
|
||||
# MySQL Driver:
|
||||
# MySQL Driver DSN
|
||||
username:password@tcp(localhost:3306)/dbname?param=value
|
||||
|
||||
# SQLite Driver DSN
|
||||
file:test.db?cache=shared&mode=memory
|
||||
```
|
||||
|
||||
### query
|
||||
|
@ -79,3 +83,14 @@ sql.from(
|
|||
query:"SELECT * FROM ExampleTable"
|
||||
)
|
||||
```
|
||||
|
||||
### Query an SQLite database
|
||||
```js
|
||||
import "sql"
|
||||
|
||||
sql.from(
|
||||
driverName: "sqlite3",
|
||||
dataSourceName: "file:test.db?cache=shared&mode=memory",
|
||||
query:"SELECT * FROM ExampleTable"
|
||||
)
|
||||
```
|
||||
|
|
|
@ -20,7 +20,8 @@ import "sql"
|
|||
sql.to(
|
||||
driverName: "mysql",
|
||||
dataSourceName: "username:password@tcp(localhost:3306)/dbname?param=value",
|
||||
table: "ExampleTable"
|
||||
table: "ExampleTable",
|
||||
batchSize: 10000
|
||||
)
|
||||
```
|
||||
|
||||
|
@ -35,20 +36,24 @@ The following drivers are available:
|
|||
|
||||
- mysql
|
||||
- postgres
|
||||
- sqlite3
|
||||
|
||||
### dataSourceName
|
||||
The connection string used to connect to the SQL database.
|
||||
The data source name (DSN) or connection string used to connect to the SQL database.
|
||||
The string's form and structure depend on the [driver](#drivername) used.
|
||||
|
||||
_**Data type:** String_
|
||||
|
||||
##### Driver dataSourceName examples
|
||||
```sh
|
||||
# Postgres Driver
|
||||
# Postgres Driver DSN
|
||||
postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full
|
||||
|
||||
# MySQL Driver
|
||||
# MySQL Driver DSN
|
||||
username:password@tcp(localhost:3306)/dbname?param=value
|
||||
|
||||
# SQLite Driver DSN
|
||||
file:test.db?cache=shared&mode=memory
|
||||
```
|
||||
|
||||
### table
|
||||
|
@ -56,6 +61,16 @@ The destination table.
|
|||
|
||||
_**Data type:** String_
|
||||
|
||||
### batchSize
|
||||
The number of parameters or columns that can be queued within each call to `Exec`.
|
||||
Defaults to `10000`.
|
||||
|
||||
_**Data type:** Integer_
|
||||
|
||||
{{% note %}}
|
||||
If writing to a **SQLite** database, set `batchSize` to `999` or less.
|
||||
{{% /note %}}
|
||||
|
||||
## Examples
|
||||
|
||||
### Write data to a MySQL database
|
||||
|
@ -79,3 +94,14 @@ sql.to(
|
|||
table: "ExampleTable"
|
||||
)
|
||||
```
|
||||
|
||||
### Write data to an SQLite database
|
||||
```js
|
||||
import "sql"
|
||||
|
||||
sql.to(
|
||||
driverName: "sqlite3",
|
||||
dataSourceName: "file:test.db?cache=shared&mode=memory",
|
||||
table: "ExampleTable"
|
||||
)
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue