Skip to content

Commit

Permalink
Adding support for timeuuid operators
Browse files Browse the repository at this point in the history
  • Loading branch information
alexflav23 committed Apr 2, 2019
1 parent 20f4c12 commit e697232
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Expand Up @@ -158,8 +158,8 @@ private[phantom] trait TimeUUIDOperator {
new Condition(fn(CQLQuery.escape(new DateTime(date).toString())))
}

def apply(mark: PrepareMark): OperatorClause.Prepared[DateTime] = {
new OperatorClause.Prepared[DateTime](fn(mark.qb.queryString))
def apply(mark: PrepareMark): OperatorClause.Prepared[Long] = {
new OperatorClause.Prepared[Long](fn(mark.qb.queryString))
}

def fn: String => CQLQuery
Expand Down
Expand Up @@ -175,7 +175,7 @@ class Jdk8TimeUUIDTests extends PhantomSuite {
}
}

it should "be able to store and retrieve a time slice of records based on ZonedDateTime and prepared statements" in {
it should "be able to store and retrieve a time slice of records with prepared statements" in {

val interval = 60
val now = ZonedDateTime.now()
Expand Down Expand Up @@ -222,9 +222,13 @@ class Jdk8TimeUUIDTests extends PhantomSuite {
_ <- database.timeuuidTable.store(record).future()
_ <- database.timeuuidTable.store(record1).future()
_ <- database.timeuuidTable.store(record2).future()
one <- query.flatMap(_.bind(record.user, start, end).fetch())
one <- query.flatMap(_.bind(record.user, start.toInstant.toEpochMilli, end.toInstant.toEpochMilli).fetch())

one2 <- query.flatMap(_.bind(record.user, start.plusMinutes(-2), end).fetch())
one2 <- query.flatMap(_.bind(
record.user,
start.plusMinutes(-2).toInstant.toEpochMilli,
end.toInstant.toEpochMilli
).fetch())
} yield (one, one2)

whenReady(chain) { case (res, res2) =>
Expand Down Expand Up @@ -292,18 +296,18 @@ class Jdk8TimeUUIDTests extends PhantomSuite {
Gen.choose(
-intervalOffset,
intervalOffset
).sample.get
).sample.value
).timeuuid)
)

val chain = for {
_ <- database.timeuuidTable.storeRecords(records)
get <- database.timeuuidTable.select
records <- database.timeuuidTable.select
.where(_.user eqs user)
.and(_.id >= minTimeuuid(start.plusSeconds(-3 * intervalOffset)))
.and(_.id <= maxTimeuuid(start.plusSeconds(-2 * intervalOffset)))
.fetch()
} yield get
} yield records

whenReady(chain) { res =>
res.size shouldEqual 0
Expand Down
1 change: 1 addition & 0 deletions readme/src/main/tut/basics/tables.md
Expand Up @@ -122,6 +122,7 @@ abstract class ExampleRecord extends Table[ExampleRecord, ExampleModel] {
object name extends StringColumn
object props extends MapColumn[String, String]
object test extends OptionalIntColumn
}
```


Expand Down

0 comments on commit e697232

Please sign in to comment.