MongoPath

io.github.mbannour.fields.MongoPath
object MongoPath

Macro-powered extractor for case-class field paths that map to MongoDB document keys.

Core ideas:

  • Accepts a selector lambda like _.address.zipCode and returns a dot-separated path (e.g. "address.zip").
  • Honors @BsonProperty on constructor parameters and uses the overridden name when present.
  • Supports a transparent hop over Option via the .? syntax imported from MongoPath.syntax.

Usage: import io.github.mbannour.fields.MongoPath import io.github.mbannour.fields.MongoPath.syntax.?

case class Address(street: String, @BsonProperty("zip") zipCode: Int) case class User(address: Option[Address])

MongoPath.ofUser // "address" MongoPath.ofUser // "address.zip"

Notes:

  • The .? method is never executed at runtime; it only helps the lambda typecheck and be recognized by the macro.
  • If the macro cannot detect a valid case-class field selection chain, it will abort compilation with an error.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
MongoPath.type

Members list

Type members

Classlikes

object syntax

Syntax helpers for transparent Option hops inside selector lambdas.

Syntax helpers for transparent Option hops inside selector lambdas.

The .? method lets you write _.opt.?.field to mean "walk into the option when present" without contributing anything to the resulting path. It is defined inline and its body is never evaluated.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
syntax.type

Value members

Concrete methods

inline def of[T](inline pick: T => Any): String

Compute a Mongo-style dot-separated field path for a given case-class selector.

Compute a Mongo-style dot-separated field path for a given case-class selector.

Example: MongoPath.ofAddress // "zip" if annotated with @BsonProperty("zip")

Type parameters

T

the root case class

Value parameters

pick

a lambda selecting a field chain, e.g. _.a.b.c

Attributes

Returns

the resolved dot-separated path