-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconsole.go
53 lines (44 loc) · 1.48 KB
/
console.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/rs/zerolog/pkgerrors"
"github.com/tarantool/go-tarantool"
)
func main() {
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack //nolint: reassign
log.Logger = log.With().Stack().Logger()
if err := doMain(); err != nil {
log.Fatal().Err(err).Send()
}
}
// Tarantella testing tool
// feel free to add some useful stuff here
func doMain() error {
// actually tarantella doesn't check password, and username used for directory, where data files are stored
opts := tarantool.Opts{User: "user", Pass: "DSoXbver3p4bbMK6dGhUfo"}
conn, err := tarantool.Connect("127.0.0.1:3302", opts)
if err != nil {
return err
}
log.Info().Any("greeting", conn.Greeting).Msg("Greeting received")
// not so important, but ping
r, err := conn.Ping()
log.Error().Err(err).Uint32("res", r.Code).Msg("Ping successfully")
// execute
resp, err := conn.Execute(`select * from things`, []interface{}{})
log.Info().Err(err).Any("resp", resp).Msg("Prepared")
// insert
resp, err = conn.Insert("tester", []any{"assd", "ABBA", 1972})
// resp, err := conn.Insert("tester", []any{5, "Lord Huron", 2020})
if err != nil {
log.Error().Err(err).Msg("Insert failed")
}
log.Info().Any("response", resp).Msg("Insert")
resp, err = conn.Select("tester", "secondary", 0, 1, tarantool.IterEq, []any{"ABBA"})
if err != nil {
log.Error().Err(err).Msg("Select failed")
}
log.Info().Any("response", resp).Msg("Select")
return nil
}