fireboltgosdk

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 24 Imported by: 1

README

Firebolt GO SDK

Nightly code check Code quality checks Integration tests Coverage

Firebolt GO driver is an implementation of database/sql/driver.

Installation
go get github.com/firebolt-db/firebolt-go-sdk
Example

Here is an example of establishing a connection and executing a simple select query. For it to run successfully, you have to specify your credentials, and have a default engine up and running.

package main

import (
	"database/sql"
	"fmt"
	// we need to import firebolt-go-sdk, so it is able to register its driver
	_ "github.com/firebolt-db/firebolt-go-sdk"
)

func main() {

	// constructing a dsn string, you need to set your credentials
	clientId := ""
	clientSecret := ""
	accountName := ""
	databaseName := ""
	dsn := fmt.Sprintf("firebolt:///%s?account_name=%s&client_id=%s&client_secret=%s", databaseName, accountName, clientId, clientSecret)

	// opening the firebolt driver
	db, err := sql.Open("firebolt", dsn)
	if err != nil {
		fmt.Println("error during opening a driver: %v", err)
	}

	// executing a simple select query
	rows, err := db.Query("SELECT 1 UNION SELECT 2")
	if err != nil {
		fmt.Println("error during select query: %v", err)
	}

	// iterating over the resulting rows
	defer rows.Close()
	for rows.Next() {
		var id int
		if err := rows.Scan(&id); err != nil {
			fmt.Println("error during scan: %v", err)
		}
		fmt.Println(id)
	}
}
DSN (Data source name)

All information for the connection should be specified using the DSN string. The firebolt dsn string has the following format:

firebolt://[/database]?account_name=account_name&client_id=client_id&client_secret=client_secret[&engine=engine]
  • client_id - credentials client id.
  • client_secret - credentials client secret.
  • account_name - the name of Firebolt account to log in to.
  • database - (optional) the name of the database to connect to.
  • engine - (optional) the name of the engine to run SQL on.
Limitations

Although, all interfaces are available, not all of them are implemented or could be implemented:

  • driver.Result is a dummy implementation and doesn't return the real result values.

Documentation

Index

Constants

View Source
const (
	ContentTypeForm = "application/x-www-form-urlencoded"
	ContentTypeJSON = "application/json"
)
View Source
const (
	ServiceAccountLoginURLSuffix = "/oauth/token"
	EngineUrlByAccountName       = "/web/v3/account/%s/engineUrl"
	AccountInfoByAccountName     = "/web/v3/account/%s/resolve"
	//API v0
	UsernamePasswordURLSuffix  = "/auth/v1/login"
	DefaultAccountURL          = "/iam/v2/account"
	AccountIdByNameURL         = "/iam/v2/accounts:getIdByName"
	EngineIdByNameURL          = "/core/v1/accounts/%s/engines:getIdByName"
	EngineByIdURL              = "/core/v1/accounts/%s/engines/%s"
	EngineUrlByDatabaseNameURL = "/core/v1/accounts/%s/engines:getURLByDatabaseName"
)
View Source
const AuthAudienceValue = "https://api.firebolt.io"

Variables

This section is empty.

Functions

func ConstructNestedError

func ConstructNestedError(message string, err error) error

func ConstructUserAgentString

func ConstructUserAgentString() (ua_string string)

ConstructUserAgentString returns a string with go, GoSDK and os type and versions additionally user can set "FIREBOLT_GO_DRIVERS" and "FIREBOLT_GO_CLIENTS" env variable, and they will be concatenated with the final user-agent string

func GetHostNameURL

func GetHostNameURL() string

GetHostNameURL returns a hostname url, either default or overwritten with the environment variable

func ParseDSNString

func ParseDSNString(dsn string) (*fireboltSettings, error)

ParseDSNString parses a dsn in a format: firebolt://username:password@db_name[/engine_name][?account_name=organization] returns a settings object where all parsed values are populated returns an error if required fields couldn't be parsed or if after parsing some characters were left unparsed

func SplitStatements added in v0.0.6

func SplitStatements(sql string) ([]string, error)

SplitStatements split multiple statements into a list of statements

func WithClientParams added in v1.1.0

func WithClientParams(accountID string, token string, userAgent string) driverOption

