fireboltgosdk

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: Apache-2.0 Imports: 24 Imported by: 5

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://username:password@database[/engine_name][?account_name=account_name]
  • username - the email address you use to log in to Firebolt.
  • password - your password to log in to Firebolt.
  • database - the Firebolt database to connect to.
  • engine_url - the url of the engine to run SQL on. Alternatively engine_name could be specified here, in this case, the engine url will be retrieved automatically. If omitted, the default engine for the database is used.
  • account_name - the Firebolt account to log in to.

You need to escape some characters with double backslashes, e.g. if you have a @ sign in the password, you should write \\@.

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.
  • Both Exec and Query accept arguments for prepared statements, but aren't implemented, and will panic

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"
	AccountIdByAccountName       = "/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

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, databaseName, query string, setStatements map[string]string) (*QueryResponse, error)

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

type Client

type Client interface {
	GetEngineUrlAndDB(ctx context.Context, engineName string, accountId string) (string, string, error)
	Query(ctx context.Context, engineUrl, databaseName, query string, setStatements map[string]string) (*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
	BaseClient
}

func MakeClient added in v1.0.0

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

func (*ClientImpl) GetEngineUrlAndDB added in v1.0.0

func (c *ClientImpl) GetEngineUrlAndDB(ctx context.Context, engineName, databaseName string) (string, string, error)

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

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) GetEngineUrlAndDB added in v1.0.0

func (c *ClientImplV0) GetEngineUrlAndDB(ctx context.Context, engineName, databaseName string) (string, string, error)

GetEngineUrlAndDB 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 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

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