来自复杂JSON的SQLite DB(嵌套数据)

时间:2018-07-19 08:58:21

标签: json database sqlite go database-design

在过去的几个小时里,这一直困扰着我...我通过Go,Echo,Vue.js和HTML创建了一个交互式网页,允许用户显示和编辑简历。我遇到的问题是了解如何设计数据库,以便它可以处理JSON数据的复杂结构(因为现在,我正在通过包含数据的全局变量加载数据,这就是为什么我将其更改为数据库以进行加载和存储)……这可能不是最有效的方法……但这是代码的JSON部分。

{
PersonInfo: PersonInfo{
    Name:    "John Doe",
    Address: "1234 Main St",
    Phone:   "xxx-xxx-xxxx",
    Email:   "fake@email.com",
},
Educations: []Education{
    {
        School:       "Harvard University",
        DateAttended: "Aug 2015 - Present",
        Notes: []string{
            "Graduated Summa Cum Laude.....",
            "Enter more text here...."},
    },
    {
        School:       "Washington State",
        DateAttended: "Apr 2011 – Dec 2012",
        Notes: []string{
            "Completed courses such as......"},
    },
},
Employments: []Employment{
    {
        Company:      "WU Tutor Lab",
        DateAttended: "Jan 2018 - Present",
        Position:     "Math Tutor",
        Notes: []string{
            "Coached students 1-on-1, teaching them to think critically for problem solving math....",
            "More honorable notes about the awesome job here",
        },
    },
    {
        Company:      "Joe's Pizzeria",
        DateAttended: "Feb 2016 – Aug 2016",
        Position:     "Delivery Driver",
        Notes: []string{
            "Averaged 90 mph per delivery. YOLO.",
        },
    },
},
Volunteers: []Volunteer{
    {
        Company:      "Lulu's Bilingual School; Shenzhen, China",
        DateAttended: "Mar 2015 - Jul 2015",
        Position:     "English Teacher",
        Notes: []string{
            "Adapted to Chinese culture while teaching English to 12 classes of 30+ students from 1st-8th grade",
        },
    },
    {
        Company:      "Expect Grateness",
        DateAttended: "Feb 2009 - Feb 2011",
        Position:     "Cheese consultant",
        Notes: []string{
            "Consulted about cheese...",
            "Demonstrated leadership by planning projects and holding team meetings",
        },
    },
},
}

请注意,一份简历如何可以接受多种教育,并且每份教育具有多种注释...与“就业”和“志愿人员”部分相同...任何想法如何设计数据库(表格应包括哪些内容以应对复杂性?)帮助将不胜感激。

此外,我的结构是通过以下方式设置的:

type PersonInfo struct {
Name    string `json:"name"`
Address string `json:"address"`
Phone   string `json:"phone"`
Email   string `json:"email"`
}

type Education struct {
    School       string   `json:"school"`
    DateAttended string   `json:"date_attended"`
    Notes        []string `json:"notes"`
}

type Employment struct {
    Company      string   `json:"company"`
    DateAttended string   `json:"date_attended"`
    Position     string   `json:"position"`
    Notes        []string `json:"notes"`
}

type Volunteer struct {
    Company      string   `json:"company"`
    DateAttended string   `json:"date_attended"`
    Position     string   `json:"position"`
    Notes        []string `json:"notes"`
}

type Resume struct {
    PersonInfo  PersonInfo   `json:"person_info"`
    Educations  []Education  `json:"educations"`
    Employments []Employment `json:"employments"`
    Volunteers  []Volunteer  `json:"volunteers"`
}

0 个答案:

没有答案