Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OverrideSchema not working as expected #318

Closed
verybadcoder01 opened this issue Jul 21, 2023 · 3 comments
Closed

OverrideSchema not working as expected #318

verybadcoder01 opened this issue Jul 21, 2023 · 3 comments
Labels
question Further information is requested teamE

Comments

@verybadcoder01
Copy link

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?

@oleg-jukovec oleg-jukovec added question Further information is requested teamE labels Jul 21, 2023
@oleg-jukovec
Copy link
Collaborator

oleg-jukovec commented Jul 21, 2023

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.

@verybadcoder01
Copy link
Author

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?

@oleg-jukovec
Copy link
Collaborator

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.

askalt added a commit that referenced this issue Nov 17, 2023
This patch modifies `Connect` api.

Now, to connect to the Tarantool, you need to pass an
object that satisfies `tarantool.Dialer` interface.

You can use one of the existing implementations:
`TtDialer` or `OpenSslDialer`.

For example:
```
conn, err := tarantool.Connect(context.Background(), tarantool.TtDialer{
	Address:  "127.0.0.1:3301",
	User:     "user",
	Password: "secret",
}, tarantool.Opts{})
```

To create a connection pool, you need to pass a `map[string]tarantool.Dialer`,
where each dialer is associated with a unique ID (for example, it can be
the server address). Connections will be distinguished from each other using
these IDs.

For example:
```
connPool, err := pool.Connect(context.Background(), map[string]tarantool.Dialer{
	"127.0.0.1": tarantool.TtDialer{
		Address:  "127.0.0.1",
		User:     "user",
		Password: "secret",
	},
}, tarantool.Opts{})
```

The `conn.RemoteAddr` and `conn.LocalAddr` functions have been removed.
To obtain the connection address, you can use `conn.Addr`. This function
panics if the connection has not been established.

Now, `NewWatcher` checks the actual features of the server, rather than relying
on the features provided by the user during connection creation.

In the case of connection pool, watchers are created for connections that support
this feature.

`ClientProtocolInfo`, `ServerProtocolInfo` were removed. Now, there is `ProtocolInfo`,
which returns the server protocol info.

Part of #318
askalt added a commit that referenced this issue Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested teamE
Projects
None yet
Development

No branches or pull requests

2 participants