Skip to content

Commit

Permalink
Merge 99cbf31 into 468f057
Browse files Browse the repository at this point in the history
  • Loading branch information
alexflav23 committed Jun 12, 2019
2 parents 468f057 + 99cbf31 commit bb6cdb8
Show file tree
Hide file tree
Showing 26 changed files with 203 additions and 124 deletions.
Expand Up @@ -56,4 +56,5 @@ object DefaultVersions {
val `3.6.0` = Version(3, 6, 0)
val `3.7.0` = Version(3, 7, 0)
val `3.8.0` = Version(3, 8, 0)
val `3.10.0` = Version(3, 10, 0)
}
Expand Up @@ -174,6 +174,10 @@ private[phantom] trait ImplicitMechanism extends ModifyMechanism {
new MapEntriesConditionals[K, V](cond)
}

implicit def nonIndexedColumnQueries[RR : Primitive](col: AbstractColumn[RR])(
implicit ev: col.type <:!< Indexed
): QueryColumn[RR] = new QueryColumn[RR](col.name)

implicit def partitionColumnQueries[RR : Primitive](
col: AbstractColumn[RR] with PartitionKey
): PartitionQueryColumn[RR] = new PartitionQueryColumn[RR](col.name)
Expand Down
Expand Up @@ -24,7 +24,9 @@ private[phantom] trait Unmodifiable
private[phantom] trait Indexed

