Documentation
¶
Index ¶
- func LogWarnings(errors []error) error
- func WarningsAsErrors(warnings []error) error
- type IsolationLevel
- type ModuleAlias
- type Options
- type QueryOptions
- type RetryBackoff
- type RetryCondition
- type RetryOptions
- type RetryRule
- type TLSOptions
- type TLSSecurityMode
- type TxOptions
- func (o TxOptions) Deferrable() bool
- func (o TxOptions) IsValid() bool
- func (o TxOptions) IsolationLevel() IsolationLevel
- func (o TxOptions) ReadOnly() bool
- func (o TxOptions) WithDeferrable(d bool) TxOptions
- func (o TxOptions) WithIsolation(i IsolationLevel) TxOptions
- func (o TxOptions) WithReadOnly(r bool) TxOptions
- type WarningHandler
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LogWarnings ¶
LogWarnings is a WarningHandler that logs warnings using log.Println.
func WarningsAsErrors ¶
WarningsAsErrors is a WarningHandler that returns warnings as errors.
Types ¶
type IsolationLevel ¶
type IsolationLevel string
IsolationLevel documentation can be found here
const ( // Serializable is the only isolation level Serializable IsolationLevel = "serializable" )
type ModuleAlias ¶
ModuleAlias is an alias name and module name pair.
See github.com/geldata/gel-go.Client.WithModuleAliases for example usage.
type Options ¶
type Options struct { // Host is a Gel server host address, given as either an IP address or // domain name. (Unix-domain socket paths are not supported) // // Host cannot be specified alongside the 'dsn' argument, or // CredentialsFile option. Host will override all other credentials // resolved from any environment variables, or project credentials with // their defaults. Host string // Port is a port number to connect to at the server host. // // Port cannot be specified alongside the 'dsn' argument, or // CredentialsFile option. Port will override all other credentials // resolved from any environment variables, or project credentials with // their defaults. Port int // Credentials is a JSON string containing connection credentials. // // Credentials cannot be specified alongside the 'dsn' argument, Host, // Port, or CredentialsFile. Credentials will override all other // credentials not present in the credentials string with their defaults. Credentials []byte // CredentialsFile is a path to a file containing connection credentials. // // CredentialsFile cannot be specified alongside the 'dsn' argument, Host, // Port, or Credentials. CredentialsFile will override all other // credentials not present in the credentials file with their defaults. CredentialsFile string // User is the name of the database role used for authentication. // // If not specified, the value is resolved from any compound // argument/option, then from GEL_USER, then any compound environment // variable, then project credentials. User string // Database is the name of the database to connect to. // // If not specified, the value is resolved from any compound // argument/option, then from EDGEDB_DATABASE, then any compound // environment variable, then project credentials. // // Deprecated: Database has been replaced by Branch Database string // Branch is the name of the branch to use. // // If not specified, the value is resolved from any compound // argument/option, then from GEL_BRANCH, then any compound environment // variable, then project credentials. Branch string // Password to be used for authentication, if the server requires one. // // If not specified, the value is resolved from any compound // argument/option, then from GEL_PASSWORD, then any compound // environment variable, then project credentials. // Note that the use of the environment variable is discouraged // as other users and applications may be able to read it // without needing specific privileges. Password types.OptionalStr // ConnectTimeout is used when establishing connections in the background. ConnectTimeout time.Duration // WaitUntilAvailable determines how long to wait // to reestablish a connection. WaitUntilAvailable time.Duration // Concurrency determines the maximum number of connections. // If Concurrency is zero, max(4, runtime.NumCPU()) will be used. // Has no effect for single connections. Concurrency uint // Parameters used to configure TLS connections to Gel server. TLSOptions TLSOptions // Read the TLS certificate from this file. // DEPRECATED, use TLSOptions.CAFile instead. TLSCAFile string // Specifies how strict TLS validation is. // DEPRECATED, use TLSOptions.SecurityMode instead. TLSSecurity string // ServerSettings is currently unused. ServerSettings map[string][]byte // SecretKey is used to connect to cloud instances. SecretKey string // WarningHandler is invoked when Gel returns warnings. Defaults to // gelcfg.LogWarnings. WarningHandler WarningHandler }
Options for connecting to a Gel server
Example ¶
opts := gelcfg.Options{ ConnectTimeout: 60 * time.Second, WaitUntilAvailable: 5 * time.Second, WarningHandler: gelcfg.WarningsAsErrors, } client, err := gel.CreateClient(opts) if err != nil { log.Fatal(err) } var message string err = client.QuerySingle(ctx, `SELECT "hello Gel"`, &message) if err != nil { log.Fatal(err) } fmt.Println(message)
Output: hello Gel
type QueryOptions ¶
type QueryOptions struct {
// contains filtered or unexported fields
}
QueryOptions controls limitations that the server can impose on queries.
See github.com/geldata/gel-go.Client.WithQueryOptions for example usage.
func NewQueryOptions ¶
func NewQueryOptions() QueryOptions
NewQueryOptions returns the default QueryOptions value with readOnly set to false, and implicitLimit set to 0.
func (QueryOptions) ImplicitLimit ¶
func (o QueryOptions) ImplicitLimit() uint64
ImplicitLimit returns the configured implicit limit.
func (QueryOptions) ReadOnly ¶
func (o QueryOptions) ReadOnly() bool
ReadOnly returns true if read only mode is enabled.
func (QueryOptions) WithImplicitLimit ¶
func (o QueryOptions) WithImplicitLimit(limit uint64) QueryOptions
WithImplicitLimit sets the max number of results that the server will return. If set to 0 the server will return all results. Defaults to 0.
func (QueryOptions) WithReadOnly ¶
func (o QueryOptions) WithReadOnly(readOnly bool) QueryOptions
WithReadOnly enables read only mode if readOnly is true.
type RetryBackoff ¶
RetryBackoff returns the duration to wait after the nth attempt before retrying a transaction.
type RetryCondition ¶
type RetryCondition int
RetryCondition represents scenarios that can cause a transaction or a single query run outside a geltypes.TxBlock to be retried.
const ( // TxConflict indicates that the server could not complete a transaction // because it encountered a deadlock or serialization error. TxConflict RetryCondition = iota // NetworkError indicates that the transaction was interupted // by a network error. NetworkError )
type RetryOptions ¶
type RetryOptions struct {
// contains filtered or unexported fields
}
RetryOptions configures how failed transactions or queries outside of transactions are retried. Use NewRetryOptions to get a default RetryOptions value instead of creating one yourself.
See github.com/geldata/gel-go.Client.WithRetryOptions for an example.
func NewRetryOptions ¶
func NewRetryOptions() RetryOptions
NewRetryOptions returns the default RetryOptions.
func (RetryOptions) IsValid ¶
func (o RetryOptions) IsValid() bool
IsValid returns true if o was created with NewRetryOptions()
func (RetryOptions) RuleForException ¶
func (o RetryOptions) RuleForException(err gelerr.Error) (RetryRule, error)
RuleForException returns the RetryRule to be applied for err.
func (RetryOptions) WithCondition ¶
func (o RetryOptions) WithCondition( condition RetryCondition, rule RetryRule, ) RetryOptions
WithCondition sets the retry rule for the specified condition.
func (RetryOptions) WithDefault ¶
func (o RetryOptions) WithDefault(rule RetryRule) RetryOptions
WithDefault sets the rule for all conditions to rule.
type RetryRule ¶
type RetryRule struct {
// contains filtered or unexported fields
}
RetryRule determines how transactions or queries outside of transactions should be retried.
Retries are governed by retry rules. The default rule can be set with RetryOptions.WithDefault. For more fine grained control a RetryRule can be set for each defined RetryCondition using RetryOptions.WithCondition. When a transaction fails but gelerr.Error.HasTag gelerr.ShouldRetry the rule for the failure condition is used to determine if the transaction should be tried again based on RetryRule.Attempts and the amount of time to wait before retrying is determined by RetryRule.Backoff. The default retry rule is 3 attempts and exponential backoff with jitter.
See github.com/geldata/gel-go.Client.WithRetryOptions for an example.
func (RetryRule) Backoff ¶
func (r RetryRule) Backoff() RetryBackoff
Backoff returns the RetryBackoff.
func (RetryRule) WithAttempts ¶
WithAttempts sets the rule's attempts. attempts must be greater than zero.
func (RetryRule) WithBackoff ¶
func (r RetryRule) WithBackoff(fn RetryBackoff) RetryRule
WithBackoff returns a copy of the RetryRule with backoff set to fn.
type TLSOptions ¶
type TLSOptions struct { // PEM-encoded CA certificate CA []byte // Path to a PEM-encoded CA certificate file CAFile string // Determines how strict we are with TLS checks SecurityMode TLSSecurityMode // Used to verify the hostname on the returned certificates ServerName string }
TLSOptions contains the parameters needed to configure TLS on Gel server connections.
type TLSSecurityMode ¶
type TLSSecurityMode string
TLSSecurityMode specifies how strict TLS validation is.
const ( // TLSModeDefault makes security mode inferred from other options TLSModeDefault TLSSecurityMode = "default" // TLSModeInsecure results in no certificate verification whatsoever TLSModeInsecure TLSSecurityMode = "insecure" // TLSModeNoHostVerification enables certificate verification // against CAs, but hostname matching is not performed. TLSModeNoHostVerification TLSSecurityMode = "no_host_verification" // TLSModeStrict enables full certificate and hostname verification. TLSModeStrict TLSSecurityMode = "strict" )
type TxOptions ¶
type TxOptions struct {
// contains filtered or unexported fields
}
TxOptions configures how transactions behave.
See github.com/geldata/gel-go.Client.WithTxOptions for an example.
func (TxOptions) Deferrable ¶
Deferrable returns true if deferrable mode is set.
func (TxOptions) IsolationLevel ¶
func (o TxOptions) IsolationLevel() IsolationLevel
IsolationLevel returns the TxOptions IsolationLevel setting.
func (TxOptions) WithDeferrable ¶
WithDeferrable returns a copy of the TxOptions with the transaction deferrable mode set to d.
func (TxOptions) WithIsolation ¶
func (o TxOptions) WithIsolation(i IsolationLevel) TxOptions
WithIsolation returns a copy of the TxOptions with the isolation level set to i.
func (TxOptions) WithReadOnly ¶
WithReadOnly returns a copy of the TxOptions with the transaction read only access mode set to r.
type WarningHandler ¶
WarningHandler takes an error slice that represent warnings and optionally returns an error. This can be used to log warnings, increment metrics, promote warnings to errors by returning them etc.
See github.com/geldata/gel-go.Client.WithWarningHandler for an example.