forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support session settings in a separate subpackage "settings" [1]. It allows to create a specific requests to get or set session settings. Settings are independent for each connection. 1. https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/_session_settings/ Closes #215
- Loading branch information
1 parent
3a1e82b
commit 404772c
Showing
11 changed files
with
1,138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package settings | ||
|
||
const sessionSettingsSpace string = "_session_settings" | ||
|
||
// In Go and IPROTO_UPDATE count starts with 0. | ||
const sessionSettingValueField int = 1 | ||
|
||
const ( | ||
errorMarshalingEnabled string = "error_marshaling_enabled" | ||
sqlDefaultEngine string = "sql_default_engine" | ||
sqlDeferForeignKeys string = "sql_defer_foreign_keys" | ||
sqlFullColumnNames string = "sql_full_column_names" | ||
sqlFullMetadata string = "sql_full_metadata" | ||
sqlParserDebug string = "sql_parser_debug" | ||
sqlRecursiveTriggers string = "sql_recursive_triggers" | ||
sqlReverseUnorderedSelects string = "sql_reverse_unordered_selects" | ||
sqlSelectDebug string = "sql_select_debug" | ||
sqlVDBEDebug string = "sql_vdbe_debug" | ||
) | ||
|
||
const selectAllLimit uint32 = 1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package settings_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tarantool/go-tarantool" | ||
"github.com/tarantool/go-tarantool/settings" | ||
"github.com/tarantool/go-tarantool/test_helpers" | ||
) | ||
|
||
func example_connect(opts tarantool.Opts) *tarantool.Connection { | ||
conn, err := tarantool.Connect(server, opts) | ||
if err != nil { | ||
panic("Connection is not established: " + err.Error()) | ||
} | ||
return conn | ||
} | ||
|
||
func Example_sqlFullColumnNames() { | ||
var resp *tarantool.Response | ||
var err error | ||
var isLess bool | ||
|
||
conn := example_connect(opts) | ||
defer conn.Close() | ||
|
||
// Tarantool supports session settings since version 2.3.1 | ||
isLess, err = test_helpers.IsTarantoolVersionLess(2, 3, 1) | ||
if err != nil || isLess { | ||
return | ||
} | ||
|
||
// Create a space. | ||
_, err = conn.Execute("CREATE TABLE example(id INT PRIMARY KEY, x INT);", []interface{}{}) | ||
if err != nil { | ||
fmt.Printf("error in create table: %v\n", err) | ||
return | ||
} | ||
|
||
// Insert some tuple into space. | ||
_, err = conn.Execute("INSERT INTO example VALUES (1, 1);", []interface{}{}) | ||
if err != nil { | ||
fmt.Printf("error on insert: %v\n", err) | ||
return | ||
} | ||
|
||
// Enable showing full column names in SQL responses. | ||
_, err = conn.Do(settings.NewSQLFullColumnNamesSetRequest(true)).Get() | ||
if err != nil { | ||
fmt.Printf("error on setting setup: %v\n", err) | ||
return | ||
} | ||
|
||
// Get some data with SQL query. | ||
resp, err = conn.Execute("SELECT x FROM example WHERE id = 1;", []interface{}{}) | ||
if err != nil { | ||
fmt.Printf("error on select: %v\n", err) | ||
return | ||
} | ||
// Show response metadata. | ||
fmt.Printf("full column name: %v\n", resp.MetaData[0].FieldName) | ||
|
||
// Disable showing full column names in SQL responses. | ||
_, err = conn.Do(settings.NewSQLFullColumnNamesSetRequest(false)).Get() | ||
if err != nil { | ||
fmt.Printf("error on setting setup: %v\n", err) | ||
return | ||
} | ||
|
||
// Get some data with SQL query. | ||
resp, err = conn.Execute("SELECT x FROM example WHERE id = 1;", []interface{}{}) | ||
if err != nil { | ||
fmt.Printf("error on select: %v\n", err) | ||
return | ||
} | ||
// Show response metadata. | ||
fmt.Printf("short column name: %v\n", resp.MetaData[0].FieldName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//go:build !go_tarantool_msgpack_v5 | ||
// +build !go_tarantool_msgpack_v5 | ||
|
||
package settings | ||
|
||
import ( | ||
"gopkg.in/vmihailenco/msgpack.v2" | ||
) | ||
|
||
type encoder = msgpack.Encoder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//go:build go_tarantool_msgpack_v5 | ||
// +build go_tarantool_msgpack_v5 | ||
|
||
package settings | ||
|
||
import ( | ||
"github.com/vmihailenco/msgpack/v5" | ||
) | ||
|
||
type encoder = msgpack.Encoder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.