backstack: added saving of backstack to workspace
This commit is contained in:
parent
96207821a2
commit
721d3abe5e
9 changed files with 214 additions and 11 deletions
9
internal/dynamo-browse/services/workspaces/iface.go
Normal file
9
internal/dynamo-browse/services/workspaces/iface.go
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
package workspaces
|
||||
|
||||
import "github.com/lmika/audax/internal/dynamo-browse/models/serialisable"
|
||||
|
||||
type ResultSetSnapshotStore interface {
|
||||
Save(rs *serialisable.ResultSetSnapshot) error
|
||||
SetAsHead(resultSetId int64) error
|
||||
Head() (*serialisable.ResultSetSnapshot, error)
|
||||
}
|
||||
43
internal/dynamo-browse/services/workspaces/service.go
Normal file
43
internal/dynamo-browse/services/workspaces/service.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package workspaces
|
||||
|
||||
import (
|
||||
"github.com/lmika/audax/internal/dynamo-browse/models"
|
||||
"github.com/lmika/audax/internal/dynamo-browse/models/serialisable"
|
||||
"github.com/pkg/errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
store ResultSetSnapshotStore
|
||||
}
|
||||
|
||||
func NewService(store ResultSetSnapshotStore) *Service {
|
||||
return &Service{
|
||||
store: store,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) PushSnapshot(rs *models.ResultSet) error {
|
||||
newSnapshot := &serialisable.ResultSetSnapshot{
|
||||
Time: time.Now(),
|
||||
TableInfo: rs.TableInfo,
|
||||
}
|
||||
if q := rs.Query; q != nil {
|
||||
newSnapshot.Query.Expression = q.String()
|
||||
}
|
||||
|
||||
if head, err := s.store.Head(); head != nil {
|
||||
newSnapshot.BackLink = head.ID
|
||||
} else if err != nil {
|
||||
return errors.Wrap(err, "cannot get head result set")
|
||||
}
|
||||
|
||||
if err := s.store.Save(newSnapshot); err != nil {
|
||||
return errors.Wrap(err, "cannot save snapshot")
|
||||
}
|
||||
if err := s.store.SetAsHead(newSnapshot.ID); err != nil {
|
||||
return errors.Wrap(err, "cannot set new snapshot as head")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue