Skip to content

Datetime docs? #280

New issue

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

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

Already on GitHub? # to your account

Open
zachgrayio opened this issue Apr 2, 2023 · 3 comments
Open

Datetime docs? #280

zachgrayio opened this issue Apr 2, 2023 · 3 comments
Labels
doc Related to documentation good first issue Good for newcomers

Comments

@zachgrayio
Copy link

zachgrayio commented Apr 2, 2023

given schema

box.schema.space.create('some_space', {
    format = {
        {name = 'somedate', type = 'datetime'},
        ... 
    }
})

trying to write some data with the go driver gets me:

Tuple field 13 (somedate) type does not match one required by operation: expected datetime, got string

changing the schema to type = 'string' and it seems to just work fine, so I assume either the datetime package isn't functioning as expected, and again there's no docs or full examples. is this expected? am I doing something wrong? can we get some docs created someday?

@zachgrayio zachgrayio changed the title Datetime doesnt seem to work as expected and theres no docs Datetime docs? Apr 2, 2023
@oleg-jukovec
Copy link
Collaborator

oleg-jukovec commented Apr 2, 2023

Hello, could you please provide a reproducer with the connector code?

There is an example:

https://pkg.go.dev/github.com/tarantool/go-tarantool@v1.10.0/datetime#example-package

func Example() {
opts := tarantool.Opts{
User: "test",
Pass: "test",
}
conn, err := tarantool.Connect("127.0.0.1:3013", opts)
if err != nil {
fmt.Printf("Error in connect is %v", err)
return
}
var datetime = "2013-10-28T17:51:56.000000009Z"
tm, err := time.Parse(time.RFC3339, datetime)
if err != nil {
fmt.Printf("Error in time.Parse() is %v", err)
return
}
dt, err := NewDatetime(tm)
if err != nil {
fmt.Printf("Unable to create Datetime from %s: %s", tm, err)
return
}
space := "testDatetime_1"
index := "primary"
// Replace a tuple with datetime.
resp, err := conn.Replace(space, []interface{}{dt})
if err != nil {
fmt.Printf("Error in replace is %v", err)
return
}
respDt := resp.Data[0].([]interface{})[0].(Datetime)
fmt.Println("Datetime tuple replace")
fmt.Printf("Code: %d\n", resp.Code)
fmt.Printf("Data: %v\n", respDt.ToTime())
// Select a tuple with datetime.
var offset uint32 = 0
var limit uint32 = 1
resp, err = conn.Select(space, index, offset, limit, tarantool.IterEq, []interface{}{dt})
if err != nil {
fmt.Printf("Error in select is %v", err)
return
}
respDt = resp.Data[0].([]interface{})[0].(Datetime)
fmt.Println("Datetime tuple select")
fmt.Printf("Code: %d\n", resp.Code)
fmt.Printf("Data: %v\n", respDt.ToTime())
// Delete a tuple with datetime.
resp, err = conn.Delete(space, index, []interface{}{dt})
if err != nil {
fmt.Printf("Error in delete is %v", err)
return
}
respDt = resp.Data[0].([]interface{})[0].(Datetime)
fmt.Println("Datetime tuple delete")
fmt.Printf("Code: %d\n", resp.Code)
fmt.Printf("Data: %v\n", respDt.ToTime())
}

@zachgrayio
Copy link
Author

After spending some more time on this probably the issue was somewhere else in the stack, though with a clearer example somewhere I could have ruled it out sooner before coming here.

In particular, you aren't showing an end to end example of saving this into a space (what does the space def look like in the example tests you shared?)

Also lacking is a complete example of a real entity/struct defined actually using the datetime type as a member prop etc so you really need to be motivated to find the answer, not great for newcomers to tarantool which I would assume many users of the Golang drivers will be

@oleg-jukovec
Copy link
Collaborator

oleg-jukovec commented Apr 3, 2023

The space has a just datetime field:

local s_1 = box.schema.space.create('testDatetime_1', {

Let's summarize. We need to improve our datetime examples:

  1. Add a comment with space.create().
  2. Add an example with a tuple as a custom structure type.

@oleg-jukovec oleg-jukovec added 1sp good first issue Good for newcomers doc Related to documentation labels Apr 3, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
doc Related to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants