Merge pull request #619 from influxdata/flux/sqlite3

Flux SQLite support
pull/632/head
Scott Anderson 2019-11-20 15:11:34 -07:00 committed by GitHub
commit 3f200c1c17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 11 deletions

View File

@ -13,8 +13,9 @@ weight: 207
The [Flux](/v2.0/reference/flux) `sql` package provides functions for working with SQL data sources. 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 [`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/) like [PostgreSQL](https://www.postgresql.org/), [MySQL](https://www.mysql.com/),
and use the results with InfluxDB dashboards, tasks, and other operations. 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) - [Query a SQL data source](#query-a-sql-data-source)
- [Join SQL data with data in InfluxDB](#join-sql-data-with-data-in-influxdb) - [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 %}} {{% code-tabs %}}
[PostgreSQL](#) [PostgreSQL](#)
[MySQL](#) [MySQL](#)
[SQLite](#)
{{% /code-tabs %}} {{% /code-tabs %}}
{{% code-tab-content %}} {{% code-tab-content %}}
@ -62,6 +64,18 @@ sql.from(
) )
``` ```
{{% /code-tab-content %}} {{% /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 >}} {{< /code-tabs-wrapper >}}
_See the [`sql.from()` documentation](/v2.0/reference/flux/stdlib/sql/from/) for _See the [`sql.from()` documentation](/v2.0/reference/flux/stdlib/sql/from/) for

View File

@ -2,7 +2,8 @@
title: Flux SQL package title: Flux SQL package
list_title: SQL package list_title: SQL package
description: > 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. Import the `sql` package.
aliases: aliases:
- /v2.0/reference/flux/functions/sql/ - /v2.0/reference/flux/functions/sql/
@ -14,7 +15,8 @@ weight: 202
v2.0/tags: [functions, sql, package, mysql, postgres] 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: Import the `sql` package:
```js ```js

View File

@ -35,20 +35,24 @@ The following drivers are available:
- mysql - mysql
- postgres - postgres
- sqlite3
### dataSourceName ### 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. The string's form and structure depend on the [driver](#drivername) used.
_**Data type:** String_ _**Data type:** String_
##### Driver dataSourceName examples ##### Driver dataSourceName examples
```sh ```sh
# Postgres Driver: # Postgres Driver DSN
postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full
# MySQL Driver: # MySQL Driver DSN
username:password@tcp(localhost:3306)/dbname?param=value username:password@tcp(localhost:3306)/dbname?param=value
# SQLite Driver DSN
file:test.db?cache=shared&mode=memory
``` ```
### query ### query
@ -79,3 +83,14 @@ sql.from(
query:"SELECT * FROM ExampleTable" 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"
)
```

View File

@ -20,7 +20,8 @@ import "sql"
sql.to( sql.to(
driverName: "mysql", driverName: "mysql",
dataSourceName: "username:password@tcp(localhost:3306)/dbname?param=value", 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 - mysql
- postgres - postgres
- sqlite3
### dataSourceName ### 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. The string's form and structure depend on the [driver](#drivername) used.
_**Data type:** String_ _**Data type:** String_
##### Driver dataSourceName examples ##### Driver dataSourceName examples
```sh ```sh
# Postgres Driver # Postgres Driver DSN
postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full
# MySQL Driver # MySQL Driver DSN
username:password@tcp(localhost:3306)/dbname?param=value username:password@tcp(localhost:3306)/dbname?param=value
# SQLite Driver DSN
file:test.db?cache=shared&mode=memory
``` ```
### table ### table
@ -56,6 +61,16 @@ The destination table.
_**Data type:** String_ _**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 ## Examples
### Write data to a MySQL database ### Write data to a MySQL database
@ -79,3 +94,14 @@ sql.to(
table: "ExampleTable" 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"
)
```