Skip to content

Use sqlx Instead of String Formatting in TimescaleDB Provider#83

Open
YKawesome wants to merge 2 commits into
mainfrom
refactor/sqlx-named-params
Open

Use sqlx Instead of String Formatting in TimescaleDB Provider#83
YKawesome wants to merge 2 commits into
mainfrom
refactor/sqlx-named-params

Conversation

@YKawesome

Copy link
Copy Markdown
Collaborator

Description

Updates the TimescaleDB Provider to use sqlx instead of string formatting. The insertion statements have been updated:

const (
	insertEventDefSQL = `INSERT INTO eventDefs (id, component, name, severity, args)
		VALUES (:id, :component, :name, :severity, :args) ON CONFLICT DO NOTHING`
	insertEventSQL = `INSERT INTO events (eventDefId, time, timeSclk, message, source, args, ert)
		VALUES (:eventDefId, :time, :timeSclk, :message, :source, :args, :ert) ON CONFLICT DO NOTHING`
	insertTelemetryDefSQL = `INSERT INTO telemetryDefs (id, name, component)
		VALUES (:id, :name, :component) ON CONFLICT DO NOTHING`
	insertTelemetrySQL = `INSERT INTO telemetry (time, telemetryDefId, timeSclk, source, labels, key, valueType, integral, floating, boolval, string, bytes, ert)
		VALUES (:time, :telemetryDefId, :timeSclk, :source, :labels, :key, :valueType, :integral, :floating, :boolval, :string, :bytes, :ert) ON CONFLICT DO NOTHING`
)

Along with the ExecContext blocks:

if _, err := tx.NamedExecContext(ctx, insertEventDefSQL, map[string]any{
	"id":        ref.GetId(),
	"component": ref.GetComponent(),
	"name":      ref.GetName(),
	"severity":  ref.GetSeverity(),
	"args":      string(defArgs),
}); err != nil {
	return fmt.Errorf("failed to insert event def: %w", err)
}

Small changes were made to transactions (e.g. BeginTxx instead of BeginTx) to follow the sqlx methods.

Issues

Closes #80

@YKawesome YKawesome requested a review from Kronos3 July 6, 2026 23:25
@YKawesome YKawesome self-assigned this Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use sqlx instead of string formatting for robustness in TimescaleDB Provider

1 participant