First attempt at a resultset pseudovar
The resultset needs a table set, so rs:new will also assume the current table.
This commit is contained in:
parent
6bf721873b
commit
18ffe85a56
2
go.mod
2
go.mod
|
@ -117,5 +117,5 @@ require (
|
|||
golang.org/x/text v0.9.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
ucl.lmika.dev v0.0.0-20250517003439-109be33d1495 // indirect
|
||||
ucl.lmika.dev v0.0.0-20250517115116-0f1ceba0902e // indirect
|
||||
)
|
||||
|
|
2
go.sum
2
go.sum
|
@ -442,3 +442,5 @@ ucl.lmika.dev v0.0.0-20250515115457-27b6cc0b92e2 h1:cvguOoQ0HVgLKbHH17ZHvAUFht6H
|
|||
ucl.lmika.dev v0.0.0-20250515115457-27b6cc0b92e2/go.mod h1:/MMZKm6mOMtnY4I8TYEot4Pc8dKEy+/IAQo1VdpA5EY=
|
||||
ucl.lmika.dev v0.0.0-20250517003439-109be33d1495 h1:r46r+7T59Drm+in7TEWKCZfFYIM0ZyZ26QjHAbj8Lto=
|
||||
ucl.lmika.dev v0.0.0-20250517003439-109be33d1495/go.mod h1:/MMZKm6mOMtnY4I8TYEot4Pc8dKEy+/IAQo1VdpA5EY=
|
||||
ucl.lmika.dev v0.0.0-20250517115116-0f1ceba0902e h1:CQ+qPqI5lYiiEM0tNAr4jS0iMz16bFqOui5mU3AHsCU=
|
||||
ucl.lmika.dev v0.0.0-20250517115116-0f1ceba0902e/go.mod h1:/MMZKm6mOMtnY4I8TYEot4Pc8dKEy+/IAQo1VdpA5EY=
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/lmika/dynamo-browse/internal/dynamo-browse/models/queryexpr"
|
||||
"github.com/lmika/dynamo-browse/internal/dynamo-browse/services/tables"
|
||||
"github.com/pkg/errors"
|
||||
"time"
|
||||
"ucl.lmika.dev/repl"
|
||||
"ucl.lmika.dev/ucl"
|
||||
)
|
||||
|
@ -19,11 +20,36 @@ type rsModule struct {
|
|||
|
||||
var rsNewDoc = repl.Doc{
|
||||
Brief: "Creates a new, empty result set",
|
||||
Usage: "[-table NAME]",
|
||||
Detailed: `
|
||||
The result set assumes the details of the current table. If no table is specified,
|
||||
the command will return an error.
|
||||
`,
|
||||
}
|
||||
|
||||
func (rs *rsModule) rsNew(ctx context.Context, args ucl.CallArgs) (any, error) {
|
||||
return &ResultSetProxy{
|
||||
RS: &models.ResultSet{},
|
||||
func (rs *rsModule) rsNew(ctx context.Context, args ucl.CallArgs) (_ any, err error) {
|
||||
var tableInfo *models.TableInfo
|
||||
if args.HasSwitch("table") {
|
||||
var tblName string
|
||||
if err := args.BindSwitch("table", &tblName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tableInfo, err = rs.tableService.Describe(ctx, tblName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else if currRs := rs.state.ResultSet(); currRs != nil && currRs.TableInfo != nil {
|
||||
tableInfo = currRs.TableInfo
|
||||
} else {
|
||||
return nil, errors.New("no table specified")
|
||||
}
|
||||
|
||||
return ResultSetProxy{
|
||||
RS: &models.ResultSet{
|
||||
TableInfo: tableInfo,
|
||||
Created: time.Now(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -102,7 +128,7 @@ func (rs *rsModule) rsQuery(ctx context.Context, args ucl.CallArgs) (any, error)
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return &ResultSetProxy{
|
||||
return ResultSetProxy{
|
||||
RS: newResultSet,
|
||||
}, nil
|
||||
}
|
||||
|
|
31
internal/common/ui/commandctrl/cmdpacks/pvars.go
Normal file
31
internal/common/ui/commandctrl/cmdpacks/pvars.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package cmdpacks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/lmika/dynamo-browse/internal/common/ui/commandctrl"
|
||||
"github.com/lmika/dynamo-browse/internal/dynamo-browse/controllers"
|
||||
"github.com/pkg/errors"
|
||||
"log"
|
||||
)
|
||||
|
||||
type resultSetPVar struct {
|
||||
state *controllers.State
|
||||
readController *controllers.TableReadController
|
||||
}
|
||||
|
||||
func (rs resultSetPVar) Get(ctx context.Context) (any, error) {
|
||||
return ResultSetProxy{rs.state.ResultSet()}, nil
|
||||
}
|
||||
|
||||
func (rs resultSetPVar) Set(ctx context.Context, value any) error {
|
||||
rsVal, ok := value.(ResultSetProxy)
|
||||
if !ok {
|
||||
return errors.New("new value to @resultset is not a result set")
|
||||
}
|
||||
|
||||
log.Printf("type = %T", rsVal.RS)
|
||||
|
||||
msg := rs.readController.SetResultSet(rsVal.RS)
|
||||
commandctrl.PostMsg(ctx, msg)
|
||||
return nil
|
||||
}
|
|
@ -384,4 +384,6 @@ func (sc StandardCommands) ConfigureUCL(ucl *ucl.Inst) {
|
|||
ucl.SetBuiltin("noisy-touch", sc.cmdNoisyTouch)
|
||||
ucl.SetBuiltin("rebind", sc.cmdRebind)
|
||||
// set-opt --> alias to opts:set
|
||||
|
||||
ucl.SetPseudoVar("resultset", resultSetPVar{sc.State, sc.ReadController})
|
||||
}
|
||||
|
|
|
@ -29,6 +29,14 @@ func (s *State) Filter() string {
|
|||
return s.filter
|
||||
}
|
||||
|
||||
func (s *State) SetResultSet(resultSet *models.ResultSet) {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
s.resultSet = resultSet
|
||||
s.filter = ""
|
||||
}
|
||||
|
||||
func (s *State) withResultSet(rs func(*models.ResultSet)) {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
|
|
@ -291,6 +291,12 @@ func (c *TableReadController) setResultSetAndFilter(resultSet *models.ResultSet,
|
|||
return c.state.buildNewResultSetMessage("")
|
||||
}
|
||||
|
||||
func (c *TableReadController) SetResultSet(resultSet *models.ResultSet) tea.Msg {
|
||||
c.state.setResultSetAndFilter(resultSet, "")
|
||||
c.eventBus.Fire(newResultSetEvent, resultSet, resultSetUpdateScript)
|
||||
return c.state.buildNewResultSetMessage("")
|
||||
}
|
||||
|
||||
func (c *TableReadController) Mark(op MarkOp, where string) tea.Msg {
|
||||
var (
|
||||
whereExpr *queryexpr.QueryExpr
|
||||
|
|
|
@ -2,6 +2,7 @@ package testdynamo
|
|||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
|
@ -28,8 +29,13 @@ func SetupTestTable(t *testing.T, testData []TestData) *dynamodb.Client {
|
|||
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("abc", "123", "")))
|
||||
assert.NoError(t, err)
|
||||
|
||||
testDynamoURL, ok := os.LookupEnv("TEST_DYNAMO_URL")
|
||||
if !ok {
|
||||
testDynamoURL = "http://localhost:4566"
|
||||
}
|
||||
|
||||
dynamoClient := dynamodb.NewFromConfig(cfg,
|
||||
dynamodb.WithEndpointResolver(dynamodb.EndpointResolverFromURL("http://localhost:4566")))
|
||||
dynamodb.WithEndpointResolver(dynamodb.EndpointResolverFromURL(testDynamoURL)))
|
||||
|
||||
for _, table := range testData {
|
||||
tableInput := &dynamodb.CreateTableInput{
|
||||
|
|
Loading…
Reference in a new issue