tarantool/go-tarantool

OverrideSchema not working as expected

verybadcoder01 opened this issue · 3 comments

I'm trying to create space with indexes and everything with my go application. At firtst I tried doing this by calling lua functions directly via tarantool.Call(), but that's just painful, so I looked around and found OverrideSchema() function. Unfortunately, I could not find any documentation for it. I wrote some code:

s.conn.OverrideSchema(&tarantool.Schema{
		Version: 1,
		Spaces: map[string]*tarantool.Space{
			"messages": {
				Name: "messages", Id: 1,
				Fields: map[string]*tarantool.Field{
					"time":  {Name: "time", Id: 1, Type: "datetime", IsNullable: false},
					"value": {Name: "value", Id: 2, Type: "string", IsNullable: false},
				},
				Indexes: map[string]*tarantool.Index{
					"primary": {
						Name: "primary", SpaceId: 1, Unique: false,
						Fields: []*tarantool.IndexField{{Id: 1, Type: "datetime"}},
					},
				},
			},
		},
	})

This doesn't seem to do anything. At least, it doesn't create a space in tarantool (and that's what I want). What am I missing? Do I have to stick with direct function calling approach?

The connector does not support an automatic schema reload after a space/index creation: #7 .

So you need:

  1. Create a space with Call().
  2. Create an index with Call().
  3. Create a new connection and work with it to make requests to the space/index.

The OverrideSchema method just overwrites a schema data from a Tarantool instance. It does not create any space/index. It does not modify a schema data on the Tarantool instance. You could to skip creating a new connection (step 3) after a space/index creation with the method.

Thank you, I get it now. I guess this doesn't relate to this issue, but that's just something I also couldn't find an answer for. How to marshall time.Time into tarantool datetime field? I have a struct like

type Tuple struct {
	_msgpack struct{}  `msgpack:",asArray"` //nolint // that's the doc
	Value    string   
	Time     time.Time
}

And throwing it into insert query gives me "Tuple field 2 (time) type does not match one required by operation: expected datetime, got extension"
Do I have to use msgpack:"something" for this?

Thank you, I get it now. I guess this doesn't relate to this issue, but that's just something I also couldn't find an answer for. How to marshall time.Time into tarantool datetime field?

You need to use github.com/tarantool/go-tarantool/datetime subpackage and Datetime type instead of time.Time, see examples.