Skip to content

Commit

Permalink
rework draft
Browse files Browse the repository at this point in the history
  • Loading branch information
DifferentialOrange committed Dec 13, 2022
1 parent d2141b7 commit 31a1af1
Show file tree
Hide file tree
Showing 8 changed files with 855 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ test-uuid:
go clean -testcache
go test -tags "$(TAGS)" ./uuid/ -v -p 1

.PHONY: test-settings
test-settings:
@echo "Running tests in settings package"
go clean -testcache
go test -tags "$(TAGS)" ./settings/ -v -p 1

.PHONY: test-main
test-main:
@echo "Running tests in main package"
Expand Down
15 changes: 15 additions & 0 deletions settings/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Do not set listen for now so connector won't be
-- able to send requests until everything is configured.
box.cfg{
work_dir = os.getenv("TEST_TNT_WORK_DIR"),
}

box.schema.user.create('test', { password = 'test' , if_not_exists = true })
box.schema.user.grant('test', 'execute', 'universe', nil, { if_not_exists = true })
box.schema.user.grant('test', 'create,read,write,drop,alter', 'space', nil, { if_not_exists = true })
box.schema.user.grant('test', 'create', 'sequence', nil, { if_not_exists = true })

-- Set listen only when every other thing is configured.
box.cfg{
listen = os.getenv("TEST_TNT_LISTEN"),
}
48 changes: 48 additions & 0 deletions settings/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package settings

const sessionSettingsSpace string = "_session_settings"

// In Go and IPROTO_UPDATE count starts with 0.
const sessionSettingValueField int = 1

const (
// ErrorMarshalingEnabled defines whether error objects
// have a special structure. Added in Tarantool 2.4.1, dropped
// in Tarantool 2.10.0 in favor of ErrorExtensionFeature protocol
// feature. Default is `false`.
ErrorMarshalingEnabled string = "error_marshaling_enabled"
// SQLDefaultEngine defined default storage engine for
// new SQL tables. Added in Tarantool 2.3.1. Default is `"memtx"`.
SQLDefaultEngine string = "sql_default_engine"
// SQLDeferForeignKeys defines whether foreign-key checks
// can wait till commit. Added in Tarantool 2.3.1, dropped
// in master commit 14618c4 (possible 2.10.5 or 2.11.0). Default is `false`.
SQLDeferForeignKeys string = "sql_defer_foreign_keys"
// SQLFullColumnNames defines whether full column names is displayed
// in SQL result set metadata. Added in Tarantool 2.3.1. Default is `false`.
SQLFullColumnNames string = "sql_full_column_names"
// SQLFullMetadata defines whether SQL result set metadata will have
// more than just name and type. Added in Tarantool 2.3.1. Default is `false`.
SQLFullMetadata string = "sql_full_metadata"
// SQLParserDebug defines whether to show parser steps for following
// statements. Option has no effect unless Tarantool was built with
// `-DCMAKE_BUILD_TYPE=Debug`. Added in Tarantool 2.3.1. Default is `false`.
SQLParserDebug string = "sql_parser_debug"
// SQLParserDebug defines whether a triggered statement can activate
// a trigger. Added in Tarantool 2.3.1. Default is `true`.
SQLRecursiveTriggers string = "sql_recursive_triggers"
// SQLReverseUnorderedSelects defines whether result rows are usually
// in reverse order if there is no ORDER BY clause. Added in Tarantool 2.3.1.
// Default is `false`.
SQLReverseUnorderedSelects string = "sql_reverse_unordered_selects"
// SQLSelectDebug defines whether to show execution steps during SELECT.
// Option has no effect unless Tarantool was built with `-DCMAKE_BUILD_TYPE=Debug`.
// Added in Tarantool 2.3.1. Default is `false`.
SQLSelectDebug string = "sql_select_debug"
// SQLVDBEDebug defines whether VDBE debug mode is enabled.
// Option has no effect unless Tarantool was built with `-DCMAKE_BUILD_TYPE=Debug`.
// Added in Tarantool 2.3.1. Default is `false`.
SQLVDBEDebug string = "sql_vdbe_debug"
)

const selectAllLimit uint32 = 1000
13 changes: 13 additions & 0 deletions settings/msgpack_helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build !go_tarantool_msgpack_v5
// +build !go_tarantool_msgpack_v5

package settings_test

import (
"github.com/tarantool/go-tarantool"
)

func toBoxError(i interface{}) (v tarantool.BoxError, ok bool) {
v, ok = i.(tarantool.BoxError)
return
}
16 changes: 16 additions & 0 deletions settings/msgpack_v5_helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build go_tarantool_msgpack_v5
// +build go_tarantool_msgpack_v5

package settings_test

import (
"github.com/tarantool/go-tarantool"
)

func toBoxError(i interface{}) (v tarantool.BoxError, ok bool) {
var ptr *tarantool.BoxError
if ptr, ok = i.(*tarantool.BoxError); ok {
v = *ptr
}
return
}
162 changes: 162 additions & 0 deletions settings/request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package settings

import (
"github.com/tarantool/go-tarantool"
)

func newSetRequest(setting string, value interface{}) *tarantool.UpdateRequest {
return tarantool.NewUpdateRequest(sessionSettingsSpace).
Key(tarantool.StringKey{setting}).
Operations(tarantool.NewOperations().Assign(sessionSettingValueField, value))
}

func newGetRequest(setting string) *tarantool.SelectRequest {
return tarantool.NewSelectRequest(sessionSettingsSpace).
Key(tarantool.StringKey{setting}).
Limit(1)
}

