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 {
|
||||
|
@@ -42,6 +42,7 @@ type Storage interface {
|
||||
AddPackage(ctx context.Context, req *pb.AddPackageReq) error
|
||||
InsertButchModules(ctx context.Context, req []models.Module) ([]uint64, error)
|
||||
GetModule(ctx context.Context, req *pb.GetModuleReq) (models.ListModule, error)
|
||||
GetComment(ctx context.Context, req *pb.GetCommentsReq) (models.ListComment, error)
|
||||
}
|
||||
|
||||
func NewStorage(name string, db *sql.DB) (Storage, error) {
|
||||
|
@@ -38,3 +38,31 @@ func TestGetModule(t *testing.T) {
|
||||
|
||||
fmt.Println(module)
|
||||
}
|
||||
|
||||
func TestGetComment(t *testing.T) {
|
||||
conn, err := sql.Open("sqlite3", "/Users/devstigneev_local/GolandProjects/unistack/pkgdash/identifier.sqlite")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
if err = conn.Ping(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
st := sqlite.NewStorage()
|
||||
store := st(conn, fs)
|
||||
|
||||
s, ok := store.(Storage)
|
||||
if !ok {
|
||||
t.Fatal("dont implements interface Storage")
|
||||
}
|
||||
|
||||
req := &pb.GetCommentsReq{
|
||||
Id: []uint64{1, 2, 3, 15},
|
||||
}
|
||||
comments, err := s.GetComment(context.Background(), req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Println(comments.Decode())
|
||||
}
|
||||
|
Reference in New Issue
Block a user