WithClientParams defines client parameters for the driver

func WithDatabaseName added in v1.1.0

func WithDatabaseName(databaseName string) driverOption

WithDatabaseName defines database name for the driver

func WithEngineUrl added in v1.1.0

func WithEngineUrl(engineUrl string) driverOption

WithEngineUrl defines engine url for the driver

Types

type AuthenticationResponse

type AuthenticationResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int    `json:"expires_in"`
	TokenType    string `json:"token_type"`
	Scope        string `json:"scope"`
}

type BaseClient added in v1.0.0

type BaseClient struct {
	ClientID     string
	ClientSecret string
	AccountID    string
	ApiEndpoint  string
	UserAgent    string
	// contains filtered or unexported fields
}

func (*BaseClient) Query added in v1.0.0

func (c *BaseClient) Query(ctx context.Context, engineUrl, query string, parameters map[string]string, control connectionControl) (*QueryResponse, error)

Query sends a query to the engine URL and populates queryResponse, if query was successful

type Client

type Client interface {
	GetConnectionParameters(ctx context.Context, engineName string, databaseName string) (string, map[string]string, error)
	Query(ctx context.Context, engineUrl, query string, parameters map[string]string, control connectionControl) (*QueryResponse, error)
}

func Authenticate

func Authenticate(settings *fireboltSettings, apiEndpoint string) (Client, error)

Authenticate sends an authentication request, and returns a newly constructed client object

type ClientImpl added in v1.0.0

type ClientImpl struct {
	ConnectedToSystemEngine bool
	SystemEngineURL         string
	AccountVersion          int
	BaseClient
}

func MakeClient added in v1.0.0

func MakeClient(settings *fireboltSettings, apiEndpoint string) (*ClientImpl, error)

func (*ClientImpl) GetConnectionParameters added in v1.1.0

func (c *ClientImpl) GetConnectionParameters(ctx context.Context, engineName, databaseName string) (string, map[string]string, error)

GetConnectionParameters returns engine URL and parameters based on engineName and databaseName

type ClientImplV0 added in v1.0.0

type ClientImplV0 struct {
	BaseClient
}

func MakeClientV0 added in v1.0.0

func MakeClientV0(settings *fireboltSettings, apiEndpoint string) (*ClientImplV0, error)

func (*ClientImplV0) GetConnectionParameters added in v1.1.0

func (c *ClientImplV0) GetConnectionParameters(ctx context.Context, engineName, databaseName string) (string, map[string]string, error)

GetConnectionParameters returns engine URL and engine name based on engineName and accountId

type Column

type Column struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type FireboltConnector added in v1.1.0

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

FireboltConnector is an intermediate type between a Connection and a Driver which stores session data

func FireboltConnectorWithOptions added in v1.1.0

func FireboltConnectorWithOptions(opts ...driverOption) *FireboltConnector

FireboltConnectorWithOptions builds a custom connector

func (*FireboltConnector) Connect added in v1.1.0

func (c *FireboltConnector) Connect(ctx context.Context) (driver.Conn, error)

Connect returns a connection to the database

func (*FireboltConnector) Driver added in v1.1.0

func (c *FireboltConnector) Driver() driver.Driver

Driver returns the underlying driver of the Connector

type FireboltDriver

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

func (*FireboltDriver) Open

func (d *FireboltDriver) Open(dsn string) (driver.Conn, error)

Open parses the dsn string, and if correct tries to establish a connection

func (*FireboltDriver) OpenConnector added in v1.1.0

func (d *FireboltDriver) OpenConnector(dsn string) (driver.Connector, error)

type FireboltResult

type FireboltResult struct {
}

func (FireboltResult) LastInsertId

func (r FireboltResult) LastInsertId() (int64, error)

LastInsertId returns last inserted ID, not supported by firebolt

func (FireboltResult) RowsAffected

func (r FireboltResult) RowsAffected() (int64, error)

RowsAffected returns a number of affected rows, not supported by firebolt

type QueryResponse

type QueryResponse struct {
	Query      interface{}     `json:"query"`
	Meta       []Column        `json:"meta"`
	Data       [][]interface{} `json:"data"`
	Rows       int             `json:"rows"`
	Statistics interface{}     `json:"statistics"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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