dslquery

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

type Condition struct {
	Field    string // canonical lowercase field name as typed, e.g. "star"
	Def      FieldDef
	Operator Operator

	NumValue float64 // valid when Def.Kind is FieldBeatmap or FieldSkill
	StrValue string  // valid when Def.Kind is FieldText
}

type FieldDef

type FieldDef struct {
	Kind   FieldKind
	Column string
}

type FieldKind

type FieldKind int
const (
	FieldBeatmap FieldKind = iota // numeric column on beatmaps (b.*)
	FieldSkill                    // numeric column on skill_cache (sc.*), requires join
	FieldText                     // text column, matched via LIKE — artist=/title=/etc
	FieldMode                     // special: mode=/mods= parses into osu.Mod, not a WHERE column
)

type Operator

type Operator string
const (
	OpLT  Operator = "<"
	OpLTE Operator = "<="
	OpGT  Operator = ">"
	OpGTE Operator = ">="
	OpEQ  Operator = "="
	OpNEQ Operator = "!="
)

type Query

type Query struct {
	Conditions []Condition
	FreeText   []string

	Mods    osu.Mod
	HasMods bool
}

func Parse

func Parse(raw string) (*Query, error)

Parse tokenizes raw on whitespace (collapsing any run of spaces/tabs) and classifies each token as either a "field<op>value" expression or a bare free-text term. Unknown field names fall back to free text for the whole token, mirroring how osu!'s own search box silently ignores unrecognized filter syntax rather than erroring the whole query.

func (*Query) Compile

func (q *Query) Compile() (where string, args []any)

Compile turns the parsed Query into a parameterized SQL WHERE clause (no leading "WHERE") plus its positional args. Column names come only from fieldRegistry (never raw user input), and every value is bound as a placeholder — injection-safe regardless of what the user typed.

func (*Query) NeedsSkillJoin

func (q *Query) NeedsSkillJoin() bool

NeedsSkillJoin reports whether compiling this query requires joining skill_cache — either because a skill field is filtered on, or because mode=/mods= was given (needed to pick which mod combination's row to join against, even if no skill field itself is filtered).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL