|
1 | | -# sql Integration Pack |
| 1 | +# SQL Integration Pack |
| 2 | +Query, Insert, Update, and Delete information from PostgreSQL, SQLite, MsSQL, MySQL, Oracle, Firebird, and Sybase Databases |
| 3 | + |
| 4 | +## Pre-Requisites |
| 5 | +This pack is set up to provide funcationality for the above databases. For MySQL and MsSQL we need to install 2 system packages. |
| 6 | + |
| 7 | +#### MySQL |
| 8 | +``` shell |
| 9 | +yum install mysql-devel |
| 10 | +``` |
| 11 | + |
| 12 | +#### MsSQL |
| 13 | +https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017 |
| 14 | +``` shell |
| 15 | +curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo |
| 16 | +yum install msodbcsql17 |
| 17 | +yum install unixODBC-devel |
| 18 | +``` |
| 19 | + |
| 20 | +## Quick Start |
| 21 | + |
| 22 | +1. Install the pack |
| 23 | + |
| 24 | + ``` shell |
| 25 | + st2 pack install sql |
| 26 | + ``` |
| 27 | + |
| 28 | +2. Execute an action (example: query) |
| 29 | + |
| 30 | + ``` shell |
| 31 | + st2 run sql.query host=test_serve.domain.tld username=test_user password=test_password database=test_database database_type=postgresql query="select * from test;" |
| 32 | + ``` |
2 | 33 |
|
3 | 34 | ## Configuration |
4 | | -TODO: Describe configuration |
| 35 | +Copy the example configuration in [sql.yaml.example](./sql.yaml.example) |
| 36 | +to `/opt/stackstorm/configs/sql.yaml` and edit as required. |
| 37 | + |
| 38 | +It can contain an array of one or more sets of SQL connection parameters, like this: |
| 39 | + |
| 40 | +``` yaml |
| 41 | +--- |
| 42 | +sql: |
| 43 | + postgresql: |
| 44 | + host: postgresql_db.domain.tld |
| 45 | + |
| 46 | + password: Password |
| 47 | + database: TestDatabase |
| 48 | + database_type: postgresql |
| 49 | + mysql: |
| 50 | + host: mysql_db.domain.tld |
| 51 | + |
| 52 | + password: NewPassword |
| 53 | + database: TestDatabase |
| 54 | + database_type: mysql |
| 55 | +``` |
| 56 | + |
| 57 | +Each entry should contain |
5 | 58 |
|
| 59 | +* ``host`` - Database hostname |
| 60 | +* ``username`` - Username to authenticate to DB |
| 61 | +* ``password`` - Password for DB authentication |
| 62 | +* ``database`` - Database to use |
| 63 | +* ``database_type`` - The type of database that is being connected to. |
6 | 64 |
|
7 | | -# Sensors |
| 65 | +When running actions, you can pass in the name of a connection, e.g. |
| 66 | +`st2 run sql.query connection="postgresql" query="select * from test;"` |
8 | 67 |
|
9 | | -## Example Sensor |
10 | | -TODO: Describe sensor |
| 68 | +Alternatively, when running an action, you can pass in the host, username, password, database, database_type parameters. These parameters can also be used for overrides if you wish to use the configs as well. |
11 | 69 |
|
| 70 | +**Note** : When modifying the configuration in `/opt/stackstorm/configs/` please remember to tell StackStorm to load these new values by running `st2ctl reload --register-configs` |
12 | 71 |
|
13 | 72 | # Actions |
14 | 73 |
|
15 | | -## example |
16 | | -TODO: Describe action |
| 74 | +| Action | Description | |
| 75 | +|--------|-------------| |
| 76 | +| query | Generic query action to get inforamtion from the database. | |
| 77 | +| insert | Insert data into a database table. Insert data is passed as an object. | |
| 78 | +| insert_bulk | Bulk insert data into a database table. Insert data is passed as an array of objects. | |
| 79 | +| update | Update data in a database table. | |
| 80 | +| delete | Delete data from a database table. | |
0 commit comments