sql

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Example
client, err := hazelcast.StartNewClient(context.TODO())
if err != nil {
	panic(err)
}
sqlService := client.SQL()
stmt := sql.NewStatement(`SELECT name, age FROM person WHERE age >= ?`, 30)
err = stmt.SetCursorBufferSize(1000)
if err != nil {
	panic(err)
}
result, err := sqlService.ExecuteStatement(context.TODO(), stmt)
if err != nil {
	panic(err)
}
defer result.Close()
it, err := result.Iterator()
if err != nil {
	panic(err)
}
var name string
var age int
for it.HasNext() {
	row, err := it.Next()
	if err != nil {
		panic(err)
	}
	v1, err := row.Get(0)
	if err != nil {
		panic(err)
	}
	v2, err := row.Get(1)
	if err != nil {
		panic(err)
	}
	name, age = v1.(string), v2.(int)
	fmt.Println(name, age)
}
Output:

Index

Examples

Constants

View Source
const (
	ExpectedResultTypeAny         = ExpectedResultType(0)
	ExpectedResultTypeRows        = ExpectedResultType(1)
	ExpectedResultTypeUpdateCount = ExpectedResultType(2)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnMetadata

type ColumnMetadata interface {
	Name() string
	Type() ColumnType
	Nullable() bool
}

ColumnMetadata SQL column metadata.

type ColumnType

type ColumnType int32

ColumnType SQL column type.

const (
	ColumnTypeVarchar               ColumnType = 0
	ColumnTypeBoolean               ColumnType = 1
	ColumnTypeTinyInt               ColumnType = 2
	ColumnTypeSmallInt              ColumnType = 3
	ColumnTypeInt                   ColumnType = 4
	ColumnTypeBigInt                ColumnType = 5
	ColumnTypeDecimal               ColumnType = 6
	ColumnTypeReal                  ColumnType = 7
	ColumnTypeDouble                ColumnType = 8
	ColumnTypeDate                  ColumnType = 9
	ColumnTypeTime                  ColumnType = 10
	ColumnTypeTimestamp             ColumnType = 11
	ColumnTypeTimestampWithTimeZone ColumnType = 12
	ColumnTypeObject                ColumnType = 13
	ColumnTypeNull                  ColumnType = 14
	ColumnTypeJSON                  ColumnType = 15
)

type Error

type Error struct {
	Message             string
	Suggestion          string
	OriginatingMemberId types.UUID
	Code                int32
}

Error is a server-side error that is propagated to the client.

func (Error) Error

func (e Error) Error() string

type ExpectedResultType

type ExpectedResultType byte

ExpectedResultType represents the expected statement result type.

type Result

type Result interface {
	// RowMetadata returns metadata information about rows.
	// An error is returned if result represents an update count.
	RowMetadata() (RowMetadata, error)
	// IsRowSet returns whether this result has rows to iterate using the HasNext method.
	IsRowSet() bool
	// UpdateCount returns the number of rows updated by the statement or -1 if this result is a row set.
	UpdateCount() int64
	// Iterator returns the RowsIterator over the result rows.
	// The iterator may be requested only once.
	// An error is returned if the iterator is requested more than once, or if the result contains only update count.
	Iterator() (RowsIterator, error)
	// Close notifies the member to release resources for the corresponding query for results that represents a stream of rows.
	// It can be safely called more than once, and it is concurrency-safe.
	// If result represents an update count, it has no effect.
	Close() error
}

Result represents a query result. Depending on the statement type it represents a stream of rows or an update count. It is not concurrency-safe except the Close and Iterator method.

type Row

type Row interface {
	// Get returns the value of the column by index.
	// If index is out of range, an error is returned.
	Get(index int) (interface{}, error)
	// GetByColumnName returns the value of the column by name.
	// If columns does not exist, an error is returned.
	GetByColumnName(name string) (interface{}, error)
	// Metadata returns the metadata information about the row.
	Metadata() RowMetadata
}

Row represents an SQL result row.

type RowMetadata

type RowMetadata interface {
	GetColumn(index int) (ColumnMetadata, error)
	FindColumn(columnName string) (int, error)
	ColumnCount() int
	Columns() []ColumnMetadata
}

RowMetadata represents SQL row metadata.

type RowsIterator

type RowsIterator interface {
	// HasNext prepares the next result row for reading via Next method.
	// It returns true on success, or false if there is no next result row or an error happened while preparing it.
	HasNext() bool
	// Next returns the current row.
	// Every call to Next, even the first one, must be preceded by a call to HasNext.
	Next() (Row, error)
}

RowsIterator provides means to iterate over SQL statement result. It is not concurrency-safe.

type Service

type Service interface {
	// ExecuteStatement executes the given SQL Statement.
	ExecuteStatement(ctx context.Context, stmt Statement) (Result, error)
	// Execute is a convenience method to execute a distributed query with the given parameter values.
	// You may define parameter placeholders in the query with the "?" character.
	// For every placeholder, a value must be provided.
	Execute(ctx context.Context, query string, params ...interface{}) (Result, error)
}

Service represents the SQL service.

type Statement

type Statement struct {
	// contains filtered or unexported fields
}

Statement represents an SQL Statement. Use NewStatement to benefit from the default settings. Fields are read once before the execution is started. Changes to fields do not affect the behavior of already running statements.

func NewStatement

func NewStatement(statement string, params ...interface{}) Statement

NewStatement returns a new sql Statement with provided arguments You may define parameter placeholders in the Statement with the "?" character. For every placeholder, a value must be provided in 'params'.

func (*Statement) AddParameter

func (s *Statement) AddParameter(param interface{})

AddParameter adds a single parameter value to the end of the parameter values slice.

func (*Statement) ClearParameters

func (s *Statement) ClearParameters()

ClearParameters clears statement parameter values.

func (*Statement) CursorBufferSize

func (s *Statement) CursorBufferSize() int32

CursorBufferSize returns the cursor buffer size (measured in the number of rows).

func (*Statement) ExpectedResultType

func (s *Statement) ExpectedResultType() ExpectedResultType

ExpectedResultType returns ExpectedResultType.

func (*Statement) Parameters

func (s *Statement) Parameters() []interface{}

Parameters returns the statement parameter values.

func (Statement) QueryTimeout

func (s Statement) QueryTimeout() int64

QueryTimeout returns the execution timeout in milliseconds. -1 means timeout is not set and member configuration SqlConfig#setStatementTimeoutMillis will be respected.

func (*Statement) SQL

func (s *Statement) SQL() string

SQL returns the SQL string to be executed.

func (*Statement) Schema

func (s *Statement) Schema() string

Schema returns the schema name.

func (*Statement) SetCursorBufferSize

func (s *Statement) SetCursorBufferSize(cbs int) error

SetCursorBufferSize sets the query cursor buffer size. When rows are ready to be consumed, they are put into an internal buffer of the cursor. This parameter defines the maximum number of rows in that buffer. When the threshold is reached, the backpressure mechanism will slow down the execution, possibly to a complete halt, to prevent out-of-memory. The default value is expected to work well for most workloads. A bigger buffer size may give you a slight performance boost for queries with large result sets at the cost of increased memory consumption. Defaults to 4096. The given buffer size must be in the non-negative int32 range.

func (*Statement) SetExpectedResultType

func (s *Statement) SetExpectedResultType(resultType ExpectedResultType) error

SetExpectedResultType sets the expected result type. Returns an error if parameter is not one of ExpectedResultTypeAny, ExpectedResultTypeRows or ExpectedResultTypeUpdateCount.

func (*Statement) SetParameters

func (s *Statement) SetParameters(params ...interface{})

SetParameters sets the values for statement parameters. You may define parameter placeholders in the SQL statement with the "?" character. For every placeholder, a value must be provided.

func (*Statement) SetQueryTimeout

func (s *Statement) SetQueryTimeout(t time.Duration)

SetQueryTimeout sets the query execution timeout. If the timeout is reached for a running Statement, it will be cancelled forcefully. Zero value means no timeout. Negative values mean that the value from the server-side config will be used. Defaults to -1.

func (*Statement) SetSQL

func (s *Statement) SetSQL(statement string) error

SetSQL Sets the SQL string to be executed. Returns an error if statement is empty string.

func (*Statement) SetSchema

func (s *Statement) SetSchema(schema string)

SetSchema sets the schema name. The engine will try to resolve the non-qualified object identifiers from the Statement in the given schema. If not found, the default search path will be used. The schema name is case-sensitive. For example, foo and Foo are different schemas. By default, only the default search path is used, which looks for objects in the predefined schemas "partitioned" and "public".

Directories

Path Synopsis
Package driver provides a standard database/sql compatible SQL driver for Hazelcast.
Package driver provides a standard database/sql compatible SQL driver for Hazelcast.

Jump to

Keyboard shortcuts

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