/
package.scala
39 lines (27 loc) · 1.42 KB
/
package.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.gu
import com.gu.scanamo.query._
package object scanamo {
object syntax extends Scannable.ToScannableOps with Queryable.ToQueryableOps {
implicit class SymbolKeyCondition(s: Symbol) {
def <[V: DynamoFormat](v: V) = KeyIs(s, LT, v)
def >[V: DynamoFormat](v: V) = KeyIs(s, GT, v)
def <=[V: DynamoFormat](v: V) = KeyIs(s, LTE, v)
def >=[V: DynamoFormat](v: V) = KeyIs(s, GTE, v)
def beginsWith[V: DynamoFormat](v: V) = KeyBeginsWith(s, v)
def and(other: Symbol) = HashAndRangeKeyNames(s, other)
}
case class HashAndRangeKeyNames(hash: Symbol, range: Symbol)
implicit def symbolTupleToUniqueKey[V: DynamoFormat](pair: (Symbol, V)) =
UniqueKey(KeyEquals(pair._1, pair._2))
implicit def symbolTupleToKeyCondition[V: DynamoFormat](pair: (Symbol, V)) =
KeyEquals(pair._1, pair._2)
implicit def toUniqueKey[T: UniqueKeyCondition](t: T) = UniqueKey(t)
implicit def symbolListTupleToUniqueKeys[V: DynamoFormat](pair: (Symbol, List[V])) =
UniqueKeys(KeyList(pair._1, pair._2))
implicit def toMultipleKeyList[H: DynamoFormat, R: DynamoFormat](pair: (HashAndRangeKeyNames, List[(H, R)])) =
UniqueKeys(MultipleKeyList(pair._1.hash -> pair._1.range, pair._2))
implicit def symbolTupleToQuery[V: DynamoFormat](pair: (Symbol, V)) =
Query(KeyEquals(pair._1, pair._2))
implicit def toQuery[T: QueryableKeyCondition](t: T) = Query(t)
}
}