sqldb

package
v2.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sqldb is a general SQL DB backend implementation that takes an stdlib sql.DB connection and creates tables and writes results to it. It has explicit support for MySQL and PostGres for handling differences in SQL dialects, but should ideally work with any standard SQL backend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Opt

type Opt struct {
	DBType         string
	ResultsTable   string
	UnloggedTables bool
}

Opt represents SQL DB backend's options.

type SQLDBResultSet

type SQLDBResultSet struct {
	// contains filtered or unexported fields
}

SQLDBResultSet represents a writer that saves results to a sqlDB backend.

func (*SQLDBResultSet) Close

func (w *SQLDBResultSet) Close() error

Close closes the active sqlDB connection.

func (*SQLDBResultSet) Flush

func (w *SQLDBResultSet) Flush() error

Flush flushes the rows written into the sqlDB pipe.

func (*SQLDBResultSet) IsColTypesRegistered

func (w *SQLDBResultSet) IsColTypesRegistered() bool

IsColTypesRegistered checks whether the column types for a particular taskName's structure is registered in the backend.

func (*SQLDBResultSet) RegisterColTypes

func (w *SQLDBResultSet) RegisterColTypes(cols []string, colTypes []*sql.ColumnType) error

RegisterColTypes registers the column types of a particular taskName's result set. Internally, it translates sql types into the simpler sqlDB (SQLite 3) types, creates a CREATE TABLE() schema for the results table with the structure of the particular taskName, and caches it be used for every subsequent result db creation and population. This should only be called once for each kind of taskName.

func (*SQLDBResultSet) WriteCols

func (w *SQLDBResultSet) WriteCols(cols []string) error

WriteCols writes the column (headers) of a result set to the backend. Internally, it creates a sqlDB database and creates a results table based on the schema RegisterColTypes() would've created and cached. This should only be called once on a ResultWriter instance.

func (*SQLDBResultSet) WriteRow

func (w *SQLDBResultSet) WriteRow(row []interface{}) error

WriteRow writes an individual row from a result set to the backend. Internally, it INSERT()s the given row into the sqlDB results table.

type SqlDB

type SqlDB struct {
	// contains filtered or unexported fields
}

SqlDB represents the SqlDB backend.

func NewSQLBackend

func NewSQLBackend(db *sql.DB, opt Opt, lo *slog.Logger) (*SqlDB, error)

NewSQLBackend returns a new sqlDB result backend instance.

func (*SqlDB) NewResultSet

func (s *SqlDB) NewResultSet(jobID, taskName string, ttl time.Duration) (models.ResultSet, error)

NewResultSet returns a new instance of an sqlDB result writer. A new instance should be acquired for every individual job result to be written to the backend and then thrown away.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL