From 0e4ba9050f77d6af366390918c932fc27f4b3e32 Mon Sep 17 00:00:00 2001 From: William Perron Date: Tue, 30 Jan 2024 09:01:23 -0500 Subject: [PATCH] add option to inject a sql.DB instance --- factory.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/factory.go b/factory.go index a14d190..523d8b9 100644 --- a/factory.go +++ b/factory.go @@ -79,3 +79,16 @@ func newSqliteExporter(cfg *Config) (*sqliteExporter, error) { func NewSqliteSDKTraceExporter(cfg *Config) (sdktrace.SpanExporter, error) { return newSqliteExporter(cfg) } + +func NewSqliteSDKTraceExporterWithDB(db *sql.DB) (sdktrace.SpanExporter, error) { + tx, _ := db.Begin() + defer tx.Commit() + + if _, err := tx.Exec(initScript); err != nil { + return nil, fmt.Errorf("failed to run migrations: %w", err) + } + + return &sqliteExporter{ + db: db, + }, nil +}