Documentation ¶
Index ¶
- Constants
- Variables
- func Array(v interface{}) driver.Valuer
- func DBCallerPrettyfier(frame *runtime.Frame) (string, string)
- func Date(t time.Time) driver.Valuer
- func Decimal128(v interface{}, s int32) driver.Valuer
- func Decimal32(v interface{}, s int32) driver.Valuer
- func Decimal64(v interface{}, s int32) driver.Valuer
- func DeregisterTLSConfig(key string)
- func IP(i net.IP) driver.Valuer
- func IsAuthFailed(err error) bool
- func IsNotFound(err error) bool
- func IsProxyErr(err error) bool
- func Map(v interface{}) driver.Valuer
- func NewAPIError(hint string, status int, respBuf []byte) error
- func NewDefaultCSVFormatOptions() map[string]string
- func NewDefaultCopyOptions() map[string]string
- func RegisterTLSConfig(key string, config *tls.Config) error
- func SetLogger(inLogger *DBLogger)
- func Tuple(v interface{}) driver.Valuer
- func UInt64(u uint64) driver.Valuer
- type APIClient
- func (c *APIClient) DoQuery(ctx context.Context, query string, args []driver.Value) (*QueryResponse, error)
- func (c *APIClient) GetPresignedURL(ctx context.Context, stage *StageLocation) (*PresignedResponse, error)
- func (c *APIClient) InsertWithStage(ctx context.Context, sql string, stage *StageLocation, ...) (*QueryResponse, error)
- func (c *APIClient) KillQuery(ctx context.Context, killURI string) error
- func (c *APIClient) QueryPage(ctx context.Context, nextURI string) (*QueryResponse, error)
- func (c *APIClient) QuerySingle(ctx context.Context, query string, args []driver.Value) (*QueryResponse, error)
- func (c *APIClient) QuerySync(ctx context.Context, query string, args []driver.Value, ...) error
- func (c *APIClient) UploadToStage(ctx context.Context, stage *StageLocation, input *bufio.Reader, size int64) error
- func (c *APIClient) UploadToStageByAPI(ctx context.Context, stage *StageLocation, input *bufio.Reader, size int64) error
- func (c *APIClient) UploadToStageByPresignURL(ctx context.Context, stage *StageLocation, input *bufio.Reader, size int64) error
- func (c *APIClient) WaitForQuery(ctx context.Context, result *QueryResponse) (*QueryResponse, error)
- type APIError
- type APIErrorResponseBody
- type AccessTokenLoader
- type AuthMethod
- type Config
- type DBLogger
- type DataField
- type DataParser
- type DataParserOptions
- type DatabendConn
- func (dc *DatabendConn) Begin() (driver.Tx, error)
- func (dc *DatabendConn) Close() error
- func (dc *DatabendConn) Commit() (err error)
- func (dc *DatabendConn) Exec(query string, args []driver.Value) (driver.Result, error)
- func (dc *DatabendConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
- func (dc *DatabendConn) Prepare(query string) (driver.Stmt, error)
- func (dc *DatabendConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)
- func (dc *DatabendConn) Query(query string, args []driver.Value) (driver.Rows, error)
- func (dc *DatabendConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
- func (dc *DatabendConn) Rollback() error
- type DatabendDriver
- type Error
- type FileAccessTokenData
- type FileAccessTokenLoader
- type PaginationConfig
- type PresignedResponse
- type QueryError
- type QueryProgress
- type QueryRequest
- type QueryResponse
- type QueryStats
- type QueryStatsTracker
- type SessionConfig
- type StageAttachmentConfig
- type StageLocation
- type StaticAccessTokenLoader
- type TypeDesc
Constants ¶
const ( DatabendTenantHeader = "X-DATABEND-TENANT" DatabendWarehouseHeader = "X-DATABEND-WAREHOUSE" Authorization = "Authorization" WarehouseRoute = "X-DATABEND-ROUTE" UserAgent = "User-Agent" )
const DBSessionIDKey contextKey = "LOG_SESSION_ID"
DBSessionIDKey is context key of session id
const SFSessionUserKey contextKey = "LOG_USER"
SFSessionUserKey is context key of user id of a session
const (
SSL_MODE_DISABLE = "disable"
)
Variables ¶
var ( ProvisionWarehouseTimeout = "ProvisionWarehouseTimeout" ErrDoRequest = errors.New("DoReqeustFailed") ErrReadResponse = errors.New("ReadResponseFailed") )
var ( ErrPlaceholderCount = errors.New("databend: wrong placeholder count") ErrNoLastInsertID = errors.New("no LastInsertId available") ErrNoRowsAffected = errors.New("no RowsAffected available") )
var LogKeys = [...]contextKey{DBSessionIDKey, SFSessionUserKey}
LogKeys these keys in context should be included in logging messages when using logger.WithContext
Functions ¶
func Array ¶
Array wraps slice or array into driver.Valuer interface to allow pass through it from database/sql
func DBCallerPrettyfier ¶
DBCallerPrettyfier to provide base file name and function name from calling frame used in SFLogger
func Decimal128 ¶
Decimal128 converts value to Decimal128 of precision S. The value can be a number or a string. The S (scale) parameter specifies the number of decimal places.
func Decimal32 ¶
Decimal32 converts value to Decimal32 of precision S. The value can be a number or a string. The S (scale) parameter specifies the number of decimal places.
func Decimal64 ¶
Decimal64 converts value to Decimal64 of precision S. The value can be a number or a string. The S (scale) parameter specifies the number of decimal places.
func DeregisterTLSConfig ¶
func DeregisterTLSConfig(key string)
DeregisterTLSConfig removes the tls.Config associated with key.
func IsAuthFailed ¶ added in v0.1.1
func IsNotFound ¶ added in v0.1.1
func IsProxyErr ¶ added in v0.1.1
func NewDefaultCSVFormatOptions ¶ added in v0.3.7
func NewDefaultCopyOptions ¶ added in v0.3.7
func RegisterTLSConfig ¶
RegisterTLSConfig registers a custom tls.Config to be used with sql.Open.
func SetLogger ¶
func SetLogger(inLogger *DBLogger)
SetLogger set a new logger of SFLogger interface for godatabend
Types ¶
type APIClient ¶
type APIClient struct { WaitTimeSeconds int64 MaxRowsInBuffer int64 MaxRowsPerPage int64 PresignedURLDisabled bool // contains filtered or unexported fields }
func NewAPIClientFromConfig ¶ added in v0.3.2
func (*APIClient) GetPresignedURL ¶ added in v0.3.12
func (c *APIClient) GetPresignedURL(ctx context.Context, stage *StageLocation) (*PresignedResponse, error)
func (*APIClient) InsertWithStage ¶ added in v0.3.6
func (c *APIClient) InsertWithStage(ctx context.Context, sql string, stage *StageLocation, fileFormatOptions, copyOptions map[string]string) (*QueryResponse, error)
func (*APIClient) QuerySingle ¶ added in v0.3.6
func (*APIClient) UploadToStage ¶ added in v0.3.6
func (*APIClient) UploadToStageByAPI ¶ added in v0.3.12
func (*APIClient) UploadToStageByPresignURL ¶ added in v0.0.4
func (*APIClient) WaitForQuery ¶ added in v0.3.12
func (c *APIClient) WaitForQuery(ctx context.Context, result *QueryResponse) (*QueryResponse, error)
type APIError ¶ added in v0.1.1
type APIError struct { RespBody APIErrorResponseBody RespText string StatusCode int Hint string }
type APIErrorResponseBody ¶ added in v0.1.1
func RespBody ¶ added in v0.1.1
func RespBody(err error) APIErrorResponseBody
type AccessTokenLoader ¶ added in v0.3.4
type AccessTokenLoader interface { // LoadAccessToken is called whenever a new request is made to the server. LoadAccessToken(ctx context.Context, forceRotate bool) (string, error) }
AccessTokenLoader is used on Bearer authentication. The token may have a limited lifetime, you can rotate your token by this interface.
type AuthMethod ¶ added in v0.3.4
type AuthMethod string
const ( AuthMethodUserPassword AuthMethod = "userPassword" AuthMethodAccessToken AuthMethod = "accessToken" )
type Config ¶
type Config struct { Tenant string // Tenant Warehouse string // Warehouse User string // Username Password string // Password (requires User) Database string // Database name Role string // Role is the databend role you want to use for the current connection AccessToken string AccessTokenFile string // path to file containing access token, it can be used to rotate access token AccessTokenLoader AccessTokenLoader Host string Timeout time.Duration /* Pagination params: WaitTimeSecs, MaxRowsInBuffer, MaxRowsPerPage Pagination: critical conditions for each HTTP request to return (before all remaining result is ready to return) Related docs:https://databend.rs/doc/integrations/api/rest#query-request */ WaitTimeSecs int64 MaxRowsInBuffer int64 MaxRowsPerPage int64 Location *time.Location Debug bool GzipCompression bool Params map[string]string TLSConfig string SSLMode string // track the progress of query execution StatsTracker QueryStatsTracker // used on the storage which does not support presigned url like HDFS, local fs PresignedURLDisabled bool }
Config is a set of configuration parameters
type DBLogger ¶
type DBLogger interface { rlog.Ext1FieldLogger SetLogLevel(level string) error WithContext(ctx context.Context) *rlog.Entry SetOutput(output io.Writer) }
DBLogger Databend logger interface to expose FieldLogger defined in logrus
func CreateDefaultLogger ¶
func CreateDefaultLogger() DBLogger
CreateDefaultLogger return a new instance of SFLogger with default config
type DataParser ¶
DataParser implements parsing of a driver value and reporting its type.
func NewDataParser ¶
func NewDataParser(t *TypeDesc, opt *DataParserOptions) (DataParser, error)
NewDataParser creates a new DataParser based on the given TypeDesc.
type DataParserOptions ¶
type DataParserOptions struct { // Location describes default location for DateTime and Date field without Timezone argument. Location *time.Location // UseDBLocation if false: always use Location, ignore DateTime argument. UseDBLocation bool }
DataParserOptions describes DataParser options. Ex.: Fields Location and UseDBLocation specify timezone options.
type DatabendConn ¶
type DatabendConn struct {
// contains filtered or unexported fields
}
func (*DatabendConn) Close ¶
func (dc *DatabendConn) Close() error
Close invalidates and potentially stops any current prepared statements and transactions, marking this connection as no longer in use.
func (*DatabendConn) Commit ¶
func (dc *DatabendConn) Commit() (err error)
Commit applies prepared statement if it exists
func (*DatabendConn) ExecContext ¶ added in v0.0.9
func (dc *DatabendConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
func (*DatabendConn) PrepareContext ¶
func (*DatabendConn) QueryContext ¶ added in v0.0.9
func (dc *DatabendConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
func (*DatabendConn) Rollback ¶
func (dc *DatabendConn) Rollback() error
Rollback cleans prepared statement
type DatabendDriver ¶
type DatabendDriver struct {
// contains filtered or unexported fields
}
DatabendDriver is a context of Go Driver
func (DatabendDriver) Open ¶
func (d DatabendDriver) Open(dsn string) (driver.Conn, error)
Open creates a new connection.
func (DatabendDriver) OpenWithConfig ¶
OpenWithConfig creates a new connection with the given Config.
type FileAccessTokenData ¶ added in v0.3.4
type FileAccessTokenData struct {
AccessToken string `toml:"access_token"`
}
type FileAccessTokenLoader ¶ added in v0.3.4
type FileAccessTokenLoader struct {
// contains filtered or unexported fields
}
func NewFileAccessTokenLoader ¶ added in v0.3.4
func NewFileAccessTokenLoader(path string) *FileAccessTokenLoader
func (*FileAccessTokenLoader) LoadAccessToken ¶ added in v0.3.4
func (l *FileAccessTokenLoader) LoadAccessToken(ctx context.Context, forceRotate bool) (string, error)
try decode as toml, if not toml, return the plain key content
type PaginationConfig ¶ added in v0.3.4
type PresignedResponse ¶ added in v0.3.6
type QueryError ¶
type QueryError struct { Code int `json:"code"` Message string `json:"message"` Kind string `json:"kind"` }
func (*QueryError) Error ¶ added in v0.1.0
func (e *QueryError) Error() string
type QueryProgress ¶
type QueryRequest ¶
type QueryRequest struct { Session *SessionConfig `json:"session,omitempty"` SQL string `json:"sql"` Pagination *PaginationConfig `json:"pagination,omitempty"` StageAttachment *StageAttachmentConfig `json:"stage_attachment,omitempty"` }
type QueryResponse ¶
type QueryResponse struct { ID string `json:"id"` SessionID string `json:"session_id"` Session *SessionConfig `json:"session"` Schema []DataField `json:"schema"` Data [][]string `json:"data"` State string `json:"state"` Error *QueryError `json:"error"` Stats QueryStats `json:"stats"` // TODO: Affect rows StatsURI string `json:"stats_uri"` FinalURI string `json:"final_uri"` NextURI string `json:"next_uri"` KillURI string `json:"kill_uri"` }
type QueryStats ¶
type QueryStats struct { RunningTimeMS float64 `json:"running_time_ms"` ScanProgress QueryProgress `json:"scan_progress"` WriteProgress QueryProgress `json:"write_progress"` ResultProgress QueryProgress `json:"result_progress"` }
type QueryStatsTracker ¶ added in v0.4.4
type QueryStatsTracker func(queryID string, stats *QueryStats)
QueryStatsTracker is a function that will be called when query stats are updated, it can be specified in the Config struct.
type SessionConfig ¶ added in v0.3.4
type StageAttachmentConfig ¶ added in v0.3.6
type StageLocation ¶ added in v0.3.7
func (*StageLocation) String ¶ added in v0.3.7
func (sl *StageLocation) String() string
type StaticAccessTokenLoader ¶ added in v0.3.4
type StaticAccessTokenLoader struct {
AccessToken string
}
func NewStaticAccessTokenLoader ¶ added in v0.3.4
func NewStaticAccessTokenLoader(accessToken string) *StaticAccessTokenLoader
func (*StaticAccessTokenLoader) LoadAccessToken ¶ added in v0.3.4
type TypeDesc ¶
TypeDesc describes a (possibly nested) data type returned by Databend.
func ParseTypeDesc ¶
ParseTypeDesc parses the type description that Databend provides.
The grammar is quite simple:
desc name name() name(args) args desc desc, args
Examples:
String Nullable(Nothing) Array(Tuple(Tuple(String, String), Tuple(String, UInt64)))