fireboltgosdk

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 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
	username := ""
	password := ""
	databaseName := ""
	dsn := fmt.Sprintf("firebolt://%s:%s@%s", username, password, databaseName)

	// 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 (
	UsernamePasswordURLSuffix    = "/auth/v1/login"
	ServiceAccountLoginURLSuffix = "/auth/v1/token"
	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"
)

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 Client

type Client struct {
	Username    string
	Password    string
	ApiEndpoint string
	UserAgent   string
}

func Authenticate

func Authenticate(username, password, apiEndpoint string) (*Client, error)

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

func (*Client) GetAccountIdByName

func (c *Client) GetAccountIdByName(ctx context.Context, accountName string) (string, error)

GetAccountIdByName returns account ID based on account name

func (*Client) GetDefaultAccountId

func (c *Client) GetDefaultAccountId(ctx context.Context) (string, error)

GetDefaultAccount returns an id of the default account

func (*Client) GetEngineIdByName

func (c *Client) GetEngineIdByName(ctx context.Context, engineName string, accountId string) (string, error)

GetEngineIdByName returns engineId based on engineName and accountId

func (*Client) GetEngineUrlByDatabase

func (c *Client) GetEngineUrlByDatabase(ctx context.Context, databaseName string, accountId string) (string, error)

GetEngineUrlByDatabase return URL of the default engine based on databaseName and accountName

func (*Client) GetEngineUrlById

func (c *Client) GetEngineUrlById(ctx context.Context, engineId string, accountId string) (string, error)

GetEngineUrlById returns engine url based on engineId and accountId

func (*Client) GetEngineUrlByName

func (c *Client) GetEngineUrlByName(ctx context.Context, engineName string, accountId string) (string, error)

GetEngineUrlByName return engine URL based on engineName and accountName

func (*Client) Query

func (c *Client) 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 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