Skip to content

structs one-to-many relation #26

Description

@lycifer3

is it possible to create structures one to many
db: clickhouse 20.3.5.21

example:

type DomainType struct {
	Id        string      `json:"id"`
	Domain    string      `json:"domain"`
	Date      time.Time   `json:"date"`
	Redirects []*Redirect `json:"redirects"`
}

type Redirect struct {
	Id             sql.NullString `json:"id"`
	RedirectDomain sql.NullString `json:"redirect_domain" db:"redirect_domain"`
	Date           sql.NullTime   `json:"redirect_date" db:"date"`
}

end query:

var result []entity.DomainType
query := sess.Select("*").From("domain").LeftJoin("domain_redirect", "domain.id = domain_redirect.id")

query.LoadStructs(&result)

if this is possible then tell me how, I'm begginer to the golang

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions