mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-10 18:10:49 +09:00
GO-3663: Clean up
This commit is contained in:
parent
5f0867c700
commit
416a10f315
5 changed files with 1 additions and 120 deletions
|
@ -1,8 +1,6 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogo/protobuf/types"
|
||||
|
||||
"github.com/anyproto/anytype-heart/core/domain"
|
||||
|
@ -212,20 +210,6 @@ type Filters struct {
|
|||
dateKeys []string
|
||||
}
|
||||
|
||||
func (f *Filters) String() string {
|
||||
var filterString string
|
||||
var orderString string
|
||||
var separator string
|
||||
if f.FilterObj != nil {
|
||||
filterString = fmt.Sprintf("WHERE %v", f.FilterObj.String())
|
||||
separator = " "
|
||||
}
|
||||
if f.Order != nil {
|
||||
orderString = fmt.Sprintf("%sORDER BY %v", separator, f.Order.String())
|
||||
}
|
||||
return fmt.Sprintf("%s%s", filterString, orderString)
|
||||
}
|
||||
|
||||
// ListRelationOptions returns options for specific relation
|
||||
func ListRelationOptions(store ObjectStore, spaceID string, relationKey string) (options []*model.RelationOption, err error) {
|
||||
filters := []*model.BlockContentDataviewFilter{
|
||||
|
|
|
@ -177,7 +177,6 @@ type WithNestedFilter interface {
|
|||
|
||||
type Filter interface {
|
||||
FilterObject(g *types.Struct) bool
|
||||
String() string
|
||||
Compile() query.Filter
|
||||
}
|
||||
|
||||
|
@ -194,14 +193,6 @@ func (a FiltersAnd) FilterObject(g *types.Struct) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (a FiltersAnd) String() string {
|
||||
var andS []string
|
||||
for _, f := range a {
|
||||
andS = append(andS, f.String())
|
||||
}
|
||||
return fmt.Sprintf("(%s)", strings.Join(andS, " AND "))
|
||||
}
|
||||
|
||||
func (a FiltersAnd) Compile() query.Filter {
|
||||
var filters []query.Filter
|
||||
for _, f := range a {
|
||||
|
@ -240,14 +231,6 @@ func (fo FiltersOr) Compile() query.Filter {
|
|||
return query.Or(filters)
|
||||
}
|
||||
|
||||
func (fo FiltersOr) String() string {
|
||||
var orS []string
|
||||
for _, f := range fo {
|
||||
orS = append(orS, f.String())
|
||||
}
|
||||
return fmt.Sprintf("(%s)", strings.Join(orS, " OR "))
|
||||
}
|
||||
|
||||
func (fo FiltersOr) IterateNestedFilters(fn func(nestedFilter Filter) error) error {
|
||||
return iterateNestedFilters(fo, fn)
|
||||
}
|
||||
|
@ -279,10 +262,6 @@ func (f FilterNot) Compile() query.Filter {
|
|||
return query.Not{Filter: f.Filter.Compile()}
|
||||
}
|
||||
|
||||
func (n FilterNot) String() string {
|
||||
return fmt.Sprintf("NOT(%s)", n.Filter.String())
|
||||
}
|
||||
|
||||
type FilterEq struct {
|
||||
Key string
|
||||
Cond model.BlockContentDataviewFilterCondition
|
||||
|
@ -360,24 +339,7 @@ func (e FilterEq) filterObject(v *types.Value) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (e FilterEq) String() string {
|
||||
var eq string
|
||||
switch e.Cond {
|
||||
case model.BlockContentDataviewFilter_Equal:
|
||||
eq = "="
|
||||
case model.BlockContentDataviewFilter_Greater:
|
||||
eq = ">"
|
||||
case model.BlockContentDataviewFilter_GreaterOrEqual:
|
||||
eq = ">="
|
||||
case model.BlockContentDataviewFilter_Less:
|
||||
eq = "<"
|
||||
case model.BlockContentDataviewFilter_LessOrEqual:
|
||||
eq = "<="
|
||||
}
|
||||
return fmt.Sprintf("%s %s '%s'", e.Key, eq, pbtypes.Sprint(e.Value))
|
||||
}
|
||||
|
||||
// any?
|
||||
// any
|
||||
type FilterIn struct {
|
||||
Key string
|
||||
Value *types.ListValue
|
||||
|
@ -405,10 +367,6 @@ func (i FilterIn) Compile() query.Filter {
|
|||
}
|
||||
}
|
||||
|
||||
func (i FilterIn) String() string {
|
||||
return fmt.Sprintf("%v IN(%v)", i.Key, pbtypes.Sprint(i.Value))
|
||||
}
|
||||
|
||||
type FilterLike struct {
|
||||
Key string
|
||||
Value *types.Value
|
||||
|
@ -438,10 +396,6 @@ func (l FilterLike) Compile() query.Filter {
|
|||
}
|
||||
}
|
||||
|
||||
func (l FilterLike) String() string {
|
||||
return fmt.Sprintf("%v LIKE '%s'", l.Key, pbtypes.Sprint(l.Value))
|
||||
}
|
||||
|
||||
type FilterExists struct {
|
||||
Key string
|
||||
}
|
||||
|
@ -462,10 +416,6 @@ func (e FilterExists) Compile() query.Filter {
|
|||
}
|
||||
}
|
||||
|
||||
func (e FilterExists) String() string {
|
||||
return fmt.Sprintf("%v EXISTS", e.Key)
|
||||
}
|
||||
|
||||
type FilterEmpty struct {
|
||||
Key string
|
||||
}
|
||||
|
@ -513,10 +463,6 @@ func (e FilterEmpty) Compile() query.Filter {
|
|||
}
|
||||
}
|
||||
|
||||
func (e FilterEmpty) String() string {
|
||||
return fmt.Sprintf("%v IS EMPTY", e.Key)
|
||||
}
|
||||
|
||||
// all?
|
||||
type FilterAllIn struct {
|
||||
Key string
|
||||
|
@ -562,9 +508,6 @@ func (l FilterAllIn) Compile() query.Filter {
|
|||
Filter: query.And(conds),
|
||||
}
|
||||
}
|
||||
func (l FilterAllIn) String() string {
|
||||
return fmt.Sprintf("%s ALLIN(%v)", l.Key, l.Value)
|
||||
}
|
||||
|
||||
type FilterOptionsEqual struct {
|
||||
Key string
|
||||
|
@ -624,10 +567,6 @@ func (exIn FilterOptionsEqual) Compile() query.Filter {
|
|||
}
|
||||
}
|
||||
|
||||
func (exIn FilterOptionsEqual) String() string {
|
||||
return fmt.Sprintf("%s EXACTINN(%v)", exIn.Key, exIn.Value)
|
||||
}
|
||||
|
||||
func optionsToMap(spaceID string, key string, store ObjectStore) map[string]string {
|
||||
result := make(map[string]string)
|
||||
options, err := ListRelationOptions(store, spaceID, key)
|
||||
|
@ -699,10 +638,6 @@ func (i *FilterNestedIn) Compile() query.Filter {
|
|||
}
|
||||
}
|
||||
|
||||
func (i *FilterNestedIn) String() string {
|
||||
return fmt.Sprintf("%v IN(%v)", i.Key, i.IDs)
|
||||
}
|
||||
|
||||
func (i *FilterNestedIn) IterateNestedFilters(fn func(nestedFilter Filter) error) error {
|
||||
return fn(i)
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/anyproto/any-store/encoding"
|
||||
"github.com/anyproto/any-store/key"
|
||||
"github.com/anyproto/any-store/query"
|
||||
|
@ -20,7 +18,6 @@ import (
|
|||
type Order interface {
|
||||
Compare(a, b *types.Struct) int
|
||||
Compile() query.Sort
|
||||
String() string
|
||||
}
|
||||
|
||||
// ObjectStore interface is used to enrich filters
|
||||
|
@ -51,14 +48,6 @@ func (so SetOrder) Compile() query.Sort {
|
|||
return sorts
|
||||
}
|
||||
|
||||
func (so SetOrder) String() (s string) {
|
||||
var ss []string
|
||||
for _, o := range so {
|
||||
ss = append(ss, o.String())
|
||||
}
|
||||
return strings.Join(ss, ", ")
|
||||
}
|
||||
|
||||
type KeyOrder struct {
|
||||
SpaceID string
|
||||
Key string
|
||||
|
@ -281,14 +270,6 @@ func (ko *KeyOrder) GetOptionValue(value *types.Value) *types.Value {
|
|||
return pbtypes.String(res)
|
||||
}
|
||||
|
||||
func (ko *KeyOrder) String() (s string) {
|
||||
s = ko.Key
|
||||
if ko.Type == model.BlockContentDataviewSort_Desc {
|
||||
s += " DESC"
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (ko *KeyOrder) ensureComparator() {
|
||||
if ko.comparator == nil {
|
||||
ko.comparator = collate.New(language.Und, collate.IgnoreCase)
|
||||
|
@ -360,11 +341,3 @@ func (co CustomOrder) Compare(a, b *types.Struct) int {
|
|||
|
||||
return co.KeyOrd.Compare(a, b)
|
||||
}
|
||||
|
||||
func (co CustomOrder) String() (s string) {
|
||||
ss := make([]string, len(co.NeedOrderMap))
|
||||
for key, id := range co.NeedOrderMap {
|
||||
ss[id] = key
|
||||
}
|
||||
return strings.Join(ss, ", ")
|
||||
}
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/bundle"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
|
||||
"github.com/anyproto/anytype-heart/util/pbtypes"
|
||||
)
|
||||
|
||||
type schemaByRelations struct {
|
||||
|
@ -32,7 +29,3 @@ func (sch *schemaByRelations) RequiredRelations() []*model.RelationLink {
|
|||
func (sch *schemaByRelations) ListRelations() []*model.RelationLink {
|
||||
return sch.CommonRelations
|
||||
}
|
||||
|
||||
func (sch *schemaByRelations) String() string {
|
||||
return fmt.Sprintf("relations: %v", pbtypes.GetRelationListKeys(sch.CommonRelations))
|
||||
}
|
||||
|
|
|
@ -18,7 +18,3 @@ func (sch *emptySchema) RequiredRelations() []*model.RelationLink {
|
|||
func (sch *emptySchema) ListRelations() []*model.RelationLink {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sch *emptySchema) String() string {
|
||||
return ""
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue