Documentation ¶
Index ¶
- Constants
- Variables
- func Encode(w io.Writer, item interface{}, indent int) error
- func LoadConfig(cfg *Config) error
- func LoadConfigFile(fname, profile string, cfg *Config) error
- func LoadConfigProfile(profile string, cfg *Config) error
- func LoadConfigString(source, profile string, cfg *Config) error
- func Print(item interface{}, indent int) error
- type AccessToken
- type AccessTokenHandler
- type ArrowRelation
- type CSVOptions
- func (opts *CSVOptions) WithDelim(delim rune) *CSVOptions
- func (opts *CSVOptions) WithEscapeChar(escapeChar rune) *CSVOptions
- func (opts *CSVOptions) WithHeaderRow(headerRow int) *CSVOptions
- func (opts *CSVOptions) WithQuoteChar(quoteChar rune) *CSVOptions
- func (opts *CSVOptions) WithSchema(schema map[string]string) *CSVOptions
- type Client
- func (c *Client) AccessToken() (string, error)
- func (c *Client) CancelTransaction(id string) (*TransactionAsyncCancelResponse, error)
- func (c *Client) CloneDatabase(database, source string) (*Database, error)
- func (c *Client) Context() context.Context
- func (c *Client) CreateDatabase(database string) (*Database, error)
- func (c *Client) CreateEngine(engine, size string) (*Engine, error)
- func (c *Client) CreateEngineAsync(engine, size string) (*Engine, error)
- func (c *Client) CreateOAuthClient(name string, perms []string) (*OAuthClientExtra, error)
- func (c *Client) CreateUser(email string, roles []string) (*User, error)
- func (c *Client) Delete(path string, args url.Values, data, result interface{}) error
- func (c *Client) DeleteDatabase(database string) error
- func (c *Client) DeleteEngine(engine string) error
- func (c *Client) DeleteEngineAsync(engine string) (*Engine, error)
- func (c *Client) DeleteModel(database, engine, name string) (*TransactionResult, error)
- func (c *Client) DeleteModels(database, engine string, models []string) (*TransactionResult, error)
- func (c *Client) DeleteOAuthClient(id string) (*DeleteOAuthClientResponse, error)
- func (c *Client) DeleteUser(id string) (*DeleteUserResponse, error)
- func (c *Client) DisableUser(id string) (*User, error)
- func (c *Client) Do(req *http.Request) (*http.Response, error)
- func (c *Client) EnableUser(id string) (*User, error)
- func (c *Client) Execute(database, engine, source string, inputs map[string]string, readonly bool) (*TransactionAsyncResult, error)
- func (c *Client) ExecuteAsync(database, engine, source string, inputs map[string]string, readonly bool) (*TransactionAsyncResult, error)
- func (c *Client) ExecuteV1(database, engine, source string, inputs map[string]string, readonly bool) (*TransactionResult, error)
- func (c *Client) FindOAuthClient(name string) (*OAuthClient, error)
- func (c *Client) FindUser(email string) (*User, error)
- func (c *Client) Get(path string, args url.Values, result interface{}) error
- func (c *Client) GetAccessToken(creds *ClientCredentials) (*AccessToken, error)
- func (c *Client) GetDatabase(database string) (*Database, error)
- func (c *Client) GetEngine(engine string) (*Engine, error)
- func (c *Client) GetModel(database, engine, model string) (*Model, error)
- func (c *Client) GetOAuthClient(id string) (*OAuthClientExtra, error)
- func (c *Client) GetTransaction(id string) (*TransactionAsyncSingleResponse, error)
- func (c *Client) GetTransactionMetadata(id string) ([]TransactionAsyncMetadataResponse, error)
- func (c *Client) GetTransactionProblems(id string) ([]interface{}, error)
- func (c *Client) GetTransactionResults(id string) ([]ArrowRelation, error)
- func (c *Client) GetTransactions() (*TransactionAsyncMultipleResponses, error)
- func (c *Client) GetUser(id string) (*User, error)
- func (c *Client) ListDatabases(filters ...interface{}) ([]Database, error)
- func (c *Client) ListEDBs(database, engine string) ([]EDB, error)
- func (c *Client) ListEngines(filters ...interface{}) ([]Engine, error)
- func (c *Client) ListModelNames(database, engine string) ([]string, error)
- func (c *Client) ListModels(database, engine string) ([]Model, error)
- func (c *Client) ListOAuthClients() ([]OAuthClient, error)
- func (c *Client) ListUsers() ([]User, error)
- func (c *Client) LoadCSV(database, engine, relation string, r io.Reader, opts *CSVOptions) (*TransactionResult, error)
- func (c *Client) LoadJSON(database, engine, relation string, r io.Reader) (*TransactionResult, error)
- func (c *Client) LoadModel(database, engine, name string, r io.Reader) (*TransactionResult, error)
- func (c *Client) LoadModels(database, engine string, models map[string]io.Reader) (*TransactionResult, error)
- func (c *Client) Patch(path string, args url.Values, data, result interface{}) error
- func (c *Client) Post(path string, args url.Values, data, result interface{}) error
- func (c *Client) Put(path string, args url.Values, data, result interface{}) error
- func (c *Client) SetAccessTokenHandler(handler AccessTokenHandler)
- func (c *Client) SetContext(ctx context.Context)
- func (c *Client) UpdateUser(id string, req UpdateUserRequest) (*User, error)
- func (c *Client) Url(path string) string
- type ClientCredentials
- type ClientCredentialsHandler
- type ClientOptions
- type ClientProblem
- type Config
- type Database
- type DbAction
- type DeleteEngineStatus
- type DeleteOAuthClientResponse
- type DeleteUserResponse
- type EDB
- type Engine
- type HTTPError
- type IntegrityConstraintViolation
- type Model
- type NopAccessTokenHandler
- type OAuthClient
- type OAuthClientExtra
- type RelKey
- type Relation
- type Showable
- type Source
- type Transaction
- type TransactionAsync
- type TransactionAsyncCancelResponse
- type TransactionAsyncFile
- type TransactionAsyncMetadataResponse
- type TransactionAsyncMultipleResponses
- type TransactionAsyncResponse
- type TransactionAsyncResult
- type TransactionAsyncSingleResponse
- type TransactionResult
- type UpdateUserRequest
- type User
Constants ¶
const ( PathDatabase = "/database" PathEngine = "/compute" PathOAuthClients = "/oauth-clients" PathTransaction = "/transaction" PathTransactions = "/transactions" PathUsers = "/users" )
const DefaultConfigFile = "~/.rai/config"
const DefaultConfigProfile = "default"
const DefaultHost = "azure.relationalai.com"
const DefaultPort = "443"
const DefaultRegion = "us-east"
const DefaultScheme = "https"
const Version = "0.0.1"
Variables ¶
var ErrMissingFilterValue = errors.New("missing filter value")
var ErrNotFound = newHTTPError(http.StatusNotFound, "")
Functions ¶
func LoadConfig ¶
Load settings from the default profile of the default config file.
func LoadConfigFile ¶
Load settings from the given profile of the named config file.
func LoadConfigProfile ¶
Load settings from the given profile in the default config file.
func LoadConfigString ¶
Load settings from the given profile of the provided config source.
Types ¶
type AccessToken ¶
type AccessToken struct { Token string `json:"access_token"` Scope string `json:"scope"` ExpiresIn int `json:"expires_in"` // token lifetime in seconds CreatedOn int64 `json:"created_on"` // epoch seconds }
todo: make sure CreatedOn is persisted as epoch seconds
func (*AccessToken) ExpiresOn ¶
func (a *AccessToken) ExpiresOn() int64
Instant the token expires in epoch seconds.
func (*AccessToken) IsExpired ¶
func (a *AccessToken) IsExpired() bool
Anticipate access token expiration by 5 seconds
func (*AccessToken) String ¶
func (a *AccessToken) String() string
type AccessTokenHandler ¶
type ArrowRelation ¶
type ArrowRelation struct { RelationID string Table []interface{} }
type CSVOptions ¶
type CSVOptions struct { Schema map[string]string HeaderRow *int Delim rune EscapeChar rune QuoteChar rune }
func NewCSVOptions ¶
func NewCSVOptions() *CSVOptions
func (*CSVOptions) WithDelim ¶
func (opts *CSVOptions) WithDelim(delim rune) *CSVOptions
func (*CSVOptions) WithEscapeChar ¶
func (opts *CSVOptions) WithEscapeChar(escapeChar rune) *CSVOptions
func (*CSVOptions) WithHeaderRow ¶
func (opts *CSVOptions) WithHeaderRow(headerRow int) *CSVOptions
func (*CSVOptions) WithQuoteChar ¶
func (opts *CSVOptions) WithQuoteChar(quoteChar rune) *CSVOptions
func (*CSVOptions) WithSchema ¶
func (opts *CSVOptions) WithSchema(schema map[string]string) *CSVOptions
type Client ¶
type Client struct { Region string Scheme string Host string Port string // contains filtered or unexported fields }
func NewClientFromConfig ¶
Returns a new client using the background context and config settings from the named profile.
func NewDefaultClient ¶
Returns a new client using the background context and config settings from the default profile.
func (*Client) AccessToken ¶
Returns the current access token
func (*Client) CancelTransaction ¶ added in v0.1.1
func (c *Client) CancelTransaction(id string) (*TransactionAsyncCancelResponse, error)
func (*Client) CloneDatabase ¶
func (*Client) CreateEngine ¶
Request the creation of an engine, and wait for the opeartion to complete. This can block the caller for up to a minute.
func (*Client) CreateEngineAsync ¶
Request the creation of an engine, and immediately return. The process of provisioning a new engine can take up to a minute.
func (*Client) CreateOAuthClient ¶
func (c *Client) CreateOAuthClient( name string, perms []string, ) (*OAuthClientExtra, error)
func (*Client) CreateUser ¶
func (*Client) DeleteDatabase ¶
func (*Client) DeleteEngine ¶
Request the deletion of an engine and wait for the operation to complete.
func (*Client) DeleteEngineAsync ¶
func (*Client) DeleteModel ¶
func (c *Client) DeleteModel( database, engine, name string, ) (*TransactionResult, error)
func (*Client) DeleteModels ¶
func (c *Client) DeleteModels( database, engine string, models []string, ) (*TransactionResult, error)
func (*Client) DeleteOAuthClient ¶
func (c *Client) DeleteOAuthClient(id string) (*DeleteOAuthClientResponse, error)
func (*Client) DeleteUser ¶
func (c *Client) DeleteUser(id string) (*DeleteUserResponse, error)
func (*Client) ExecuteAsync ¶
func (*Client) ExecuteV1 ¶ added in v0.2.0
func (c *Client) ExecuteV1( database, engine, source string, inputs map[string]string, readonly bool, ) (*TransactionResult, error)
Execute the given query, with the given optional query inputs.
func (*Client) FindOAuthClient ¶
func (c *Client) FindOAuthClient(name string) (*OAuthClient, error)
Returns the OAuth client with the given name or nil if it does not exist.
func (*Client) GetAccessToken ¶
func (c *Client) GetAccessToken(creds *ClientCredentials) (*AccessToken, error)
Fetch a new access token using the given client credentials.
func (*Client) GetOAuthClient ¶
func (c *Client) GetOAuthClient(id string) (*OAuthClientExtra, error)
func (*Client) GetTransaction ¶
func (c *Client) GetTransaction(id string) (*TransactionAsyncSingleResponse, error)
func (*Client) GetTransactionMetadata ¶
func (c *Client) GetTransactionMetadata(id string) ([]TransactionAsyncMetadataResponse, error)
func (*Client) GetTransactionProblems ¶
func (*Client) GetTransactionResults ¶
func (c *Client) GetTransactionResults(id string) ([]ArrowRelation, error)
func (*Client) GetTransactions ¶
func (c *Client) GetTransactions() (*TransactionAsyncMultipleResponses, error)
func (*Client) ListDatabases ¶
func (*Client) ListEngines ¶
func (*Client) ListModelNames ¶
Returns a list of model names for the given database.
func (*Client) ListModels ¶
Returns the names of models installed in the given database.
func (*Client) ListOAuthClients ¶
func (c *Client) ListOAuthClients() ([]OAuthClient, error)
func (*Client) LoadCSV ¶
func (c *Client) LoadCSV( database, engine, relation string, r io.Reader, opts *CSVOptions, ) (*TransactionResult, error)
func (*Client) LoadModels ¶
func (*Client) SetAccessTokenHandler ¶
func (c *Client) SetAccessTokenHandler(handler AccessTokenHandler)
func (*Client) SetContext ¶
func (*Client) UpdateUser ¶
func (c *Client) UpdateUser(id string, req UpdateUserRequest) (*User, error)
type ClientCredentials ¶
type ClientCredentialsHandler ¶
type ClientCredentialsHandler struct {
// contains filtered or unexported fields
}
func NewClientCredentialsHandler ¶
func NewClientCredentialsHandler( c *Client, creds *ClientCredentials, ) ClientCredentialsHandler
This handler uses the given OAuth client credentials to retrieve access tokens, as needed, and caches them locally in ~/.rai/tokens.json.
func (ClientCredentialsHandler) GetAccessToken ¶
func (h ClientCredentialsHandler) GetAccessToken() (string, error)
type ClientOptions ¶
type ClientOptions struct { Config HTTPClient *http.Client AccessTokenHandler AccessTokenHandler }
func NewClientOptions ¶
func NewClientOptions(cfg *Config) *ClientOptions
type ClientProblem ¶
type Config ¶
type Config struct { Region string `json:"region"` Scheme string `json:"scheme"` Host string `json:"host"` Port string `json:"port"` Credentials *ClientCredentials `json:"credentials"` }
type DeleteEngineStatus ¶
type DeleteUserResponse ¶
type Engine ¶
type Engine struct { ID string `json:"id"` Name string `json:"name"` Region string `json:"region"` AccountName string `json:"account_name"` CreatedBy string `json:"created_by"` CreatedOn string `json:"created_on,omitempty"` // todo: required? DeletedOn string `json:"deleted_on,omitempty"` Size string `json:"size"` State string `json:"state"` }
type NopAccessTokenHandler ¶
type NopAccessTokenHandler struct{}
This handler always returns an empty token, which results in requests not being authenticated.
func NewNopAccessTokenHandler ¶
func NewNopAccessTokenHandler() NopAccessTokenHandler
func (NopAccessTokenHandler) GetAccessToken ¶
func (h NopAccessTokenHandler) GetAccessToken() (string, error)
type OAuthClient ¶
type OAuthClientExtra ¶
type OAuthClientExtra struct { OAuthClient Permissions []string `json:"permissions"` Secret string `json:"secret"` }
type Relation ¶
type Relation struct { RelKey RelKey `json:"rel_key"` Columns [][]interface{} `json:"columns"` }
type Transaction ¶
type Transaction struct { Region string Database string Engine string Mode string Source string Abort bool Readonly bool NoWaitDurable bool Version int }
The transaction "request" envelope
func NewTransaction ¶
func NewTransaction(region, database, engine, mode string) *Transaction
func (*Transaction) Payload ¶
func (tx *Transaction) Payload(actions ...DbAction) map[string]interface{}
Constructs a transaction request payload.
func (*Transaction) QueryArgs ¶
func (tx *Transaction) QueryArgs() url.Values
type TransactionAsync ¶
TransactionAsync is the envelope for an async transaction
func NewTransactionAsync ¶
func NewTransactionAsync(database, engine string) *TransactionAsync
func (*TransactionAsync) QueryArgs ¶
func (tx *TransactionAsync) QueryArgs() url.Values
type TransactionAsyncCancelResponse ¶ added in v0.1.1
type TransactionAsyncCancelResponse struct {
Message string `json:"message"`
}
type TransactionAsyncFile ¶
type TransactionAsyncMultipleResponses ¶
type TransactionAsyncMultipleResponses struct {
Transactions []TransactionAsyncResponse `json:"transactions"`
}
type TransactionAsyncResponse ¶
type TransactionAsyncResponse struct { ID string `json:"id"` State string `json:"state"` AccountName string `json:"account_name,omitempty"` CreatedBy string `json:"created_by,omitempty"` CreatedOn int64 `json:"created_on,omitempty"` FinishedAt int64 `json:"finished_at,omitempty"` DatabaseName string `json:"database_name,omitempty"` ReadOnly bool `json:"read_only,omitempty"` UserAgent string `json:"user_agent,omitempty"` Query string `json:"query,omitempty"` LastRequestedInterval int64 `json:"last_requested_interval,omitempty"` }
type TransactionAsyncResult ¶
type TransactionAsyncResult struct { // If !GotCompleteResult, keep polling until Transaction reaches terminal State. GotCompleteResult bool Transaction TransactionAsyncResponse Results []ArrowRelation Metadata []TransactionAsyncMetadataResponse Problems []interface{} }
type TransactionAsyncSingleResponse ¶
type TransactionAsyncSingleResponse struct {
Transaction TransactionAsyncResponse `json:"transaction"`
}
type TransactionResult ¶
type TransactionResult struct { Aborted bool `json:"aborted"` Output []Relation `json:"output"` Problems []ClientProblem `json:"problems"` }
func (*TransactionResult) Show ¶
func (tx *TransactionResult) Show()