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 ¶
- Constants
- type ColumnMetadata
- type ColumnType
- type Error
- type ExpectedResultType
- type Result
- type Row
- type RowMetadata
- type RowsIterator
- type Service
- type Statement
- func (s *Statement) AddParameter(param interface{})
- func (s *Statement) ClearParameters()
- func (s *Statement) CursorBufferSize() int32
- func (s *Statement) ExpectedResultType() ExpectedResultType
- func (s *Statement) Parameters() []interface{}
- func (s Statement) QueryTimeout() int64
- func (s *Statement) SQL() string
- func (s *Statement) Schema() string
- func (s *Statement) SetCursorBufferSize(cbs int) error
- func (s *Statement) SetExpectedResultType(resultType ExpectedResultType) error
- func (s *Statement) SetParameters(params ...interface{})
- func (s *Statement) SetQueryTimeout(t time.Duration)
- func (s *Statement) SetSQL(statement string) error
- func (s *Statement) SetSchema(schema string)
Examples ¶
Constants ¶
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 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 ¶
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 ¶
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 ¶
QueryTimeout returns the execution timeout in milliseconds. -1 means timeout is not set and member configuration SqlConfig#setStatementTimeoutMillis will be respected.
func (*Statement) SetCursorBufferSize ¶
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 ¶
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 ¶
SetSQL Sets the SQL string to be executed. Returns an error if statement is empty string.
func (*Statement) SetSchema ¶
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".