golang with master detail mysql entities

huangapple go评论86阅读模式
英文:

golang with master detail mysql entities

问题

我一直在尝试使用GO编程语言。我正在寻求一些关于如何设置主从实体的帮助。
在C#中,我会这样做。我看到很多GO的例子都是处理单个表的,但是我找不到处理像这样的主从实体的例子。

GO似乎与C#和Java非常不同。如果这不是正确的方法,请解释一下,或者指导我如何在GO中实现类似的功能。

谢谢!

type Employee struct {
    id        int
    lastName  string
    firstName string
    addresses []Address
}

type Address struct {
    id       int
    street   string
    zip      string
    employee *Employee
}

以上是你提供的代码的GO版本。希望对你有所帮助!

英文:

I have been playing around with GO programming language. I am looking for some help on how to set up master detail entities.
in c#, I would do below. I have seen many example in GO that deals with one table. but I could not find any example that deals with master detail entities like this.

GO seems very different than C# and Java. If this is not the right way to do it, please explain or point me to some example how I can achieve similar functionality in GO.

Thank you!

public class Employee
{
    public int id{get; set;}
    public string lastName{get; set;}
    public string firstName{get; set;}
    public Collection<Address> addresses { get; set; }    
}

public class Address
{
    public int id{get; set;}
    public string street{get; set;}
    public string zip{get; set;} 
    public virtual Employee employee{get; set;}    
}

答案1

得分: 1

你要找的是一个对象关系映射器(Object Relationnal Mapper)。有很多用Golang编写的ORM,但与使用更动态语言编写的库相比,它们有一些限制,这是由于语言本身的原因。

你也可以手动编写SQL语句,这通常比使用ORM更简单和更快。

英文:

What you are looking for is an Object Relationnal Mapper. There is a lot of ORMs written in Golang, but they have limitations compared to libraries written in more dynamic languages due to the language itself.

You could also writte your SQL statements by hand, which is often simpler and faster than using an ORM.

huangapple
  • 本文由 发表于 2015年9月15日 13:40:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/32578486.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定