-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix restrictions on partition and sort key expressions for complex ca…
…ses (#444)
- Loading branch information
Showing
4 changed files
with
196 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
package zio.dynamodb | ||
|
||
import zio.dynamodb.KeyConditionExpr.PartitionKeyEquals | ||
import zio.dynamodb.proofs.RefersTo | ||
import zio.dynamodb.ProjectionExpression.Unknown | ||
|
||
private[dynamodb] final case class PartitionKey[-From, +To](keyName: String) { self => | ||
def ===[To1 >: To, To2: ToAttributeValue, IsPrimaryKey]( | ||
value: To2 | ||
)(implicit ev: RefersTo[To1, To2]): PartitionKeyEquals[From] = { | ||
val _ = ev | ||
PartitionKeyEquals(self, implicitly[ToAttributeValue[To2]].toAttributeValue(value)) | ||
private[dynamodb] final case class PartitionKey[-From, +To](keyName: String) | ||
private[dynamodb] object PartitionKey { | ||
implicit class PartitionKeyUnknownToOps[-From](val pk: PartitionKey[From, Unknown]) { | ||
def ===[To: ToAttributeValue]( | ||
value: To | ||
): PartitionKeyEquals[From] = | ||
PartitionKeyEquals(pk, implicitly[ToAttributeValue[To]].toAttributeValue(value)) | ||
} | ||
implicit class PartitionKeyOps[-From, To: ToAttributeValue](val pk: PartitionKey[From, To]) { | ||
def ===( | ||
value: To | ||
): PartitionKeyEquals[From] = | ||
PartitionKeyEquals(pk, implicitly[ToAttributeValue[To]].toAttributeValue(value)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,129 @@ | ||
package zio.dynamodb | ||
|
||
import zio.dynamodb.proofs.RefersTo | ||
import zio.dynamodb.proofs.CanSortKeyBeginsWith | ||
|
||
import zio.dynamodb.KeyConditionExpr.SortKeyEquals | ||
import zio.dynamodb.KeyConditionExpr.ExtendedSortKeyExpr | ||
import zio.dynamodb.ProjectionExpression.Unknown | ||
|
||
private[dynamodb] final case class SortKey[-From, +To](keyName: String) { self => | ||
private[dynamodb] final case class SortKey[-From, +To](keyName: String) | ||
|
||
private[dynamodb] object SortKey { | ||
// all comparison ops apply to: Strings, Numbers, Binary values | ||
def ===[To1 >: To, To2: ToAttributeValue, IsPrimaryKey]( | ||
value: To2 | ||
)(implicit ev: RefersTo[To1, To2]): SortKeyEquals[From] = { | ||
val _ = ev | ||
SortKeyEquals[From]( | ||
self.asInstanceOf[SortKey[From, To2]], | ||
implicitly[ToAttributeValue[To2]].toAttributeValue(value) | ||
) | ||
} | ||
def >[To1 >: To, To2: ToAttributeValue, IsPrimaryKey]( | ||
value: To2 | ||
)(implicit ev: RefersTo[To1, To2]): ExtendedSortKeyExpr[From, To2] = { | ||
val _ = ev | ||
ExtendedSortKeyExpr.GreaterThan( | ||
self.asInstanceOf[SortKey[From, To2]], | ||
implicitly(ToAttributeValue[To2]).toAttributeValue(value) | ||
) | ||
} | ||
def <[To1 >: To, To2: ToAttributeValue, IsPrimaryKey]( | ||
value: To2 | ||
)(implicit ev: RefersTo[To1, To2]): ExtendedSortKeyExpr[From, To2] = { | ||
val _ = ev | ||
ExtendedSortKeyExpr.LessThan( | ||
self.asInstanceOf[SortKey[From, To2]], | ||
implicitly[ToAttributeValue[To2]].toAttributeValue(value) | ||
) | ||
} | ||
def <>[To1 >: To, To2: ToAttributeValue, IsPrimaryKey]( | ||
value: To2 | ||
)(implicit ev: RefersTo[To1, To2]): ExtendedSortKeyExpr[From, To2] = { | ||
val _ = ev | ||
ExtendedSortKeyExpr.NotEqual( | ||
self.asInstanceOf[SortKey[From, To2]], | ||
implicitly(ToAttributeValue[To2]).toAttributeValue(value) | ||
) | ||
} | ||
def <=[To1 >: To, To2: ToAttributeValue, IsPrimaryKey]( | ||
value: To2 | ||
)(implicit ev: RefersTo[To1, To2]): ExtendedSortKeyExpr[From, To2] = { | ||
val _ = ev | ||
ExtendedSortKeyExpr.LessThanOrEqual( | ||
self.asInstanceOf[SortKey[From, To2]], | ||
implicitly[ToAttributeValue[To2]].toAttributeValue(value) | ||
) | ||
} | ||
def >=[To1 >: To, To2: ToAttributeValue, IsPrimaryKey]( | ||
value: To2 | ||
)(implicit ev: RefersTo[To1, To2]): ExtendedSortKeyExpr[From, To2] = { | ||
val _ = ev | ||
ExtendedSortKeyExpr.GreaterThanOrEqual( | ||
self.asInstanceOf[SortKey[From, To2]], | ||
implicitly[ToAttributeValue[To2]].toAttributeValue(value) | ||
) | ||
|
||
implicit class SortKeyUnknownToOps[-From](val sk: SortKey[From, Unknown]) { | ||
def ===[To: ToAttributeValue]( | ||
value: To | ||
): SortKeyEquals[From] = | ||
SortKeyEquals(sk, implicitly[ToAttributeValue[To]].toAttributeValue(value)) | ||
def >[To: ToAttributeValue]( | ||
value: To | ||
): ExtendedSortKeyExpr[From, To] = | ||
ExtendedSortKeyExpr.GreaterThan( | ||
sk.asInstanceOf[SortKey[From, To]], | ||
implicitly(ToAttributeValue[To]).toAttributeValue(value) | ||
) | ||
def <[To: ToAttributeValue]( | ||
value: To | ||
): ExtendedSortKeyExpr[From, To] = | ||
ExtendedSortKeyExpr.LessThan( | ||
sk.asInstanceOf[SortKey[From, To]], | ||
implicitly[ToAttributeValue[To]].toAttributeValue(value) | ||
) | ||
def <>[To: ToAttributeValue]( | ||
value: To | ||
): ExtendedSortKeyExpr[From, To] = | ||
ExtendedSortKeyExpr.NotEqual( | ||
sk.asInstanceOf[SortKey[From, To]], | ||
implicitly(ToAttributeValue[To]).toAttributeValue(value) | ||
) | ||
def <=[To: ToAttributeValue]( | ||
value: To | ||
): ExtendedSortKeyExpr[From, To] = | ||
ExtendedSortKeyExpr.LessThanOrEqual( | ||
sk.asInstanceOf[SortKey[From, To]], | ||
implicitly[ToAttributeValue[To]].toAttributeValue(value) | ||
) | ||
def >=[To: ToAttributeValue]( | ||
value: To | ||
): ExtendedSortKeyExpr[From, To] = | ||
ExtendedSortKeyExpr.GreaterThanOrEqual( | ||
sk.asInstanceOf[SortKey[From, To]], | ||
implicitly[ToAttributeValue[To]].toAttributeValue(value) | ||
) | ||
def between[To: ToAttributeValue](min: To, max: To): ExtendedSortKeyExpr[From, To] = | ||
ExtendedSortKeyExpr.Between[From, To]( | ||
sk.asInstanceOf[SortKey[From, To]], | ||
implicitly[ToAttributeValue[To]].toAttributeValue(min), | ||
implicitly[ToAttributeValue[To]].toAttributeValue(max) | ||
) | ||
def beginsWith[To: ToAttributeValue]( | ||
prefix: To | ||
)(implicit ev: CanSortKeyBeginsWith[_, To]): ExtendedSortKeyExpr[From, To] = { | ||
val _ = ev | ||
ExtendedSortKeyExpr.BeginsWith[From, To]( | ||
sk.asInstanceOf[SortKey[From, To]], | ||
implicitly[ToAttributeValue[To]].toAttributeValue(prefix) | ||
) | ||
} | ||
} | ||
// applies to all PK types | ||
def between[To: ToAttributeValue, IsPrimaryKey](min: To, max: To): ExtendedSortKeyExpr[From, To] = | ||
ExtendedSortKeyExpr.Between[From, To]( | ||
self.asInstanceOf[SortKey[From, To]], | ||
implicitly[ToAttributeValue[To]].toAttributeValue(min), | ||
implicitly[ToAttributeValue[To]].toAttributeValue(max) | ||
) | ||
|
||
// beginsWith applies to: Strings, Binary values | ||
def beginsWith[To1 >: To, To2: ToAttributeValue, IsPrimaryKey]( | ||
prefix: To2 | ||
)(implicit ev: CanSortKeyBeginsWith[To1, To2]): ExtendedSortKeyExpr[From, To2] = { | ||
val _ = ev | ||
ExtendedSortKeyExpr.BeginsWith[From, To2]( | ||
self.asInstanceOf[SortKey[From, To2]], | ||
implicitly[ToAttributeValue[To2]].toAttributeValue(prefix) | ||
) | ||
implicit class SortKeyOps[-From, To: ToAttributeValue](val sk: SortKey[From, To]) { | ||
def ===( | ||
value: To | ||
): SortKeyEquals[From] = | ||
SortKeyEquals(sk, implicitly[ToAttributeValue[To]].toAttributeValue(value)) | ||
def >( | ||
value: To | ||
): ExtendedSortKeyExpr[From, To] = | ||
ExtendedSortKeyExpr.GreaterThan( | ||
sk.asInstanceOf[SortKey[From, To]], | ||
implicitly(ToAttributeValue[To]).toAttributeValue(value) | ||
) | ||
def <( | ||
value: To | ||
): ExtendedSortKeyExpr[From, To] = | ||
ExtendedSortKeyExpr.LessThan( | ||
sk.asInstanceOf[SortKey[From, To]], | ||
implicitly[ToAttributeValue[To]].toAttributeValue(value) | ||
) | ||
def <>( | ||
value: To | ||
): ExtendedSortKeyExpr[From, To] = | ||
ExtendedSortKeyExpr.NotEqual( | ||
sk.asInstanceOf[SortKey[From, To]], | ||
implicitly(ToAttributeValue[To]).toAttributeValue(value) | ||
) | ||
def <=( | ||
value: To | ||
): ExtendedSortKeyExpr[From, To] = | ||
ExtendedSortKeyExpr.LessThanOrEqual( | ||
sk.asInstanceOf[SortKey[From, To]], | ||
implicitly[ToAttributeValue[To]].toAttributeValue(value) | ||
) | ||
def >=( | ||
value: To | ||
): ExtendedSortKeyExpr[From, To] = | ||
ExtendedSortKeyExpr.GreaterThanOrEqual( | ||
sk.asInstanceOf[SortKey[From, To]], | ||
implicitly[ToAttributeValue[To]].toAttributeValue(value) | ||
) | ||
def between(min: To, max: To): ExtendedSortKeyExpr[From, To] = | ||
ExtendedSortKeyExpr.Between[From, To]( | ||
sk.asInstanceOf[SortKey[From, To]], | ||
implicitly[ToAttributeValue[To]].toAttributeValue(min), | ||
implicitly[ToAttributeValue[To]].toAttributeValue(max) | ||
) | ||
def beginsWith( | ||
prefix: To | ||
)(implicit ev: CanSortKeyBeginsWith[To, To]): ExtendedSortKeyExpr[From, To] = { | ||
val _ = ev | ||
ExtendedSortKeyExpr.BeginsWith[From, To]( | ||
sk.asInstanceOf[SortKey[From, To]], | ||
implicitly[ToAttributeValue[To]].toAttributeValue(prefix) | ||
) | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters