add GetComments and update proto
This commit is contained in:
@@ -28,5 +28,10 @@ returning id;
|
||||
queryGetModule = `
|
||||
select id, name, version, last_version from module
|
||||
where id in %s ;
|
||||
`
|
||||
|
||||
queryGetComments = `
|
||||
select id, text, created, updated from comment
|
||||
where id in %s ;
|
||||
`
|
||||
)
|
||||
|
@@ -249,6 +249,36 @@ func (s *Sqlite) GetModule(ctx context.Context, req *pb.GetModuleReq) (result mo
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *Sqlite) GetComment(ctx context.Context, req *pb.GetCommentsReq) (result models.ListComment, err error) {
|
||||
query := fmt.Sprintf(queryGetComments, generateArrayIneq(len(req.Id)))
|
||||
|
||||
rows, err := s.db.QueryContext(ctx, query, convertSliceUInt(req.Id...)...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
if err = rows.Close(); err != nil {
|
||||
return
|
||||
}
|
||||
err = rows.Err()
|
||||
}()
|
||||
for rows.Next() {
|
||||
tmp := &models.Comment{}
|
||||
if err = rows.Scan(
|
||||
&tmp.ID,
|
||||
&tmp.Text,
|
||||
&tmp.Created,
|
||||
&tmp.Updated,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result = append(result, tmp)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func convertSliceUInt(arg ...uint64) []interface{} {
|
||||
result := make([]interface{}, 0, len(arg))
|
||||
for i := range arg {
|
||||
|
Reference in New Issue
Block a user