mysql

package
v1.38.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2025 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Copyright 2025 SGNL.ai, Inc.

Copyright 2025 SGNL.ai, Inc.

Copyright 2025 SGNL.ai, Inc.

Copyright 2025 SGNL.ai, Inc.

Copyright 2025 SGNL.ai, Inc.

Copyright 2025 SGNL.ai, Inc.

Copyright 2025 SGNL.ai, Inc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAdapter

func NewAdapter(client Client) framework.Adapter[Config]

NewAdapter instantiates a new Adapter.

func ParseResponse

func ParseResponse(rows *sql.Rows, request *Request) ([]map[string]any, *framework.Error)

nolint: lll

Types

type Adapter

type Adapter struct {
	MySQLClient Client
}

Adapter implements the framework.Adapter interface to query pages of objects from datasources.

func (*Adapter) GetPage

func (a *Adapter) GetPage(ctx context.Context, request *framework.Request[Config]) framework.Response

GetPage is called by SGNL's ingestion service to query a page of objects from a datasource.

func (*Adapter) RequestPageFromDatasource

func (a *Adapter) RequestPageFromDatasource(
	ctx context.Context, request *framework.Request[Config],
) framework.Response

RequestPageFromDatasource requests a page of objects from a datasource.

func (*Adapter) ValidateGetPageRequest

func (a *Adapter) ValidateGetPageRequest(ctx context.Context, request *framework.Request[Config]) *framework.Error

ValidateGetPageRequest validates the fields of the GetPage Request.

type Client

type Client interface {
	GetPage(ctx context.Context, request *Request) (*Response, *framework.Error)
}

func NewClient

func NewClient(client SQLClient) Client

NewClient returns a Client to query the datasource.

type Config

type Config struct {
	*config.CommonConfig

	// MySQL database to connect to.
	Database string `json:"database,omitempty"`
}

Config is the configuration passed in each GetPage calls to the adapter. Adapter configuration example: nolint: godot

{
    "requestTimeoutSeconds": 10,
    "localTimeZoneOffset": 43200,
    "database": "sgnl"
}

func (*Config) Validate

func (c *Config) Validate(_ context.Context) error

ValidateConfig validates that a Config received in a GetPage call is valid.

type Datasource

type Datasource struct {
	Client SQLClient
}

func (*Datasource) GetPage

func (d *Datasource) GetPage(_ context.Context, request *Request) (*Response, *framework.Error)

type DefaultSQLClient

type DefaultSQLClient struct {
	DB *sql.DB
}

func NewDefaultSQLClient

func NewDefaultSQLClient() *DefaultSQLClient

func (*DefaultSQLClient) Connect

func (c *DefaultSQLClient) Connect(dataSourceName string) error

Connect opens a database connection to the provided datasource. The database is safe for concurrent use by multiple goroutines and maintains its own pool of idle connections. Thus, the Connect function should be called just once.

This must be called before calling Query, else that function call will fail.

func (*DefaultSQLClient) Query

func (c *DefaultSQLClient) Query(query string, args ...any) (*sql.Rows, error)

Query prepares a statement and queries a connected database with the provided query.

Returns an error if the query fails or if there is no currently open database connection.

type MockSQLClient

type MockSQLClient struct {
	DB   *sql.DB
	Mock sqlmock.Sqlmock
}

func NewMockSQLClient

func NewMockSQLClient() *MockSQLClient

func (*MockSQLClient) Connect

func (c *MockSQLClient) Connect(datasourceName string) error

func (*MockSQLClient) Query

func (c *MockSQLClient) Query(query string, args ...any) (*sql.Rows, error)

nolint: lll

type Request

type Request struct {
	// BaseURL is the Base URL of the datasource to query.
	BaseURL string

	// Username is the user name used to authenticate with the MySQL instance.
	Username string

	// Password is the password used to authenticate with the MySQL instance.
	Password string

	// PageSize is the maximum number of objects to return from the entity.
	PageSize int64

	// EntityExternalID is the external ID of the entity.
	// The external ID should match the table name on the MySQL database.
	EntityExternalID string

	// Cursor identifies the first object of the page to return, as returned by
	// the last request for the entity.
	// nil in the request for the first page.
	Cursor *int64

	// MySQL database to connect to.
	Database string

	// UniqueAttributeExternalID is used to specify the unique ID that should be used when ordering results from
	// the specified table.
	UniqueAttributeExternalID string
}

Request is a request to a MySQL database.

type Response

type Response struct {
	// StatusCode is an HTTP status code.
	StatusCode int

	// RetryAfterHeader is the Retry-After response HTTP header, if set.
	RetryAfterHeader string

	// Objects is the list of objects returned from the datasource.
	// May be empty.
	Objects []map[string]any

	// NextCursor is the cursor that identifies the first object of the next page.
	// nil if this is the last page in this full sync.
	NextCursor *int64
}

Response is a response returned by the datasource.

type SQLClient

type SQLClient interface {
	Connect(dataSourceName string) error
	Query(query string, args ...any) (*sql.Rows, error)
}

type SQLColumnTypes

type SQLColumnTypes map[string]string

type SQLRow

type SQLRow map[string]string

type SQLRows

type SQLRows []SQLRow

Jump to

Keyboard shortcuts

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