dsn

package
v0.54.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0, BSD-3-Clause, MIT, + 1 more Imports: 16 Imported by: 22 modules, 23 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

For connection string formats, see ../doc/connection.md.

Documentation

Index

Examples

Constants

View Source
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"
)
View Source
const (
	NoRole    = AdminRole("")
	SysDBA    = AdminRole("SYSDBA")
	SysOPER   = AdminRole("SYSOPER")
	SysBACKUP = AdminRole("SYSBACKUP")
	SysDG     = AdminRole("SYSDG")
	SysKM     = AdminRole("SYSKM")
	SysRAC    = AdminRole("SYSRAC")
	SysASM    = AdminRole("SYSASM")
)

Variables

View Source
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

func AppendLogfmt(w io.Writer, key, value any) error

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 Bool added in v0.46.0

func Bool(b bool) sql.NullBool

Bool is an sql.NullBool helper

func Fuzz

func Fuzz(data []byte) int

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

func ParseTZ

func ParseTZ(s string) (int, error)

ParseTZ parses timezone specification ("Europe/Budapest" or "+01:00") and returns the offset in seconds.

Types

type AccessToken added in v0.44.0

type AccessToken struct {
	Token      string
	PrivateKey string
}

AccessToken Data for Token Authentication.

type AdminRole added in v0.47.0

type AdminRole string

func (AdminRole) String added in v0.47.0

func (r AdminRole) String() string

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

func NewPassword(secret string) Password

NewPassword creates a new Password, containing the given secret.

func (*Password) CopyFrom added in v0.19.3

func (P *Password) CopyFrom(Q Password)

CopyFrom another password.

func (Password) IsZero

func (P Password) IsZero() bool

IsZero returns whether the password is emtpy.

func (Password) Len

func (P Password) Len() int

Len returns the length of the password.

func (Password) LogValue added in v0.38.0

func (P Password) LogValue() slog.Value

LogValue implements slog.LogValuer.

func (*Password) MarshalBinary added in v0.33.1

func (P *Password) MarshalBinary() ([]byte, error)

func (*Password) MarshalJSON added in v0.33.1

func (P *Password) MarshalJSON() ([]byte, error)

nosemgrep

func (*Password) MarshalText added in v0.33.1

func (P *Password) MarshalText() ([]byte, error)

func (*Password) Reset

func (P *Password) Reset()

Reset the password.

func (Password) Secret

func (P Password) Secret() string

Secret reveals the real password.

func (*Password) Set added in v0.19.3

func (P *Password) Set(secret string)

Set the password.

func (Password) String

func (P Password) String() string

String returns the secret obfuscated irreversibly.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL