Merge branch 'v1.0-rc3' into support-priority-queue-for-rabbitmq-bindings

This commit is contained in:
Yaron Schneider 2021-01-26 11:07:12 -08:00 committed by GitHub
commit da3b53f68e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 149 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
# Visual Studio 2015/2017/2019 cache/options directory
.vs/
.idea/
node_modules/
daprdocs/public
daprdocs/resources/_gen

View File

@ -19,6 +19,7 @@ Every binding has its own unique set of properties. Click the name link to see t
| [Kafka]({{< ref kafka.md >}}) | ✅ | ✅ | Experimental |
| [Kubernetes Events]({{< ref "kubernetes-binding.md" >}}) | ✅ | | Experimental |
| [MQTT]({{< ref mqtt.md >}}) | ✅ | ✅ | Experimental |
| [MySQL]({{< ref mysql.md >}}) | | ✅ | Experimental |
| [PostgreSql]({{< ref postgres.md >}}) | | ✅ | Experimental |
| [Postmark]({{< ref postmark.md >}}) | | ✅ | Experimental |
| [RabbitMQ]({{< ref rabbitmq.md >}}) | ✅ | ✅ | Experimental |

View File

@ -0,0 +1,147 @@
---
type: docs
title: "MySQL binding spec"
linkTitle: "MySQL"
description: "Detailed documentation on the MySQL binding component"
---
## Setup Dapr component
```yaml
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: <NAME>
namespace: <NAMESPACE>
spec:
type: bindings.mysql
version: v1
metadata:
- name: url # Required, define DB connection in DSN format
value: <CONNECTION_STRING>
- name: pemPath # Optional
value: <PEM PATH>
- name: maxIdleConns
value: <MAX_IDLE_CONNECTIONS>
- name: maxOpenConns
value: <MAX_OPEN_CONNECTIONS>
- name: connMaxLifetime
value: <CONNECTILN_MAX_LIFE_TIME>
- name: connMaxIdleTime
value: <CONNECTION_MAX_IDLE_TIME>
```
The MySQL binding uses [Go-MySQL-Driver](https://github.com/go-sql-driver/mysql) internally so the `url` parameter should follow the `DSN` format shown below:
- `url`: Required, represent DB connection in Data Source Name (DNS) format.
**Example DSN**
```yaml
- name: url
value: user:password@tcp(localhost:3306)/dbname
```
If your server requires SSL your connection string must end of `&tls=custom` for example, `"<user>:<password>@tcp(<server>:3306)/<database>?allowNativePasswords=true&tls=custom"`. You must replace the `<PEM PATH>` with a full path to the PEM file. If you are using [MySQL on Azure](http://bit.ly/AzureMySQLSSL) see the Azure [documentation on SSL database connections](http://bit.ly/MySQLSSL), for information on how to download the required certificate. The connection to MySQL will require a minimum TLS version of 1.2.
- `pemPath`: path to the PEM file
also support connection pool configuration variables:
- `maxIdleConns`: integer greater than 0
- `maxOpenConns`: integer greater than 0
- `connMaxLifetime`: duration string
- `connMaxIdleTime`: duration string
{{% alert title="Warning" color="warning" %}} The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described [here]({{< ref component-secrets.md >}}). {{% /alert %}}
## Output Binding Supported Operations
- `exec`
- `query`
- `close`
### exec
The `exec` operation can be used for DDL operations (like table creation), as well as `INSERT`, `UPDATE`, `DELETE` operations which return only metadata (e.g. number of affected rows).
**Request**
```json
{
"operation": "exec",
"metadata": {
"sql": "INSERT INTO foo (id, c1, ts) VALUES (1, 'demo', '2020-09-24T11:45:05Z07:00')"
}
}
```
**Response**
```json
{
"metadata": {
"operation": "exec",
"duration": "294µs",
"start-time": "2020-09-24T11:13:46.405097Z",
"end-time": "2020-09-24T11:13:46.414519Z",
"rows-affected": "1",
"sql": "INSERT INTO foo (id, c1, ts) VALUES (1, 'demo', '2020-09-24T11:45:05Z07:00')"
}
}
```
### query
The `query` operation is used for `SELECT` statements, which returns the metadata along with data in a form of an array of row values.
**Request**
```json
{
"operation": "query",
"metadata": {
"sql": "SELECT * FROM foo WHERE id < 3"
}
}
```
**Response**
```json
{
"metadata": {
"operation": "query",
"duration": "432µs",
"start-time": "2020-09-24T11:13:46.405097Z",
"end-time": "2020-09-24T11:13:46.420566Z",
"sql": "SELECT * FROM foo WHERE id < 3"
},
"data": "[
[0,\"test-0\",\"2020-09-24T04:13:46Z\"],
[1,\"test-1\",\"2020-09-24T04:13:46Z\"],
[2,\"test-2\",\"2020-09-24T04:13:46Z\"]
]"
}
```
### close
Finally, the `close` operation can be used to explicitly close the DB connection and return it to the pool. This operation doesn't have any response.
**Request**
```json
{
"operation": "close"
}
```
> Note, the MySQL binding itself doesn't prevent SQL injection, like with any database application, validate the input before executing query.
## Related links
- [Bindings building block]({{< ref bindings >}})
- [How-To: Trigger application with input binding]({{< ref howto-triggers.md >}})
- [How-To: Use bindings to interface with external resources]({{< ref howto-bindings.md >}})
- [Bindings API reference]({{< ref bindings_api.md >}})