surrealdb / surrealdb.go

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

Bug: cannot unmarshal object into Go struct field Struct.id of type string #152

Open jinrenjie opened 1 month ago

jinrenjie commented 1 month ago

Describe the bug

Go struct:

type Project struct {
    marshal.Basemodel `table:"projects"`

    ID        string     `json:"id,omitempty"`
    Name      string     `json:"name"`
    Icon      string     `json:"icon,omitempty"`
    Desc      string     `json:"desc"`
    Owner     string     `json:"owner"`
    Status    int32      `json:"status"`
    CreatedAt *time.Time `json:"created_at,omitempty"`
    UpdatedAt *time.Time `json:"updated_at,omitempty"`
    DeletedAt *time.Time `json:"deleted_at,omitempty"`
}

Record in SurrealDB:

{
  "desc": "description",
  "icon": "icon-focusly",
  "id": "projects:⟨a81e88fa-05a2-4e0a-90c6-5f3bceaea7d6⟩",
  "name": "focusly",
  "owner": "NONE",
  "status": 1
}

Error Log:

json: cannot unmarshal object into Go struct field Project.id of type string

Steps to reproduce

Query project records:

queryRes, err := db.Query("SELECT * FROM projects", nil)
if err != nil {
      journal.Logger.Error(err)
      return nil, err
}

// Other convert logic in here......

err = marshal.Unmarshal(queryResMap["result"], &ProjectItems)
if err != nil {
      journal.Logger.Error(err)
      return nil, err
}

Expected behaviour

Unmarshal json models.RecordID to string ID in Go struct.

SurrealDB version

surreal 2.0.1 for macOS on aarch64

Contact Details

george@betterde.com

Is there an existing issue for this?

Code of Conduct