Storing SQL queries with multiple rows into a struct

agolangf · 2018-01-03 07:30:11 · 429 次点击    
这是一个分享于 2018-01-03 07:30:11 的资源,其中的信息可能已经有所发展或是发生改变。

I'm currently writing a program to query a database, store the results (most likely insert them into a new table) and then compare results I.e., I'll perform a query and store results, then requery an hour later and compare the results from an hour ago to check for changes.

I built structs for the tables such that:

type table1 struct {
    id  int
    col1 string
    col2 time.Time
}

 type table2 struct{
    id int
    col1 string
    col2 time.Time
 }

I'm struggling with how to store the multiple row values into a struct in the simplest manner, then call it back and compare a field. I'll be comparing a specific field such as if t1.col1 == t2.col1 then check to see if this other field matches.

I'm not exactly sure how to store multiple rows into my struct easily though and then write it into a new table. So far I've figured that I'd use a slice of struct but I'm a little confused as to where to go from there/how to scan it in properly. I hope this is elaborated clearly. Thanks!


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

429 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传