Skip to content

Commit

Permalink
Better Id validation and condition filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Mar 28, 2024
1 parent 2b19469 commit 3aa7a5e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions core/shared/src/main/scala/lightdb/Id.scala
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions core/shared/src/main/scala/lightdb/query/package.scala
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 3aa7a5e

Please sign in to comment.