// SetErrorMarshalingEnabled creates a request to
// update current session ErrorMarshalingEnabled setting.
// Added in 1.10.0.
func SetErrorMarshalingEnabled(value bool) *tarantool.UpdateRequest {
return newSetRequest(ErrorMarshalingEnabled, value)
}

// GetErrorMarshalingEnabled creates a request to get
// current session ErrorMarshalingEnabled setting in tuple format.
// Added in 1.10.0.
func GetErrorMarshalingEnabled() *tarantool.SelectRequest {
return newGetRequest(ErrorMarshalingEnabled)
}

// SetSQLDefaultEngine creates a request to
// update current session SQLDefaultEngine setting.
// Added in 1.10.0.
func SetSQLDefaultEngine(value string) *tarantool.UpdateRequest {
return newSetRequest(SQLDefaultEngine, value)
}

// GetSQLDefaultEngine creates a request to get
// current session SQLDefaultEngine setting in tuple format.
// Added in 1.10.0.
func GetSQLDefaultEngine() *tarantool.SelectRequest {
return newGetRequest(SQLDefaultEngine)
}

// SetSQLDeferForeignKeys creates a request to
// update current session SQLDeferForeignKeys setting.
// Added in 1.10.0.
func SetSQLDeferForeignKeys(value bool) *tarantool.UpdateRequest {
return newSetRequest(SQLDeferForeignKeys, value)
}

// GetSQLDeferForeignKeys creates a request to get
// current session SQLDeferForeignKeys setting in tuple format.
// Added in 1.10.0.
func GetSQLDeferForeignKeys() *tarantool.SelectRequest {
return newGetRequest(SQLDeferForeignKeys)
}

// SetSQLFullColumnNames creates a request to
// update current session SQLFullColumnNames setting.
// Added in 1.10.0.
func SetSQLFullColumnNames(value bool) *tarantool.UpdateRequest {
return newSetRequest(SQLFullColumnNames, value)
}

// GetSQLFullColumnNames creates a request to get
// current session SQLFullColumnNames setting in tuple format.
// Added in 1.10.0.
func GetSQLFullColumnNames() *tarantool.SelectRequest {
return newGetRequest(SQLFullColumnNames)
}

// SetSQLFullMetadata creates a request to
// update current session SQLFullMetadata setting.
// Added in 1.10.0.
func SetSQLFullMetadata(value bool) *tarantool.UpdateRequest {
return newSetRequest(SQLFullMetadata, value)
}

// GetSQLFullMetadata creates a request to get
// current session SQLFullMetadata setting in tuple format.
// Added in 1.10.0.
func GetSQLFullMetadata() *tarantool.SelectRequest {
return newGetRequest(SQLFullMetadata)
}

// SetSQLParserDebug creates a request to
// update current session SQLParserDebug setting.
// Added in 1.10.0.
func SetSQLParserDebug(value bool) *tarantool.UpdateRequest {
return newSetRequest(SQLParserDebug, value)
}

// GetSQLParserDebug creates a request to get
// current session SQLParserDebug setting in tuple format.
// Added in 1.10.0.
func GetSQLParserDebug() *tarantool.SelectRequest {
return newGetRequest(SQLParserDebug)
}

// SetSQLRecursiveTriggers creates a request to
// update current session SQLRecursiveTriggers setting.
// Added in 1.10.0.
func SetSQLRecursiveTriggers(value bool) *tarantool.UpdateRequest {
return newSetRequest(SQLRecursiveTriggers, value)
}

// GetSQLRecursiveTriggers creates a request to get
// current session SQLRecursiveTriggers setting in tuple format.
// Added in 1.10.0.
func GetSQLRecursiveTriggers() *tarantool.SelectRequest {
return newGetRequest(SQLRecursiveTriggers)
}

// SetSQLReverseUnorderedSelects creates a request to
// update current session SQLReverseUnorderedSelects setting.
// Added in 1.10.0.
func SetSQLReverseUnorderedSelects(value bool) *tarantool.UpdateRequest {
return newSetRequest(SQLReverseUnorderedSelects, value)
}

// GetSQLReverseUnorderedSelects creates a request to get
// current session SQLReverseUnorderedSelects setting in tuple format.
// Added in 1.10.0.
func GetSQLReverseUnorderedSelects() *tarantool.SelectRequest {
return newGetRequest(SQLReverseUnorderedSelects)
}

// SetSQLSelectDebug creates a request to
// update current session SQLSelectDebug setting.
// Added in 1.10.0.
func SetSQLSelectDebug(value bool) *tarantool.UpdateRequest {
return newSetRequest(SQLSelectDebug, value)
}

// GetSQLSelectDebug creates a request to get
// current session SQLSelectDebug setting in tuple format.
// Added in 1.10.0.
func GetSQLSelectDebug() *tarantool.SelectRequest {
return newGetRequest(SQLSelectDebug)
}

// SetSQLVDBEDebug creates a request to
// update current session SQLVDBEDebug setting.
// Added in 1.10.0.
func SetSQLVDBEDebug(value bool) *tarantool.UpdateRequest {
return newSetRequest(SQLVDBEDebug, value)
}

// GetSQLVDBEDebug creates a request to get
// current session SQLVDBEDebug setting in tuple format.
// Added in 1.10.0.
func GetSQLVDBEDebug() *tarantool.SelectRequest {
return newGetRequest(SQLVDBEDebug)
}

func GetSession() *tarantool.SelectRequest {
return tarantool.NewSelectRequest(sessionSettingsSpace).
Limit(selectAllLimit)
}
Loading

0 comments on commit 31a1af1

Please sign in to comment.