Documentation
¶
Overview ¶
Package geode provides a database/sql driver for the Geode graph database.
The driver connects to Geode servers over QUIC with TLS 1.3 and implements the full GQL (Graph Query Language) specification.
Usage ¶
Import the driver anonymously to register it with database/sql:
import (
"database/sql"
_ "geodedb.com/geode"
)
db, err := sql.Open("geode", "localhost:3141")
DSN Format ¶
The driver supports multiple DSN formats:
quic://host:port?options (QUIC transport - recommended) grpc://host:port?options (gRPC transport) host:port?options (defaults to QUIC) host:port host
Options:
- page_size: Results page size (default: 1000)
- hello_name: Client name (default: "geode-go")
- hello_ver: Client version (default: "0.1")
- conformance: GQL conformance level (default: "min")
- ca: Path to CA certificate
- cert: Path to client certificate (for mTLS)
- key: Path to client key (for mTLS)
- insecure: Skip TLS verification (testing only)
- connect_timeout: Connection timeout in seconds (default: 0 = no timeout)
Environment variables:
- GEODE_HOST: Default host if DSN is empty
- GEODE_PORT: Default port if not specified
- GEODE_TLS_CA: Default CA certificate path
Example ¶
db, err := sql.Open("geode", "quic://localhost:3141?page_size=500")
if err != nil {
log.Fatal(err)
}
defer db.Close()
rows, err := db.QueryContext(ctx, "MATCH (n:Person) RETURN n.name LIMIT 10")
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var name string
if err := rows.Scan(&name); err != nil {
log.Fatal(err)
}
fmt.Println(name)
}
Index ¶
- Constants
- Variables
- func IsRetryableError(err error) bool
- func NewTLSConfig(cfg *Config) (*tls.Config, error)
- func Utf16ToUtf8(u []uint16) string
- func Utf8ToUtf16(s string) []uint16
- func Wtf8Lossy(b []byte) string
- type ColumnInfo
- type Config
- type ConfigError
- type Conn
- func (c *Conn) Begin() (driver.Tx, error)deprecated
- func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)
- func (c *Conn) CheckNamedValue(nv *driver.NamedValue) error
- func (c *Conn) Close() error
- func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
- func (c *Conn) IsValid() bool
- func (c *Conn) Ping(ctx context.Context) error
- func (c *Conn) Prepare(query string) (driver.Stmt, error)deprecated
- func (c *Conn) PrepareContext(_ context.Context, query string) (driver.Stmt, error)
- func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
- func (c *Conn) ResetSession(ctx context.Context) error
- type ConnState
- type Connector
- type Driver
- type DriverError
- type Error
- type GQLType
- type GRPCTransport
- func (t *GRPCTransport) Addr() string
- func (t *GRPCTransport) Close() error
- func (t *GRPCTransport) IsClosed() bool
- func (t *GRPCTransport) ReceiveProto(_ context.Context) (*proto.QuicServerMessage, error)
- func (t *GRPCTransport) SendProto(ctx context.Context, msg *proto.QuicClientMessage) error
- func (t *GRPCTransport) TryReceiveProtoBuffered() (*proto.QuicServerMessage, bool, error)
- type QUICTransport
- func (t *QUICTransport) Addr() string
- func (t *QUICTransport) Close() error
- func (t *QUICTransport) IsClosed() bool
- func (t *QUICTransport) ReceiveProto(ctx context.Context) (*proto.QuicServerMessage, error)
- func (t *QUICTransport) SendProto(ctx context.Context, msg *proto.QuicClientMessage) error
- func (t *QUICTransport) TryReceiveProtoBuffered() (*proto.QuicServerMessage, bool, error)
- type Result
- type Rows
- func (r *Rows) Close() error
- func (r *Rows) ColumnTypeDatabaseTypeName(index int) string
- func (r *Rows) ColumnTypeNullable(_ int) (nullable, ok bool)
- func (r *Rows) ColumnTypeScanType(index int) reflect.Type
- func (r *Rows) Columns() []string
- func (r *Rows) IsOrdered() bool
- func (r *Rows) Next(dest []driver.Value) error
- func (r *Rows) OrderKeys() []string
- type SecurityError
- type StateError
- type Stmt
- func (s *Stmt) Close() error
- func (s *Stmt) Exec(args []driver.Value) (driver.Result, error)deprecated
- func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)
- func (s *Stmt) NumInput() int
- func (s *Stmt) Query(args []driver.Value) (driver.Rows, error)deprecated
- func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)
- type Transport
- type TransportError
- type TransportType
- type Tx
- type UnsupportedSchemeError
Constants ¶
const ( // DefaultPort is the default Geode server port for QUIC. DefaultPort = "3141" // DefaultGRPCPort is the default Geode server port for gRPC. DefaultGRPCPort = "50051" // DefaultPageSize is the default number of rows per page. DefaultPageSize = 1000 // MaxPageSize is the maximum allowed page size. // This prevents potential DoS via memory exhaustion with extremely large page sizes. MaxPageSize = 100000 // DefaultHelloName is the default client name sent in HELLO. DefaultHelloName = "geode-go" // DefaultHelloVersion is the default client version sent in HELLO. DefaultHelloVersion = "0.1" // DefaultConformance is the default GQL conformance level. DefaultConformance = "min" // MaxQueryLength is the maximum allowed query length. MaxQueryLength = 1 << 20 // 1MB )
const ( StatusSuccess = "00000" // Successful completion StatusNoData = "02000" // No data StatusWarning = "01000" // Warning StatusTransactionState = "25000" // Invalid transaction state StatusAuth = "28000" // Authorization error StatusSerialization = "40001" // Serialization failure (retryable) StatusDeadlock = "40502" // Transaction deadlock (retryable) StatusSyntax = "42000" // Syntax error StatusConstraint = "23000" // Constraint violation StatusDuplicate = "42P07" // Duplicate object StatusInvalidParam = "22023" // Invalid parameter value StatusSystem = "58000" // System error )
ISO/IEC 39075 status class constants.
Variables ¶
var ( ErrClosed = errors.New("geode: connection closed") ErrQueryInProgress = errors.New("geode: query already in progress") ErrTxInProgress = errors.New("geode: transaction already in progress") ErrNoTx = errors.New("geode: no transaction in progress") ErrTxDone = errors.New("geode: transaction already committed or rolled back") ErrStmtClosed = errors.New("geode: statement closed") ErrRowsClosed = errors.New("geode: rows closed") ErrBadConn = errors.New("geode: bad connection") ErrInvalidState = errors.New("geode: invalid connection state") )
Sentinel errors for common conditions.
Functions ¶
func IsRetryableError ¶
IsRetryableError checks if an error is retryable.
func NewTLSConfig ¶
NewTLSConfig creates a TLS configuration for connecting to a Geode server.
The configuration enforces TLS 1.3 minimum and uses the ALPN protocol "geode/1". Certificate verification is always enabled unless explicitly disabled via Config.InsecureSkipVerify (which should only be used for testing).
CA certificates are loaded from (in order of precedence):
- Config.TLSCA (explicit path)
- GEODE_TLS_CA environment variable
- System certificate pool
If Config.TLSCert and Config.TLSKey are provided, mutual TLS (mTLS) is enabled.
func Utf16ToUtf8 ¶
Utf16ToUtf8 converts UTF-16 code units to a UTF-8 string.
CANARY: REQ=REQ-GQL-UNICODE-013; FEATURE="UTF-16 -> UTF-8 Conversion"; ASPECT=ClientWrapperGo; STATUS=IMPL; TEST=TestCANARY_ClientGo_Utf8Utf16RoundTrip; OWNER=clients; UPDATED=2025-09-27
func Utf8ToUtf16 ¶
Utf8ToUtf16 converts a UTF-8 string to UTF-16 code units.
CANARY: REQ=REQ-GQL-UNICODE-012; FEATURE="UTF-8 -> UTF-16 Conversion"; ASPECT=ClientWrapperGo; STATUS=IMPL; TEST=TestCANARY_ClientGo_Utf8Utf16RoundTrip; OWNER=clients; UPDATED=2025-09-27
func Wtf8Lossy ¶
Wtf8Lossy converts a byte slice to a UTF-8 string, replacing invalid sequences with the Unicode replacement character (U+FFFD).
CANARY: REQ=REQ-GQL-UNICODE-014; FEATURE="WTF-8 Lossy Decode"; ASPECT=ClientWrapperGo; STATUS=IMPL; TEST=TestCANARY_ClientGo_Wtf8Lossy; OWNER=clients; UPDATED=2025-09-27
Types ¶
type ColumnInfo ¶
ColumnInfo holds metadata about a column.
type Config ¶
type Config struct {
// Transport specifies the transport protocol (QUIC or gRPC).
Transport TransportType
// Host is the server hostname or IP address.
Host string
// Port is the server port.
Port string
// Username for authentication.
Username string
// Password for authentication.
Password string
// PageSize is the number of rows to fetch per page.
PageSize int
// HelloName is the client name sent in HELLO.
HelloName string
// HelloVersion is the client version sent in HELLO.
HelloVersion string
// Conformance is the GQL conformance level.
Conformance string
// TLS configuration
TLSCA string // Path to CA certificate
TLSCert string // Path to client certificate (for mTLS)
TLSKey string // Path to client private key (for mTLS)
// TLSDisabled disables TLS entirely (plaintext gRPC, for testing only).
TLSDisabled bool
// InsecureSkipVerify allows skipping TLS verification (for testing only).
// This should never be used in production.
InsecureSkipVerify bool
// ConnectTimeout is the maximum time to wait for a connection.
// Zero means no timeout. This helps prevent connection storms.
// For rate limiting, use database/sql's connection pool settings:
// db.SetMaxOpenConns(n) - limits concurrent connections
// db.SetMaxIdleConns(n) - limits idle connections
// db.SetConnMaxLifetime(d) - limits connection age
// db.SetConnMaxIdleTime(d) - limits idle time
ConnectTimeout int // in seconds, 0 = no timeout
}
Config holds the configuration for a Geode connection.
func ParseDSN ¶
ParseDSN parses a data source name into a Config.
See geode/docs/DSN.md for the complete DSN specification.
Supported formats:
- quic://host:port?options (QUIC transport)
- grpc://host:port?options (gRPC transport)
- host:port?options (QUIC transport, scheme-less)
- host:port (QUIC transport)
- host (QUIC transport, uses default port)
IPv6 hosts are supported:
- quic://[::1]:3141
- grpc://[2001:db8::1]:50051
Supported options:
- page_size: Results page size (default: 1000)
- hello_name: Client name (default: "geode-go")
- hello_ver: Client version (default: "0.1")
- conformance: GQL conformance level (default: "min")
- ca: Path to CA certificate
- cert: Path to client certificate (for mTLS)
- key: Path to client key (for mTLS)
- insecure_tls_skip_verify: Skip TLS verification (testing only, aliases: insecure, skip_verify)
- tls: Enable/disable TLS ("0" or "false" to disable, gRPC only)
Environment variables:
- GEODE_HOST: Default host if DSN is empty
- GEODE_PORT: Default port if not specified
- GEODE_TLS_CA: Default CA certificate path
type ConfigError ¶
type ConfigError struct {
Field string // Configuration field name
Value string // Invalid value
Message string // Error message
}
ConfigError represents DSN/configuration errors.
func (*ConfigError) Error ¶
func (e *ConfigError) Error() string
Error implements the error interface.
func (*ConfigError) IsRetryable ¶
func (e *ConfigError) IsRetryable() bool
IsRetryable indicates if the operation can be retried.
func (*ConfigError) StatusClass ¶
func (e *ConfigError) StatusClass() string
StatusClass returns the status class.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents a connection to a Geode database.
func (*Conn) CheckNamedValue ¶
func (c *Conn) CheckNamedValue(nv *driver.NamedValue) error
CheckNamedValue validates a named value before use.
func (*Conn) ExecContext ¶
func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
ExecContext executes a query that doesn't return rows.
func (*Conn) Prepare
deprecated
Prepare returns a prepared statement. Note: Geode doesn't have server-side prepared statements, so this is a client-side implementation.
Deprecated: Use PrepareContext instead for explicit timeout control. This method uses a default 30-second timeout.
func (*Conn) PrepareContext ¶
PrepareContext returns a prepared statement with context.
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector implements driver.Connector.
type Driver ¶
type Driver struct{}
Driver implements driver.Driver and driver.DriverContext.
func (*Driver) Open
deprecated
Open opens a new connection to the database. The name is a DSN (data source name) in the format described above.
Deprecated: Use OpenConnector and Connector.Connect with an explicit context for timeout control. This method uses defaultDeprecatedMethodTimeout (30s).
type DriverError ¶
type DriverError struct {
Class string // ISO/IEC 39075 status class (00000, 25000, etc.)
Subclass string // Status subclass
Code string // Error code (US001, IllegalOrderKey, etc.)
Message string // Human-readable message
Anchor string // Source location in query
Additional []string // Additional diagnostic info
Findings []string // Flagger findings
// contains filtered or unexported fields
}
DriverError represents errors returned from the Geode server.
func IsDriverError ¶
func IsDriverError(err error) (*DriverError, bool)
IsDriverError checks if err is a DriverError and returns it.
func (*DriverError) Error ¶
func (e *DriverError) Error() string
Error implements the error interface.
func (*DriverError) IsRetryable ¶
func (e *DriverError) IsRetryable() bool
IsRetryable indicates if the operation can be retried.
func (*DriverError) StatusClass ¶
func (e *DriverError) StatusClass() string
StatusClass returns the ISO/IEC 39075 status class.
func (*DriverError) Unwrap ¶
func (e *DriverError) Unwrap() error
Unwrap returns the underlying cause.
type Error ¶
type Error interface {
error
// StatusClass returns ISO/IEC 39075 status class.
StatusClass() string
// IsRetryable indicates if the operation can be retried.
IsRetryable() bool
}
Error is the interface for all Geode errors.
type GQLType ¶
type GQLType string
GQLType represents a GQL data type.
const ( GQLTypeInt GQLType = "INT" GQLTypeFloat GQLType = "FLOAT" GQLTypeString GQLType = "STRING" GQLTypeBool GQLType = "BOOL" GQLTypeNull GQLType = "NULL" GQLTypeList GQLType = "LIST" GQLTypeMap GQLType = "MAP" GQLTypeNode GQLType = "NODE" GQLTypeEdge GQLType = "EDGE" GQLTypePath GQLType = "PATH" GQLTypeUnknown GQLType = "UNKNOWN" )
GQL type constants.
type GRPCTransport ¶
type GRPCTransport struct {
// contains filtered or unexported fields
}
GRPCTransport implements Transport over gRPC.
func NewGRPCTransport ¶
func NewGRPCTransport(_ context.Context, cfg *Config) (*GRPCTransport, error)
NewGRPCTransport creates a new gRPC transport to the Geode server.
func (*GRPCTransport) IsClosed ¶
func (t *GRPCTransport) IsClosed() bool
IsClosed returns true if the transport is closed.
func (*GRPCTransport) ReceiveProto ¶
func (t *GRPCTransport) ReceiveProto(_ context.Context) (*proto.QuicServerMessage, error)
ReceiveProto reads a protobuf message from the gRPC stream.
func (*GRPCTransport) SendProto ¶
func (t *GRPCTransport) SendProto(ctx context.Context, msg *proto.QuicClientMessage) error
SendProto sends a protobuf message via gRPC.
func (*GRPCTransport) TryReceiveProtoBuffered ¶
func (t *GRPCTransport) TryReceiveProtoBuffered() (*proto.QuicServerMessage, bool, error)
TryReceiveProtoBuffered attempts to read a buffered message without blocking.
type QUICTransport ¶
type QUICTransport struct {
// contains filtered or unexported fields
}
QUICTransport implements Transport over QUIC with TLS using length-prefixed protobuf.
func NewQUICTransport ¶
func NewQUICTransport(ctx context.Context, cfg *Config) (*QUICTransport, error)
NewQUICTransport creates a new QUIC transport to the Geode server.
func (*QUICTransport) IsClosed ¶
func (t *QUICTransport) IsClosed() bool
IsClosed returns true if the transport is closed.
func (*QUICTransport) ReceiveProto ¶
func (t *QUICTransport) ReceiveProto(ctx context.Context) (*proto.QuicServerMessage, error)
ReceiveProto reads a length-prefixed protobuf message from the server. Note: This is a blocking call. Use context deadline for timeout control.
func (*QUICTransport) SendProto ¶
func (t *QUICTransport) SendProto(ctx context.Context, msg *proto.QuicClientMessage) error
SendProto writes a length-prefixed protobuf message to the server.
func (*QUICTransport) TryReceiveProtoBuffered ¶
func (t *QUICTransport) TryReceiveProtoBuffered() (*proto.QuicServerMessage, bool, error)
TryReceiveProtoBuffered reads a complete protobuf message if enough data is buffered. This avoids blocking when probing for inline frames.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result represents the result of an Exec query.
func (*Result) LastInsertId ¶
LastInsertId returns the last insert ID. Note: Geode doesn't support auto-increment IDs in the traditional sense, so this always returns 0.
func (*Result) RowsAffected ¶
RowsAffected returns the number of rows affected. Note: Geode doesn't always provide this information, so this may return 0 even when rows were affected.
type Rows ¶
type Rows struct {
// contains filtered or unexported fields
}
Rows represents a result set from a query.
func (*Rows) ColumnTypeDatabaseTypeName ¶
ColumnTypeDatabaseTypeName returns the database type name for a column.
func (*Rows) ColumnTypeNullable ¶
ColumnTypeNullable reports whether a column may be null.
func (*Rows) ColumnTypeScanType ¶
ColumnTypeScanType returns the Go type suitable for scanning.
type SecurityError ¶
type SecurityError struct {
Type string // Error type: "tls", "input", "validation"
Message string // Error message
// contains filtered or unexported fields
}
SecurityError represents security validation failures.
func (*SecurityError) Error ¶
func (e *SecurityError) Error() string
Error implements the error interface.
func (*SecurityError) IsRetryable ¶
func (e *SecurityError) IsRetryable() bool
IsRetryable indicates if the operation can be retried.
func (*SecurityError) StatusClass ¶
func (e *SecurityError) StatusClass() string
StatusClass returns the status class.
func (*SecurityError) Unwrap ¶
func (e *SecurityError) Unwrap() error
Unwrap returns the underlying cause.
type StateError ¶
type StateError struct {
Current ConnState // Current state
Expected ConnState // Expected state (if applicable)
Op string // Operation attempted
Message string // Additional message
}
StateError represents invalid connection state transitions.
func (*StateError) Error ¶
func (e *StateError) Error() string
Error implements the error interface.
func (*StateError) IsRetryable ¶
func (e *StateError) IsRetryable() bool
IsRetryable indicates if the operation can be retried.
func (*StateError) StatusClass ¶
func (e *StateError) StatusClass() string
StatusClass returns the status class.
type Stmt ¶
type Stmt struct {
// contains filtered or unexported fields
}
Stmt represents a prepared statement. Note: Geode doesn't have server-side prepared statements, so this is a client-side implementation that stores the query and validates parameters.
func (*Stmt) ExecContext ¶
ExecContext executes a query that doesn't return rows.
func (*Stmt) QueryContext ¶
QueryContext executes a query that returns rows.
type Transport ¶
type Transport interface {
// SendProto writes a protobuf message to the server.
SendProto(ctx context.Context, msg *proto.QuicClientMessage) error
// ReceiveProto reads a protobuf message from the server.
ReceiveProto(ctx context.Context) (*proto.QuicServerMessage, error)
// TryReceiveProtoBuffered reads a message only if enough data is already buffered.
// Returns (nil, false, nil) when no complete message is buffered.
TryReceiveProtoBuffered() (*proto.QuicServerMessage, bool, error)
// Close closes the transport.
Close() error
// IsClosed returns true if the transport is closed.
IsClosed() bool
// Addr returns the remote address.
Addr() string
}
Transport defines the interface for communication with a Geode server.
type TransportError ¶
type TransportError struct {
Op string // Operation that failed
Addr string // Remote address (if applicable) - see Security Note above
// contains filtered or unexported fields
}
TransportError represents transport-layer failures.
Security Note: The Addr field contains the remote server address for diagnostic purposes. When logging errors to public locations (e.g., client telemetry, user-facing UI), callers should sanitize or omit this field to prevent internal network topology disclosure. For internal logs and debugging, the full address is valuable for troubleshooting.
func (*TransportError) Error ¶
func (e *TransportError) Error() string
Error implements the error interface.
func (*TransportError) IsRetryable ¶
func (e *TransportError) IsRetryable() bool
IsRetryable indicates if the operation can be retried.
func (*TransportError) StatusClass ¶
func (e *TransportError) StatusClass() string
StatusClass returns the status class (always system error for transport).
func (*TransportError) Temporary ¶
func (e *TransportError) Temporary() bool
Temporary indicates if this is a temporary error.
func (*TransportError) Unwrap ¶
func (e *TransportError) Unwrap() error
Unwrap returns the underlying cause.
type TransportType ¶
type TransportType int
TransportType specifies the transport protocol to use.
const ( // TransportQUIC uses QUIC transport with TLS 1.3 (default). TransportQUIC TransportType = iota // TransportGRPC uses gRPC transport. TransportGRPC )
func (TransportType) String ¶
func (t TransportType) String() string
String returns the string representation of the transport type.
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx represents a database transaction.
type UnsupportedSchemeError ¶
type UnsupportedSchemeError struct {
Scheme string
}
UnsupportedSchemeError is returned when an unsupported DSN scheme is used.
func (*UnsupportedSchemeError) Error ¶
func (e *UnsupportedSchemeError) Error() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
benchmark
command
Native Go client benchmark for Geode
|
Native Go client benchmark for Geode |
|
internal
|
|
|
validate
Package validate provides input validation utilities.
|
Package validate provides input validation utilities. |
|
Package proto provides protobuf message types and gRPC client for Geode.
|
Package proto provides protobuf message types and gRPC client for Geode. |