-
Notifications
You must be signed in to change notification settings - Fork 8
/
schema.go
36 lines (29 loc) · 1 KB
/
schema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package txsvc
import (
"context"
"errors"
txpb "github.com/kwilteam/kwil-db/core/rpc/protobuf/tx/v1"
"github.com/kwilteam/kwil-db/internal/engine/execution"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (s *Service) GetSchema(ctx context.Context, req *txpb.GetSchemaRequest) (*txpb.GetSchemaResponse, error) {
logger := s.log.With(zap.String("rpc", "GetSchema"), zap.String("dbid", req.Dbid))
schema, err := s.engine.GetSchema(ctx, req.Dbid)
if err != nil {
logger.Debug("failed to get schema", zap.Error(err))
if errors.Is(err, execution.ErrDatasetNotFound) {
return nil, status.Error(codes.NotFound, "dataset not found")
}
return nil, status.Error(codes.Unknown, "failed to get schema")
}
txSchema, err := convertSchemaFromEngine(schema)
if err != nil {
logger.Error("failed to convert schema", zap.Error(err))
return nil, status.Error(codes.Internal, "failed to convert schema")
}
return &txpb.GetSchemaResponse{
Schema: txSchema,
}, nil
}