object Indexed {
implicit def indexedToQueryColumn[T : Primitive](col: AbstractColumn[T] with Indexed): QueryColumn[T] = {
implicit def indexedToQueryColumn[T : Primitive](
col: AbstractColumn[T] with Indexed
): QueryColumn[T] = {
new QueryColumn(col.name)
}

Expand Down
Expand Up @@ -44,7 +44,7 @@ class InsertTest extends PhantomSuite {
val row = gen[OldPrimitiveRecord].copy(timeuuid = UUIDs.timeBased())

val chain = for {
store <- database.oldPrimitives.store(row).future()
_ <- database.oldPrimitives.store(row).future()
one <- database.oldPrimitives.select.where(_.pkey eqs row.pkey).one
} yield one

Expand All @@ -57,7 +57,7 @@ class InsertTest extends PhantomSuite {
val row = gen[PrimitiveRecord]

val chain = for {
store <- database.primitives.store(row).future()
_ <- database.primitives.store(row).future()
one <- database.primitives.select.where(_.pkey eqs row.pkey).one
} yield one

Expand All @@ -68,11 +68,10 @@ class InsertTest extends PhantomSuite {

if (session.v4orNewer) {
"Insert" should "work fine for primitives cassandra 2.2 columns" in {
JodaTimeSampler
val row = gen[PrimitiveCassandra22]

val chain = for {
store <- database.primitivesCassandra22.store(row).future()
_ <- database.primitivesCassandra22.store(row).future()
one <- database.primitivesCassandra22.select.where(_.pkey eqs row.pkey).one
} yield one

Expand All @@ -86,7 +85,7 @@ class InsertTest extends PhantomSuite {
val row = gen[TestRow].copy(key = "test'", mapIntToInt = Map.empty[Int, Int])

val chain = for {
store <- database.testTable.store(row).future()
_ <- database.testTable.store(row).future()
one <- database.testTable.select.where(_.key eqs row.key).one
} yield one

Expand All @@ -99,7 +98,7 @@ class InsertTest extends PhantomSuite {
val row = gen[TestRow].copy(mapIntToInt = Map.empty)

val chain = for {
store <- database.testTable.store(row).future()
_ <- database.testTable.store(row).future()
one <- database.testTable.select.where(_.key eqs row.key).one
} yield one

Expand All @@ -112,7 +111,7 @@ class InsertTest extends PhantomSuite {
val recipe = gen[Recipe]

val chain = for {
store <- database.recipes.store(recipe).future()
_ <- database.recipes.store(recipe).future()
one <- database.recipes.select.where(_.url eqs recipe.url).one
} yield one

Expand All @@ -131,7 +130,7 @@ class InsertTest extends PhantomSuite {
val row = gen[MyTestRow].copy(stringlist = List.empty)

val chain = for {
store <- database.listCollectionTable.store(row).future()
_ <- database.listCollectionTable.store(row).future()
one <- database.listCollectionTable.select.where(_.key eqs row.key).one
} yield one

Expand All @@ -145,7 +144,7 @@ class InsertTest extends PhantomSuite {
val row = gen[MyTestRow]

val chain = for {
store <- database.listCollectionTable.store(row).future()
_ <- database.listCollectionTable.store(row).future()
get <- database.listCollectionTable.select.where(_.key eqs row.key).one
} yield get

Expand All @@ -158,7 +157,7 @@ class InsertTest extends PhantomSuite {
val sample = gen[Recipe]

val chain = for {
store <- database.recipes.insert.json(compactJson(renderJValue(Extraction.decompose(sample)))).future()
_ <- database.recipes.insert.json(compactJson(renderJValue(Extraction.decompose(sample)))).future()
get <- database.recipes.select.where(_.url eqs sample.url).one()
} yield get

Expand All @@ -176,7 +175,7 @@ class InsertTest extends PhantomSuite {
val sample = gen[OptTypesRecord].copy(wrapped = None)

val chain = for {
store <- database.optDerivedTable.store(sample).future()
_ <- database.optDerivedTable.store(sample).future()
res <- database.optDerivedTable.select.where(_.pkey eqs sample.pkey).one()
} yield res

Expand All @@ -190,7 +189,7 @@ class InsertTest extends PhantomSuite {
val sample = gen[OptTypesRecord]

val chain = for {
store <- database.optDerivedTable.store(sample).future()
_ <- database.optDerivedTable.store(sample).future()
res <- database.optDerivedTable.select.where(_.pkey eqs sample.pkey).one()
} yield res

Expand Down
Expand Up @@ -51,7 +51,7 @@ class ListOperatorsTest extends PhantomSuite {

whenReady(operation) { items =>
items.value shouldEqual recipe.ingredients
items.value should have size recipe.ingredients.size
items.value should have size recipe.ingredients.size.toLong
}
}

Expand Down
Expand Up @@ -35,8 +35,8 @@ class MapOperationsTest extends PhantomSuite {
val (key , value) = gen[(String, String)]

val operation = for {
insertDone <- database.recipes.store(recipe).future()
update <- database.recipes.update.where(_.url eqs recipe.url).modify(_.props set (key, value)).future()
_ <- database.recipes.store(recipe).future()
_ <- database.recipes.update.where(_.url eqs recipe.url).modify(_.props set (key, value)).future()

select <- database.recipes.select(_.props).where(_.url eqs recipe.url).one
} yield select
Expand All @@ -55,8 +55,8 @@ class MapOperationsTest extends PhantomSuite {
val query = database.recipes.update.where(_.url eqs ?).modify(_.props set ?).prepareAsync()

val operation = for {
insertDone <- database.recipes.store(recipe).future()
update <- query.flatMap(_.bind(key, value, recipe.url).future())
_ <- database.recipes.store(recipe).future()
_ <- query.flatMap(_.bind(key, value, recipe.url).future())
select <- database.recipes.select(_.props).where(_.url eqs recipe.url).one
} yield select

Expand All @@ -73,8 +73,8 @@ class MapOperationsTest extends PhantomSuite {
val item = gen[(String, String)]

val operation = for {
insertDone <- database.recipes.store(recipe).future()
update <- database.recipes.update.where(_.url eqs recipe.url).modify(_.props put item).future()
_ <- database.recipes.store(recipe).future()
_ <- database.recipes.update.where(_.url eqs recipe.url).modify(_.props put item).future()
select <- database.recipes.select(_.props).where(_.url eqs recipe.url).one
} yield select

Expand All @@ -89,8 +89,8 @@ class MapOperationsTest extends PhantomSuite {
val mapItems = genMap[String, String](mapSize)

val operation = for {
insertDone <- database.recipes.store(recipe).future()
update <- database.recipes.update.where(_.url eqs recipe.url).modify(_.props putAll mapItems).future()
_ <- database.recipes.store(recipe).future()
_ <- database.recipes.update.where(_.url eqs recipe.url).modify(_.props putAll mapItems).future()
select <- database.recipes.select(_.props).where(_.url eqs recipe.url).one
} yield select

Expand All @@ -107,8 +107,8 @@ class MapOperationsTest extends PhantomSuite {
val updateQuery = database.recipes.update.where(_.url eqs ?).modify(_.props putAll ?).prepareAsync()

val operation = for {
insertDone <- database.recipes.store(recipe).future()
update <- updateQuery.flatMap(_.bind(mapItems, recipe.url).future())
_ <- database.recipes.store(recipe).future()
_ <- updateQuery.flatMap(_.bind(mapItems, recipe.url).future())
select <- database.recipes.select(_.props).where(_.url eqs recipe.url).one
} yield select

Expand All @@ -124,8 +124,8 @@ class MapOperationsTest extends PhantomSuite {
val postRemove = recipe.props - removals

val operation = for {
insertDone <- database.recipes.store(recipe).future()
update <- database.recipes.update
_ <- database.recipes.store(recipe).future()
_ <- database.recipes.update
.where(_.url eqs recipe.url)
.modify(_.props - removals)
.future()
Expand All @@ -145,8 +145,8 @@ class MapOperationsTest extends PhantomSuite {
}

val operation = for {
insertDone <- database.recipes.store(recipe).future()
update <- database.recipes.update
_ <- database.recipes.store(recipe).future()
_ <- database.recipes.update
.where(_.url eqs recipe.url)
.modify(_.props - removals)
.future()
Expand All @@ -162,13 +162,11 @@ class MapOperationsTest extends PhantomSuite {
val event = gen[SampleEvent]

val chain = for {
store <- database.events.store(event).future()
get <- database.events.findById(event.id)
} yield get
_ <- database.events.store(event).future()
res <- database.events.findById(event.id)
} yield res

whenReady(chain) {
res => res.value shouldEqual event
}
whenReady(chain) { res => res.value shouldEqual event }
}

it should "allow storing maps that use Scala primitives who do not have a TypeCodec" in {
Expand All @@ -182,9 +180,9 @@ class MapOperationsTest extends PhantomSuite {
)

val chain = for {
store <- database.scalaPrimitivesTable.store(sample).future()
get <- database.scalaPrimitivesTable.findById(sample.id)
} yield get
_ <- database.scalaPrimitivesTable.store(sample).future()
res <- database.scalaPrimitivesTable.findById(sample.id)
} yield res

whenReady(chain) { res =>
res.value shouldEqual sample
Expand All @@ -206,14 +204,14 @@ class MapOperationsTest extends PhantomSuite {
)

val chain = for {
store <- database.scalaPrimitivesTable.store(sample).future()
get <- database.scalaPrimitivesTable.findById(sample.id)
update <- database.scalaPrimitivesTable.update
_ <- database.scalaPrimitivesTable.store(sample).future()
res <- database.scalaPrimitivesTable.findById(sample.id)
_ <- database.scalaPrimitivesTable.update
.where(_.id eqs sample.id)
.modify(_.map(updateKey) setTo BigDecimal(updatedValue))
.future()
get2 <- database.scalaPrimitivesTable.findById(sample.id)
} yield (get, get2)
res2 <- database.scalaPrimitivesTable.findById(sample.id)
} yield (res, res2)

whenReady(chain) { case (beforeUpdate, afterUpdate) =>
beforeUpdate.value shouldEqual sample
Expand Down
Expand Up @@ -34,7 +34,7 @@ class SelectJsonTest extends PhantomSuite {
val row = gen[PrimitiveRecord]

val chain = for {
store <- database.primitives.store(row).future()
_ <- database.primitives.store(row).future()
b <- database.primitives.select.json().where(_.pkey eqs row.pkey).one
} yield b

Expand All @@ -56,7 +56,7 @@ class SelectJsonTest extends PhantomSuite {
val expected = row.take(Nat._8)

val chain = for {
store <- database.primitives.store(row).future()
_ <- database.primitives.store(row).future()
one <- database.primitives.select(_.pkey, _.long, _.boolean, _.bDecimal, _.double, _.float, _.inet, _.int)
.json()
.where(_.pkey eqs row.pkey).one()
Expand Down
Expand Up @@ -19,6 +19,7 @@ import com.outworkers.phantom.PhantomSuite
import com.outworkers.phantom.builder.query.bugs.UserSchema
import com.outworkers.phantom.dsl._
import com.outworkers.phantom.tables._
import com.outworkers.phantom.tables.bugs.TokenRecord
import com.outworkers.util.samplers._

class SelectTest extends PhantomSuite {
Expand All @@ -27,6 +28,7 @@ class SelectTest extends PhantomSuite {
super.beforeAll()
val _ = database.primitives.createSchema()
database.userSchema.createSchema()
database.tokensTable.createSchema()
}

"Selecting the whole row" should "work fine" in {
Expand Down Expand Up @@ -70,4 +72,21 @@ class SelectTest extends PhantomSuite {
res.value shouldEqual row.id
}
}

it should "allowFiltering on partition key columns with Cassandra 3.10+" in {
if (cassandraVersion.value > Version.`3.10.0`) {

val counter = gen[Int]
val rows = genList[TokenRecord]().map(_.copy(counter = counter))

val chain = for {
_ <- database.tokensTable.storeRecords(rows)
res <- database.tokensTable.expired(counter)
} yield res

whenReady(chain) { res =>
res should contain allElementsOf rows
}
}
}
}
Expand Up @@ -31,10 +31,10 @@ class TruncateTest extends PhantomSuite {
val articles = genList[Article]()

val result = for {
truncateBefore <- database.articles.truncate.future()
store <- database.articles.storeRecords(articles)
_ <- database.articles.truncate.future()
_ <- database.articles.storeRecords(articles)
records <- database.articles.select.fetch
truncate <- database.articles.truncate.future()
_ <- database.articles.truncate.future()
records1 <- database.articles.select.fetch
} yield (records, records1)

Expand All @@ -52,10 +52,10 @@ class TruncateTest extends PhantomSuite {
val articles = genList[Article]()

val result = for {
truncateBefore <- database.articles.truncate.future()
i1 <- database.articles.storeRecords(articles)
_ <- database.articles.truncate.future()
_ <- database.articles.storeRecords(articles)
records <- database.articles.select.fetch
truncate <- database.articles.truncate.consistencyLevel_=(ConsistencyLevel.ONE).future()
_ <- database.articles.truncate.consistencyLevel_=(ConsistencyLevel.ONE).future()
records1 <- database.articles.select.fetch
} yield (records, records1)

Expand Down

0 comments on commit bb6cdb8

Please sign in to comment.