Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
673586c2f7 | |||
4606d7a08d |
@ -12,26 +12,26 @@ import (
|
||||
)
|
||||
|
||||
type Device struct {
|
||||
UUID string `goja:"uuid"`
|
||||
Host net.IP `goja:"host"`
|
||||
Port int `goja:"port"`
|
||||
Name string `goja:"name"`
|
||||
UUID string `goja:"uuid" json:"uuid"`
|
||||
Host net.IP `goja:"host" json:"host"`
|
||||
Port int `goja:"port" json:"port"`
|
||||
Name string `goja:"name" json:"name"`
|
||||
}
|
||||
|
||||
type DeviceStatus struct {
|
||||
CurrentApp DeviceStatusCurrentApp `goja:"currentApp"`
|
||||
Volume DeviceStatusVolume `goja:"volume"`
|
||||
CurrentApp DeviceStatusCurrentApp `goja:"currentApp" json:"currentApp"`
|
||||
Volume DeviceStatusVolume `goja:"volume" json:"volume"`
|
||||
}
|
||||
|
||||
type DeviceStatusCurrentApp struct {
|
||||
ID string `goja:"id"`
|
||||
DisplayName string `goja:"displayName"`
|
||||
StatusText string `goja:"statusText"`
|
||||
ID string `goja:"id" json:"id"`
|
||||
DisplayName string `goja:"displayName" json:"displayName"`
|
||||
StatusText string `goja:"statusText" json:"statusText"`
|
||||
}
|
||||
|
||||
type DeviceStatusVolume struct {
|
||||
Level float64 `goja:"level"`
|
||||
Muted bool `goja:"muted"`
|
||||
Level float64 `goja:"level" json:"level"`
|
||||
Muted bool `goja:"muted" json:"muted"`
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -91,6 +91,7 @@ func (m *StoreModule) query(call goja.FunctionCall, rt *goja.Runtime) goja.Value
|
||||
|
||||
queryOptionsFuncs := make([]storage.QueryOptionFunc, 0)
|
||||
|
||||
if queryOptions != nil {
|
||||
if queryOptions.Limit != nil {
|
||||
queryOptionsFuncs = append(queryOptionsFuncs, storage.WithLimit(*queryOptions.Limit))
|
||||
}
|
||||
@ -108,6 +109,7 @@ func (m *StoreModule) query(call goja.FunctionCall, rt *goja.Runtime) goja.Value
|
||||
storage.OrderDirection(*queryOptions.OrderDirection),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
documents, err := m.store.Query(ctx, collection, filter, queryOptionsFuncs...)
|
||||
if err != nil {
|
||||
@ -144,6 +146,10 @@ func (m *StoreModule) assertCollection(value goja.Value, rt *goja.Runtime) strin
|
||||
}
|
||||
|
||||
func (m *StoreModule) assertFilter(value goja.Value, rt *goja.Runtime) *filter.Filter {
|
||||
if value.Export() == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
rawFilter, ok := value.Export().(map[string]interface{})
|
||||
if !ok {
|
||||
panic(rt.NewTypeError(fmt.Sprintf("filter must be an object, got '%T'", value.Export())))
|
||||
@ -172,6 +178,10 @@ func (m *StoreModule) assertDocumentID(value goja.Value, rt *goja.Runtime) stora
|
||||
}
|
||||
|
||||
func (m *StoreModule) assertQueryOptions(value goja.Value, rt *goja.Runtime) *queryOptions {
|
||||
if value.Export() == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
rawQueryOptions, ok := value.Export().(map[string]interface{})
|
||||
if !ok {
|
||||
panic(rt.NewTypeError(fmt.Sprintf("query options must be an object, got '%T'", value.Export())))
|
||||
|
@ -93,7 +93,13 @@ func (s *DocumentStore) Query(ctx context.Context, collection string, filter *fi
|
||||
var documents []storage.Document
|
||||
|
||||
err := s.withTx(ctx, func(tx *sql.Tx) error {
|
||||
criteria, args, err := filterSQL.ToSQL(
|
||||
criteria := "1 = 1"
|
||||
args := make([]any, 0)
|
||||
|
||||
var err error
|
||||
|
||||
if filter != nil {
|
||||
criteria, args, err = filterSQL.ToSQL(
|
||||
filter.Root(),
|
||||
filterSQL.WithPreparedParameter("$", 2),
|
||||
filterSQL.WithKeyTransform(func(key string) string {
|
||||
@ -103,6 +109,7 @@ func (s *DocumentStore) Query(ctx context.Context, collection string, filter *fi
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
}
|
||||
|
||||
query := `
|
||||
SELECT id, data, created_at, updated_at
|
||||
|
Reference in New Issue
Block a user