From 3aa7a5e86b8b63350be19e6a266f9d79bd647e62 Mon Sep 17 00:00:00 2001 From: Matt Hicks Date: Thu, 28 Mar 2024 17:59:00 -0500 Subject: [PATCH] Better Id validation and condition filtering --- core/shared/src/main/scala/lightdb/Id.scala | 3 +-- core/shared/src/main/scala/lightdb/query/package.scala | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/shared/src/main/scala/lightdb/Id.scala b/core/shared/src/main/scala/lightdb/Id.scala index 5c5f77da..bfafbb31 100644 --- a/core/shared/src/main/scala/lightdb/Id.scala +++ b/core/shared/src/main/scala/lightdb/Id.scala @@ -1,12 +1,11 @@ package lightdb -import fabric._ import fabric.rw._ class Id[T](val value: String) extends AnyVal { def bytes: Array[Byte] = { val b = toString.getBytes("UTF-8") - assert(b.length <= 128, s"Must be 128 bytes or less, but was ${b.length}") + assert(b.length <= 128, s"Must be 128 bytes or less, but was ${b.length} ($value)") b } def parts: Vector[String] = value.split('/').toVector diff --git a/core/shared/src/main/scala/lightdb/query/package.scala b/core/shared/src/main/scala/lightdb/query/package.scala index 0f3c70de..19f0a208 100644 --- a/core/shared/src/main/scala/lightdb/query/package.scala +++ b/core/shared/src/main/scala/lightdb/query/package.scala @@ -1,8 +1,14 @@ package lightdb import lightdb.field.Field +import lightdb.query.Filter.GroupedFilter + +import scala.language.implicitConversions package object query { + implicit def conditionTuple2Filter[D <: Document[D]](tuple: (Filter[D], Condition)): Filter[D] = + GroupedFilter(0, List(tuple)) + implicit class FieldQueryExtras[D <: Document[D], F](val field: Field[D, F]) extends AnyVal { def ===(value: F): Filter[D] = Filter.Equals(field, value) def is(value: F): Filter[D] = Filter.Equals(field, value)