SQL Connector
Overview
Section titled “Overview”The SQL connector writes data to relational databases.
Connector Type: SqlWriter
Supported Databases:
- MySQL
- PostgreSQL
- SQL Server (MSSQL)
Configuration
Section titled “Configuration”{ "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" } }}Configuration Parameters
Section titled “Configuration Parameters”- connectionString: Database-specific connection string
- driver: Database driver (
mysql,postgres,sqlserver) - table: Target table name
- writeAction: Write operation (
Insert,Update,Upsert) - mode: Mapping mode (
ColumnMapping) - columns: Map payload keys to database columns
Write Actions
Section titled “Write Actions”Insert
Section titled “Insert”Add new rows:
{ "writeAction": "Insert"}Update
Section titled “Update”Update existing rows (requires WHERE condition):
{ "writeAction": "Update"}Upsert
Section titled “Upsert”Insert or update if exists:
{ "writeAction": "Upsert"}Column Mapping
Section titled “Column Mapping”Map Meddle payload keys to database columns:
{ "columns": { "payload_key": "database_column", "temperature": "temp_celsius", "pressure": "pressure_bar", "timestamp": "recorded_at" }}Connection Strings
Section titled “Connection Strings”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=valueUse Case: Production Data Logging
Section titled “Use Case: Production Data Logging”{ "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" } }}Best Practices
Section titled “Best Practices”- Create appropriate indexes on frequently queried columns
- Use
Upsertfor idempotent operations - Ensure table schema matches column mappings
- Use connection pooling for high-throughput scenarios
- Monitor database performance and query execution times
Troubleshooting
Section titled “Troubleshooting”Connection Failed
Section titled “Connection Failed”- Verify connection string format
- Check database server is running
- Verify credentials
- Check firewall rules
Column Not Found
Section titled “Column Not Found”- Ensure column names in mapping match database schema
- Check table exists
- Verify case sensitivity