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

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

Open
2 tasks done
jinrenjie opened this issue Sep 24, 2024 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@jinrenjie
Copy link

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?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@jinrenjie jinrenjie added the bug Something isn't working label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant