You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Query, Insert, Update, and Delete information from PostgreSQL, MsSQL, MySQL, Oracle, Firebird Databases. Additional databases can be added by installing the pre-requisite packes and passing the driver name as documented at [SQLAlchemy Dialects Doc](https://docs.sqlalchemy.org/en/latest/dialects/index.html).
18
5
19
6
## Quick Start
20
7
@@ -30,6 +17,17 @@ yum install unixODBC-devel
30
17
st2 run sql.query host=test_serve.domain.tld username=test_user password=test_password database=test_database drivername=postgresql query="select * from test;"
31
18
```
32
19
20
+
## Included Drivers
21
+
This pack is already set up to connect to the databases listed above. Additional databases can be connected to but pre-requisite packages will need to be installed before the drivers will work. [SQLAlchemy Dialects Doc](https://docs.sqlalchemy.org/en/latest/dialects/index.html).
22
+
23
+
You can pass any of the following driver names without any additional packages needing installed.
24
+
*`postgresql` - PostgreSQL databases
25
+
*`mssql` - Microsoft SQL Server databases
26
+
*`mysql` - MySQL/MariaDB databases
27
+
*`oracle` - Oracle databases
28
+
*`firebird` - Firebird databases
29
+
30
+
33
31
## Configuration and Connecting to Databases
34
32
Connecting to different types of databases is shown below. Connecting to different databases is donein the same manor except with sqlite where all you need to pass is the path to the database in the database option. This is show below. For more information about connections please refer to [SQLAlchemy Connection Docs](https://docs.sqlalchemy.org/en/latest/core/engines.html)
35
33
@@ -59,17 +57,20 @@ connections:
59
57
drivername: sqlite
60
58
```
61
59
62
-
Each entry should contain
60
+
Each entry should contain:
63
61
64
-
*``host`` - Database hostname
65
-
*``username`` - Username to authenticate to DB
66
-
*``password`` - Password for DB authentication
67
-
*``database`` - Database to use
68
-
*``port`` - Port to connect to database on. If Default leave blank
69
-
*``drivername`` - The type of database that is being connected to.
62
+
*`host` - Database hostname
63
+
*`username` - Username to authenticate to DB
64
+
*`password` - Password for DB authentication
65
+
*`database` - Database to use
66
+
*`port` - Port to connect to database on. If Default leave blank
67
+
*`drivername` - The type of database that is being connected to.
70
68
71
69
When running actions, you can pass in the name of a connection, e.g.
72
-
`st2 run sql.query connection="postgresql" query="select * from test;"`
70
+
71
+
``` shell
72
+
st2 run sql.query connection="postgresql" query="SELECT * FROM test;"
73
+
```
73
74
74
75
Alternatively, when running an action, you can pass in the host, username, password, database, port, drivername parameters. These parameters can also be used for overrides if you wish to use the configs as well.
75
76
@@ -87,19 +88,143 @@ Alternatively, when running an action, you can pass in the host, username, passw
87
88
| update | Update data in a database table. |
88
89
| delete | Delete data from a database table. |
89
90
91
+
### Action Example - sql.query
92
+
93
+
`sql.query` can run any SQL query against a database. This can be used for simple `SELECT`
94
+
statements:
95
+
96
+
```shell
97
+
st2 run sql.query connection="postgresql" query="SELECT * FROM test;"
98
+
```
99
+
100
+
Workflow usage:
101
+
102
+
``` yaml
103
+
insert_data:
104
+
action: sql.query
105
+
input:
106
+
connection: postgresql
107
+
query: "SELECT * FROM test;"
108
+
```
109
+
110
+
This action is also the one to use if you have a complex SQL statement that you want to run,
111
+
but there isn't another action in this pack that supports what you're trying to do.
112
+
In this case, simply pass in your arbitrary SQL statement into the `query` parameter and
113
+
it will be executed:
114
+
115
+
```shell
116
+
st2 run sql.query connection="postgresql" query="SELECT * FROM test JOIN somecrazytable ON id;"
117
+
```
118
+
119
+
### Action Example - sql.insert
120
+
121
+
`sql.insert` is used to insert a single record into a table:
122
+
123
+
```shell
124
+
st2 run sql.insert connection="postgresql" table="people" data='{"name": "bob", "phone": "1234567890"}'
125
+
```
126
+
127
+
Workflow usage:
128
+
129
+
``` yaml
130
+
insert_data:
131
+
action: sql.insert
132
+
input:
133
+
connection: postgresql
134
+
table: "people"
135
+
data:
136
+
name: "bob"
137
+
phone: "1234567890"
138
+
```
139
+
140
+
### Action Example - sql.insert_bulk
141
+
142
+
`sql.insert_bulk` is used to insert multiple records into a table. In this case the `data`
143
+
parameter expects an array of objects, where each object is a record to insert.
Copy file name to clipboardExpand all lines: actions/delete.yaml
-8Lines changed: 0 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -34,14 +34,6 @@
34
34
drivername:
35
35
type: string
36
36
description: "Optional override of the database_type in <connection> (required if <connection> is not specified). The type of database that is being connected to."
Copy file name to clipboardExpand all lines: actions/insert.yaml
-8Lines changed: 0 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -34,14 +34,6 @@
34
34
drivername:
35
35
type: string
36
36
description: "Optional override of the database_type in <connection> (required if <connection> is not specified). The type of database that is being connected to."
Copy file name to clipboardExpand all lines: actions/insert_bulk.yaml
-8Lines changed: 0 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -34,14 +34,6 @@
34
34
drivername:
35
35
type: string
36
36
description: "Optional override of the database_type in <connection> (required if <connection> is not specified). The type of database that is being connected to."
Copy file name to clipboardExpand all lines: actions/query.yaml
-8Lines changed: 0 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -34,14 +34,6 @@
34
34
drivername:
35
35
type: string
36
36
description: "Optional override of the database_type in <connection> (required if <connection> is not specified). The type of database that is being connected to."
Copy file name to clipboardExpand all lines: actions/update.yaml
-8Lines changed: 0 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -34,14 +34,6 @@
34
34
drivername:
35
35
type: string
36
36
description: "Optional override of the database_type in <connection> (required if <connection> is not specified). The type of database that is being connected to."
0 commit comments