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

Support anonymous struct fields #62

Open
ababo opened this issue Oct 29, 2016 · 4 comments
Open

Support anonymous struct fields #62

ababo opened this issue Oct 29, 2016 · 4 comments
Labels
Milestone

Comments

@ababo
Copy link
Contributor

ababo commented Oct 29, 2016

I would like to make use of Postgresql inheritance. To do that it's logical to use anonymous struct fields:

//reform:parents
type Parent struct {
    ID   int    `reform:"id,pk"`
    Name string `reform:"name"`
}

//reform:children
type Child struct {
    Parent
    Desc string `reform:"desc"`
} 

but that is not supported.

@AlekSi
Copy link
Member

AlekSi commented Oct 30, 2016

May you share your database schema?

@AlekSi AlekSi added the triage label Oct 30, 2016
@ababo
Copy link
Contributor Author

ababo commented Oct 30, 2016

CREATE TABLE parents (
  id int PRIMARY KEY,
  name varchar(64)
);

CREATE TABLE children (
  desc text
) INHERITS (parents);

@AlekSi
Copy link
Member

AlekSi commented Oct 30, 2016

Anonymous fields were reserved for valid future use-case, and that sounds like a valid one.

Proposed syntax:

//reform:parents
type Parent struct {
    ID   int    `reform:"id,pk"`
    Name string `reform:"name"`
}

//reform:children
type Child struct {
    Parent      `reform:",embed"`
    Desc string `reform:"desc"`
}

,embed tag value will allow us to differentiate from future use-cases.

@AlekSi AlekSi self-assigned this Oct 30, 2016
@AlekSi AlekSi added this to the v1.3.0 milestone Oct 30, 2016
@AlekSi AlekSi added feature and removed triage labels Oct 30, 2016
@AlekSi AlekSi removed their assignment Dec 20, 2016
@xaionaro
Copy link
Contributor

xaionaro commented Feb 12, 2017

Please don't stop on anonymous fields only. I need in support of embedded structure even if it's not an anonymous field.

In my hacky dirty fork of "reform" I already added support of embedded structures, and it looks like this:

//reform:t2
type T2 struct {
    Id   int `reform:"id,pk"`
    Var2 int `reform:"var2"`
    Var3 T1  `reform:"var3,embedded:anotherfile.go"`
}

anotherfile.go:

type T1 struct {
    Var1 int `reform:"var1"`
}

t2 columns will be: id (.Id), var2 (.Var2) and var3__var1 (.Var3.Var1).

Looking ahead, the most difficult problem was to find this structure (it may be in another file) :)

@AlekSi AlekSi modified the milestones: v1.4.0, v1.3.0 Apr 21, 2017
@AlekSi AlekSi modified the milestones: v1.4.0, v1.5.0 Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants