Documentation
¶
Index ¶
- Constants
- Variables
- func AlterSessionStmt(ps []SessionParam) string
- func AppendLogfmt(w io.Writer, key, value any) error
- func Bool(b bool) sql.NullBool
- func Fuzz(data []byte) int
- func ParseTZ(s string) (int, error)
- type AccessToken
- type AdminRole
- type CommonParams
- type CommonSimpleParams
- type ConnParams
- type ConnectionParams
- func (P ConnectionParams) IsStandalone() bool
- func (P ConnectionParams) IsZero() bool
- func (P ConnectionParams) LogValue() slog.Value
- func (P *ConnectionParams) SetSessionParamOnInit(k, v string)
- func (P *ConnectionParams) SetSessionParamOnInitKeyword(k string, v Keyword)
- func (P ConnectionParams) String() string
- func (P ConnectionParams) StringNoClass() string
- func (P ConnectionParams) StringWithPassword() string
- type Keyword
- type Password
- func (P *Password) CopyFrom(Q Password)
- func (P Password) IsZero() bool
- func (P Password) Len() int
- func (P Password) LogValue() slog.Value
- func (P *Password) MarshalBinary() ([]byte, error)
- func (P *Password) MarshalJSON() ([]byte, error)
- func (P *Password) MarshalText() ([]byte, error)
- func (P *Password) Reset()
- func (P Password) Secret() string
- func (P *Password) Set(secret string)
- func (P Password) String() string
- type PoolParams
- type SessionParam
- type SessionParamValue
- type String
Examples ¶
Constants ¶
const ( // DefaultPoolMinSessions specifies the default value for minSessions for pool creation. DefaultPoolMinSessions = 1 // DefaultPoolMaxSessions specifies the default value for maxSessions for pool creation. DefaultPoolMaxSessions = 1000 // DefaultSessionIncrement specifies the default value for increment for pool creation. DefaultSessionIncrement = 1 // DefaultPoolIncrement is a deprecated name for DefaultSessionIncrement. DefaultPoolIncrement = DefaultSessionIncrement // DefaultConnectionClass is empty, which allows to use the poolMinSessions created as part of session pool creation for non-DRCP. For DRCP, connectionClass needs to be explicitly mentioned. DefaultConnectionClass = "" // NoConnectionPoolingConnectionClass is a special connection class name to indicate no connection pooling. // It is the same as setting standaloneConnection=1 NoConnectionPoolingConnectionClass = "NO-CONNECTION-POOLING" // DefaultSessionTimeout is the seconds before idle pool sessions get evicted DefaultSessionTimeout = 5 * time.Minute // DefaultWaitTimeout is the milliseconds to wait for a session to become available DefaultWaitTimeout = 30 * time.Second // DefaultMaxLifeTime is the maximum time in seconds till a pooled session may exist DefaultMaxLifeTime = 1 * time.Hour // DefaultStandaloneConnection holds the default for standaloneConnection. DefaultStandaloneConnection = true // DefaultNoBreakOnContextCancel holds the default for noBreakOnContext DefaultNoBreakOnContextCancel = false DefaultTestDSN = "oracle://demo:demo@localhost:1521/freepdb1" DefaultTestSystemDSN = "oracle://sys:system@localhost:1521/freepdb1?sysdba=1" )
Variables ¶
var ErrCannotMarshal = errors.New("cannot be marshaled")
Functions ¶
func AlterSessionStmt ¶ added in v0.54.0
func AlterSessionStmt(ps []SessionParam) string
AlterSessionStmt returns the "ALTER SESSION SET key=value ..." statement of the session parameters, each Key written as given, and the Value written as-is if it is a Keyword, as a quoted string literal if a String.
func AppendLogfmt ¶
AppendLogfmt appends the key=val logfmt-formatted.
Example ¶
var buf strings.Builder AppendLogfmt(&buf, "user", "scott") AppendLogfmt(&buf, "password", "tiger") AppendLogfmt(&buf, "connectString", "dbhost:1521/orclpdb1?connect_timeout=2") fmt.Println(buf.String())
Output: user=scott password=tiger connectString="dbhost:1521/orclpdb1?connect_timeout=2"
func Fuzz ¶
See https://github.com/dvyukov/go-fuzz
(cd /tmp && go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build) PATH=$HOME/sdk/go1.14.6/bin:$PATH GO111MODULE=on go-fuzz-build go-fuzz
Types ¶
type AccessToken ¶ added in v0.44.0
AccessToken Data for Token Authentication.
type CommonParams ¶
type CommonParams struct {
// Logger is the per-pool or per-connection logger.
// The default nil logger does not log.
Logger *slog.Logger
// OnInit is executed on session init. Overrides AlterSession and OnInitStmts!
OnInit func(context.Context, driver.ConnPrepareContext) error `json:"-"`
// OnInitStmts are executed on session init, iff OnInit is nil.
OnInitStmts []string
// AlterSession key-values are set with "ALTER SESSION SET key=value" on session init, iff OnInit is nil.
AlterSession []SessionParam
CommonSimpleParams
}
func (CommonParams) LogValue ¶ added in v0.53.0
func (P CommonParams) LogValue() slog.Value
LogValue implements slog.LogValuer, so structured handlers (e.g. JSON) log the masked String form instead of serializing Password, Token and PrivateKey.
func (CommonParams) String ¶
func (P CommonParams) String() string
type CommonSimpleParams ¶ added in v0.39.3
type CommonSimpleParams struct {
Timezone *time.Location
ConfigDir, LibDir string
Username, ConnectString string
Token, PrivateKey string
Password Password
Charset string
// StmtCacheSize controls the Oracle Client statement cache.
// Zero means the default; -1 disables it.
StmtCacheSize int
// true: OnInit will be called only by the new session / false: OnInit will called by new or pooled connection
InitOnNewConn bool
EnableEvents, NoTZCheck, PerSessionTimezone bool
NoBreakOnContextCancel bool
}
func (CommonSimpleParams) IsZero ¶ added in v0.51.4
func (P CommonSimpleParams) IsZero() bool
func (CommonSimpleParams) LogValue ¶ added in v0.53.0
func (P CommonSimpleParams) LogValue() slog.Value
LogValue implements slog.LogValuer, see CommonParams.LogValue.
func (CommonSimpleParams) String ¶ added in v0.39.3
func (P CommonSimpleParams) String() string
String returns the string representation of CommonParams.
type ConnParams ¶
type ConnParams struct {
NewPassword Password
ConnClass string
AdminRole AdminRole
ShardingKey, SuperShardingKey []any
IsPrelim bool
}
ConnParams holds the connection-specific parameters.
For details, see https://oracle.github.io/odpi/doc/structs/dpiConnCreateParams.html#dpiconncreateparams
func (ConnParams) IsZero ¶ added in v0.51.4
func (P ConnParams) IsZero() bool
func (ConnParams) String ¶
func (P ConnParams) String() string
String returns the string representation of the ConnParams.
type ConnectionParams ¶
type ConnectionParams struct {
CommonParams
ConnParams
PoolParams
// ConnParams.NewPassword is used iff StandaloneConnection is true!
StandaloneConnection sql.NullBool
}
ConnectionParams holds the params for a connection (pool). You can use ConnectionParams{...}.StringWithPassword() as a connection string in sql.Open.
func Parse ¶
func Parse(dataSourceName string) (ConnectionParams, error)
Parse parses the given connection string into a struct.
For examples, see [../doc/connection.md](../doc/connection.md)
Example ¶
var P ConnectionParams
P.Username, P.Password = "scott", NewPassword("tiger")
P.ConnectString = "dbhost:1521/orclpdb1?connect_timeout=2"
P.SessionTimeout = 42 * time.Second
P.SetSessionParamOnInit("NLS_NUMERIC_CHARACTERS", ",.")
P.SetSessionParamOnInit("NLS_LANGUAGE", "FRENCH")
fmt.Println(P.StringWithPassword())
Output: user=scott password=tiger connectString="dbhost:1521/orclpdb1?connect_timeout=2" alterSession="NLS_NUMERIC_CHARACTERS=',.'" alterSession="NLS_LANGUAGE='FRENCH'" connectionClass= newPassword= poolIncrement=0 poolMinSessions=0 poolSessionMaxLifetime=0s poolSessionTimeout=42s poolWaitTimeout=0s
func (ConnectionParams) IsStandalone ¶
func (P ConnectionParams) IsStandalone() bool
IsStandalone returns whether the connection should be standalone, not pooled.
func (ConnectionParams) IsZero ¶ added in v0.51.4
func (P ConnectionParams) IsZero() bool
func (ConnectionParams) LogValue ¶ added in v0.53.0
func (P ConnectionParams) LogValue() slog.Value
LogValue implements slog.LogValuer, see CommonParams.LogValue.
func (*ConnectionParams) SetSessionParamOnInit ¶
func (P *ConnectionParams) SetSessionParamOnInit(k, v string)
SetSessionParamOnInit adds an "ALTER SESSION SET Key=Value" to the OnInit task list, with the value written as a quoted string literal.
func (*ConnectionParams) SetSessionParamOnInitKeyword ¶ added in v0.54.0
func (P *ConnectionParams) SetSessionParamOnInitKeyword(k string, v Keyword)
SetSessionParamOnInitKeyword adds an "ALTER SESSION SET Key=Value" to the OnInit task list, with the value written as-is: pass Keyword(v) for the parameters that take a keyword (ISOLATION_LEVEL, TIME_ZONE=LOCAL, the boolean initialization parameters) or an identifier (CURRENT_SCHEMA, EDITION, CONTAINER).
func (ConnectionParams) String ¶
func (P ConnectionParams) String() string
String returns the string representation of ConnectionParams. The password is replaced with a "***" string!
func (ConnectionParams) StringNoClass ¶
func (P ConnectionParams) StringNoClass() string
StringNoClass returns the string representation of ConnectionParams, without class info. The password is replaced with a "***" string!
func (ConnectionParams) StringWithPassword ¶
func (P ConnectionParams) StringWithPassword() string
StringWithPassword returns the string representation of ConnectionParams (as String() does), but does NOT obfuscate the password, just prints it as is.
type Keyword ¶ added in v0.54.0
type Keyword string
CommonParams holds the common parameters for pooled or standalone connections.
For details, see https://oracle.github.io/odpi/doc/structs/dpiCommonCreateParams.html#dpicommoncreateparams Keyword is a session parameter value that godror writes as-is (unquoted) into the "ALTER SESSION SET" statement: a keyword (TRUE, FALSE, LOCAL, DBTIMEZONE, SERIALIZABLE, READ COMMITTED, ...) or an identifier (a schema, an edition or a container name). See the ALTER SESSION documentation for which parameter takes which.
The textual form (ConnectionParams.String and the alterSession DSN parameter) keeps the type: a String is written as a quoted literal, a Keyword as-is, and Parse reads them back the same way. A Keyword must not contain a single quote, or it is read back as a String.
type Password ¶
type Password struct {
// contains filtered or unexported fields
}
Password is printed obfuscated with String, use Secret to reveal the secret.
func NewPassword ¶
NewPassword creates a new Password, containing the given secret.
func (*Password) MarshalBinary ¶ added in v0.33.1
func (*Password) MarshalJSON ¶ added in v0.33.1
nosemgrep
func (*Password) MarshalText ¶ added in v0.33.1
type PoolParams ¶
type PoolParams struct {
TokenCBCtx context.Context `json:"-"`
TokenCB func(context.Context, *AccessToken) error `json:"-"`
MinSessions, MaxSessions, SessionIncrement int
MaxSessionsPerShard int
WaitTimeout, MaxLifeTime, SessionTimeout time.Duration
PingInterval time.Duration
Heterogeneous, ExternalAuth, NoWait sql.NullBool
}
PoolParams holds the configuration of the Oracle Session Pool.
For details, see https://oracle.github.io/odpi/doc/structs/dpiPoolCreateParams.html#dpipoolcreateparams
For details, see https://oracle.github.io/odpi/doc/structs/dpiPoolCreateParams.html#dpipoolcreateparams
func (PoolParams) IsZero ¶ added in v0.51.4
func (P PoolParams) IsZero() bool
func (PoolParams) String ¶
func (P PoolParams) String() string
String returns the string representation of PoolParams.
type SessionParam ¶ added in v0.54.0
type SessionParam struct {
Key string
Value SessionParamValue
}
SessionParam is one "ALTER SESSION SET Key=Value" on session init.
type SessionParamValue ¶ added in v0.54.0
type SessionParamValue interface {
// contains filtered or unexported methods
}
SessionParamValue is the value of a SessionParam: a Keyword, written as-is, or a String, written as a quoted string literal. The interface is sealed: only Keyword and String implement it.
type String ¶ added in v0.54.0
type String string
String is a session parameter value written as a quoted string literal, with its single quotes doubled, so it can only set its own parameter.
The parameters that take an identifier (CURRENT_SCHEMA, EDITION, CONTAINER) are written as-is even when their value is a String. In the textual form a String is written as a quoted literal; see Keyword.