SQLコネクタ
SQLコネクタは、リレーショナルデータベースにデータを書き込みます。
コネクタタイプ: SqlWriter
サポートされているデータベース:
- MySQL
- PostgreSQL
- SQL Server(MSSQL)
{ "type": "SqlWriter", "config": { "connectionString": "user:password@tcp(localhost:3306)/database_name", "driver": "mysql", "table": "sensor_data", "writeAction": "Insert", "mode": "ColumnMapping", "columns": { "temperature": "temp_column", "pressure": "press_column", "timestamp": "ts_column" } }}PostgreSQL
Section titled “PostgreSQL”{ "type": "SqlWriter", "config": { "connectionString": "host=localhost port=5432 user=postgres password=pass dbname=mydb sslmode=disable", "driver": "postgres", "table": "measurements", "writeAction": "Insert", "mode": "ColumnMapping", "columns": { "temperature": "temperature", "humidity": "humidity" } }}SQL Server
Section titled “SQL Server”{ "type": "SqlWriter", "config": { "connectionString": "sqlserver://user:pass@localhost:1433?database=mydb", "driver": "sqlserver", "table": "sensor_readings", "writeAction": "Upsert", "mode": "ColumnMapping", "columns": { "sensor_id": "id", "value": "reading_value" } }}設定パラメータ
Section titled “設定パラメータ”- connectionString: データベース固有の接続文字列
- driver: データベースドライバー(
mysql、postgres、sqlserver) - table: ターゲットテーブル名
- writeAction: 書き込み操作(
Insert、Update、Upsert) - mode: マッピングモード(
ColumnMapping) - columns: ペイロードキーからデータベース列へのマッピング
書き込みアクション
Section titled “書き込みアクション”Insert
Section titled “Insert”新しい行を追加:
{ "writeAction": "Insert"}Update
Section titled “Update”既存の行を更新(WHERE条件が必要):
{ "writeAction": "Update"}Upsert
Section titled “Upsert”存在する場合は挿入または更新:
{ "writeAction": "Upsert"}列マッピング
Section titled “列マッピング”Meddleペイロードキーをデータベース列にマッピング:
{ "columns": { "payload_key": "database_column", "temperature": "temp_celsius", "pressure": "pressure_bar", "timestamp": "recorded_at" }}user:password@tcp(host:port)/database?param=valuePostgreSQL
Section titled “PostgreSQL”host=localhost port=5432 user=user password=pass dbname=db sslmode=disableSQL Server
Section titled “SQL Server”sqlserver://user:pass@host:port?database=db¶m=valueユースケース:生産データロギング
Section titled “ユースケース:生産データロギング”{ "type": "SqlWriter", "config": { "connectionString": "user:pass@tcp(mysql.local:3306)/production", "driver": "mysql", "table": "machine_logs", "writeAction": "Insert", "mode": "ColumnMapping", "columns": { "machine_id": "machine_id", "temperature": "temperature", "speed": "rpm", "status": "operational_status", "timestamp": "log_time" } }}ベストプラクティス
Section titled “ベストプラクティス”- 頻繁にクエリされる列に適切なインデックスを作成
- べき等操作には
Upsertを使用 - テーブルスキーマが列マッピングと一致することを確認
- 高スループットシナリオには接続プーリングを使用
- データベースパフォーマンスとクエリ実行時間を監視
トラブルシューティング
Section titled “トラブルシューティング”- 接続文字列形式を確認
- データベースサーバーが実行中であることを確認
- 認証情報を確認
- ファイアウォールルールを確認
列が見つからない
Section titled “列が見つからない”- マッピング内の列名がデータベーススキーマと一致することを確認
- テーブルが存在することを確認
- 大文字小文字の区別を確認