surrealdb / surrealdb.go

SurrealDB SDK for Golang
https://surrealdb.com
Apache License 2.0
244 stars 66 forks source link

Bug: cannot unmarshal datetime cbor type to time.Time #178

Closed TheComputerM closed 1 week ago

TheComputerM commented 1 week ago

Describe the bug

I get this error while creating a record

cbor: cannot unmarshal array into Go struct field connection.RPCResponse[...].result of type time.Time

Steps to reproduce

DEFINE TABLE user SCHEMAFULL;

DEFINE FIELD email ON user TYPE string ASSERT string::is::email($value);
DEFINE FIELD password ON user TYPE string;
DEFINE FIELD jwt ON user TYPE option<string>;
DEFINE FIELD updated_at ON user TYPE datetime DEFAULT time::now();
type User struct {
    ID        *models.RecordID `json:"id,omitempty"`
    UpdatedAt time.Time        `json:"updated_at,omitempty"`
}

user := User{
    EMail:     claims.EMail,
    UpdatedAt: time.Now(),
}

_, err = surrealdb.Create[User](DB, models.Table("user"), user)

Expected behaviour

Should unmarshal datetime field to time.Time

SurrealDB version

2.0.4 for linux on x86_64

Contact Details

No response

Is there an existing issue for this?

Code of Conduct

TheComputerM commented 1 week ago

It got fixed when I wrapped it with surrealdb.Result.

_, err = surrealdb.Create[surrealdb.Result[User]](DB, models.Table("user"), user)