Skip to content

Commit

Permalink
Feature/updating docs (#660)
Browse files Browse the repository at this point in the history
* Using  instead of  for Database members.

* Fixing collection type.

* Removing toSeq manual conversion

* Changing the collection used to Seq.

* More linting

* Updating readmes with more informationg

* Adding more docs

* Moving stuff over

* Adding batch documentation

* Adding schema bug investigation.

* Adding a databaseprovider.

* Removing bad files

* Fixing log4j

* Adding a WARN statement
  • Loading branch information
alexflav23 authored Apr 13, 2017
1 parent 92d1fb2 commit 683500b
Show file tree
Hide file tree
Showing 31 changed files with 600 additions and 199 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This is a table of the available modules for the various Scala versions. Not all

Modules marked with "x" are still in beta or pre-publishing mode.

| Module name | Scala 2.10.x | Scala 2.11.x | Scala 2.12.0 | Release date |
| Module name | Scala 2.10.x | Scala 2.11.x | Scala 2.12.0 | Release date |
| ------------ | ------------------- | ------------------| ----------------- | -------------- |
| phantom-dse | <span>yes</span> | <span>yes</span> | <span>yes</span> | Released |
| phantom-udt | <span>yes</span> | <span>yes</span> | <span>yes</span> | Released |
Expand All @@ -51,6 +51,8 @@ Modules marked with "x" are still in beta or pre-publishing mode.
| phantom-spark | <span>x</span> | <span>x</span> | <span>x</span> | July 2017 |
| phantom-solr | <span>x</span> | <span>x</span> | <span>x</span> | July 2017 |
| phantom-migrations | <span>x</span> | <span>x</span> | <span>x</span> | September 2017 |
| phantom-native | <span>x</span> | <span>x</span> | <span>x</span> | December 2017 |
| phantom-java-dsl | <span>x</span> | <span>x</span> | <span>x</span> | December 2017 |

Using phantom
=============
Expand Down
66 changes: 16 additions & 50 deletions comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ So why not just use the Datastax driver for Scala? We would like to start by say
#### Cons of using the Java driver from Scala

- Writing queries is not type-safe, and the `QueryBuilder` is mutable.
- There is no DSL to define the tables, so dealing with them is still very much manual and string based.
- There is no DSL to define the tables, so dealing with them is still very much manual and string based.
- Auto-generation of schema is not available, the CQL for tables or anything else must be manually created.
- The driver does not and cannot prevent you from doing bad things.
- You must constantly refer to the `session`.
Expand All @@ -61,6 +61,7 @@ It is built on top of the Datastax Java driver, and uses all the default connect

- A type safe Schema DSL that means you never have to deal with raw CQL again.
- A very advanced compile time mechanism that offers a fully type safe variant of CQL.
- A tool that prevents you from doing any "bad" things by enforcing Cassandra rules at compile time.
- A natural DSL that doesn't require any new terminology and aims to introduce a minimal learning curve. Phantom is not a leaking abstraction and it is exclusively built to target Cassnadra integration, therefore it has support for all the latest features of CQL and doesn't require constantly mapping terminology. Unlike LINQ style DSLs for instance, the naming will largely have 100% correspondence to CQL terminology you are already used to.
- Automated schema generation, automated table migrations, automated database generation and more, meaning you will never ever have to manually initialise CQL tables from scripts ever again.
- Native support of Scala concurrency primitives, from `scala.concurrent.Future` to more advanced access patterns such as reactive streams or even iteratees, available via separate dependencies.
Expand Down Expand Up @@ -117,43 +118,9 @@ case class Recipe(
side_id: UUID
)

class Recipes extends CassandraTable[ConcreteRecipes, Recipe] {
class Recipes extends CassandraTable[Recipes, Recipe] {

object url extends StringColumn(this) with PartitionKey[String]

object description extends OptionalStringColumn(this)

object ingredients extends ListColumn[String](this)

object servings extends OptionalIntColumn(this)

object lastcheckedat extends DateTimeColumn(this)

object props extends MapColumn[String, String](this)

object side_id extends UUIDColumn(this)


override def fromRow(r: Row): Recipe = {
Recipe(
url(r),
description(r),
ingredients(r),
servings(r),
lastcheckedat(r),
props(r),
side_id(r)
)
}
}
```

As of version 2.0.0, phantom is capable of auto-generating the `fromRow` method, so the mapping DSL is reduced to:

```
abstract class Recipes extends CassandraTable[ConcreteRecipes, Recipe] with RootConnector {
object url extends StringColumn(this) with PartitionKey[String]
object url extends StringColumn(this) with PartitionKey

object description extends OptionalStringColumn(this)

Expand Down Expand Up @@ -196,7 +163,7 @@ not possible in either of quill or the Java driver, because they do not operate
database.recipes.select.where(_.uid eqs someid)
```

Quill, *based on our current understanding, will however happily compile and generate the query, it has no way
Quill, *based on our current understanding*, will however happily compile and generate the query, it has no way
to know what you wanted to do with the `side_id` column.


Expand Down Expand Up @@ -236,7 +203,7 @@ In this category, both tools are imperfect and incomplete, and phantom has its o
the Quill comparison simply states: "You could extend Phantom by extending the DSL to add new features,
although it might not be a straightforward process.", which is a bit inaccurate.

Being a very new player in the game, Quill is a nice toy when it comes to Cassandra feature support
Being a very new player in the game, Quill is a nice toy when it comes to Cassandra feature support
and you will often find yourself needing to add features. Phantom has its gaps without a doubt, but it's a far far more mature alternative,
and the amount of times when extension is required are significantly rarer.

Expand All @@ -261,22 +228,21 @@ play-streams somewhere else in you app, otherwise it makes little sense to not s
much impossible to build Thrift services without a dependency on Thrift itself, so in that respect it is highly
unlikely that using those extra modules will end up bringing in more dependencies than you already have.

- The one place where phantom used to suck is the dependency on `scala-reflect`, which is causing some ugly things inside the
framework, namely the need for global locks to make reflection thread safe in the presence of multiple class loaders. This
is however going away in 2.0.0, already available on `feature/2.0.0`, and we are replacing `scala-reflect` with a macro based approach.
- The one place where phantom used to suck is the dependency on `scala-reflect`, which is causing some ugly things inside the
framework, namely the need for global locks to make reflection thread safe in the presence of multiple class loaders. This
is now a part of history, as of 2.x.x and up, we have entirely replaced the runtime mechanism with macros.

- The only notable dependencies of phantom are `shapeless` and `cassandra-driver-core`, the latter of which you will have
inevitably. Shapeless is also quite light and compile time, it depends only on macro libraries such as `macro-compat`. You
can have a look yourself [here](https://github.com/milessabin/shapeless). We also depend on an internal engine called the
diesel engine, which itself only depends on `macro-compat`, since it's nothing more than a customised macro toolchain.
inevitably. Shapeless is also quite light and compile time, it depends only a minuscule macro library called `macro-compat` which phantom also requires for its own macros. You
can have a look yourself [here](https://github.com/milessabin/shapeless). `phantom-dsl` has no other dependencies.

#### Documentation and commercial support

Both tools can do a lot better in this category, but phantom is probably doing a little better in that department,
Both tools can do a lot better in this category, but phantom is probably doing a little better in that department,
since we have a plethora of tests, blog posts, and resources, on how to do things in phantom. This is not yet
necessarily true of Quill, and we know very well just how challenging the ramp up process to stability can be.

In terms of commercial support, phantom wins. We don't mean to start a debase on the virtues of open source, and
In terms of commercial support, phantom wins. We don't mean to start a debase on the virtues of open source, and
we are aware most of the development community strongly favours OSS licenses and the word "commercial" is unpleasant.
However, we are constrained by the economic reality of having to pay the people competent enough to write this software
for the benefit of us all and make sure they get enough spare time to focus on these things, which is a lot less fun.
Expand All @@ -299,8 +265,8 @@ Let's sum up the points that we tried to make here in two key paragraphs.
- Phantom used to make it less interesting to extend support for custom types, however this is now trivially
done with `Primitive.derive`, which allows users to support new types by leveraging existing primitives.

- Quill is an excellence piece of software and it has theoretically less boilerplate than phantom. there's boilerplate that can be reduced through QDSLs that cannot be reduced through an EDSL, if we are fighting who's the leanest meanest string generator Quill wins.
- Quill is an excellent piece of software and it has theoretically less boilerplate than phantom. there's boilerplate that can be reduced through QDSLs that cannot be reduced through an EDSL, if we are fighting who's the leanest meanest string generator Quill wins.
It's a vastly inferior tool at the application layer, and in supports such a small subset of Cassandra features it's barely usable for anything real world, and it's even more unnatural for most people. Slick popularised the concepts to some extent, but some of the most basic functionalities you would want as part of your application lifecycle are not as easily addressable through a QDSL or at least it has yet to happen.
Phantom is far more mature, feature rich, battle tested, and very widely adopted, with more resources and input from the founding team, a long standing roadmap and a key partnership with Datastax that helps us stay on top of all features.

- Phantom is a lot easier to adopt and learn, simply as it doesn't introduce any new terminology. The mapping DSL and the `Database` object are all you need to know, so the learning curve is minimal.
- Phantom is a lot easier to adopt and learn, simply as it doesn't introduce any new terminology. The mapping DSL and the `Database` object are all you need to know, so the learning curve is minimal.
5 changes: 1 addition & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
phantom
[![Build Status](https://travis-ci.org/outworkers/phantom.svg?branch=develop)](https://travis-ci.org/outworkers/phantom?branch=develop) [![Coverage Status](https://coveralls.io/repos/outworkers/phantom/badge.svg)](https://coveralls.io/r/outworkers/phantom) [![Codacy Rating](https://api.codacy.com/project/badge/grade/25bee222a7d142ff8151e6ceb39151b4)](https://www.codacy.com/app/flavian/phantom_2) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.outworkers/phantom-dsl_2.11/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.outworkers/phantom-dsl_2.11) [![Bintray](https://api.bintray.com/packages/outworkers/oss-releases/phantom-dsl/images/download.svg) ](https://bintray.com/outworkers/oss-releases/phantom-dsl/_latestVersion) [![ScalaDoc](http://javadoc-badge.appspot.com/com.outworkers/phantom-dsl_2.11.svg?label=scaladoc)](http://javadoc-badge.appspot.com/com.outworkers/phantom-dsl_2.11) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/outworkers/phantom?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
===============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
===============================================================================================================================

Reactive type-safe Scala driver for Apache Cassandra/Datastax Enterprise

Expand All @@ -24,6 +24,3 @@ We offer a comprehensive range of elite Scala development services, including bu
- Advanced Scala and Cassandra training

We are huge advocates of open source and we will open source every project we can! To read more about our open source efforts, click [here](http://www.outworkers.com/work).



73 changes: 73 additions & 0 deletions docs/basics/batches.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
phantom
[![Build Status](https://travis-ci.org/outworkers/phantom.svg?branch=develop)](https://travis-ci.org/outworkers/phantom?branch=develop) [![Coverage Status](https://coveralls.io/repos/github/outworkers/phantom/badge.svg?branch=develop)](https://coveralls.io/github/outworkers/phantom?branch=develop) [![Codacy Rating](https://api.codacy.com/project/badge/grade/25bee222a7d142ff8151e6ceb39151b4)](https://www.codacy.com/app/flavian/phantom_2) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.outworkers/phantom-dsl_2.11/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.outworkers/phantom-dsl_2.11) [![Bintray](https://api.bintray.com/packages/outworkers/oss-releases/phantom-dsl/images/download.svg) ](https://bintray.com/outworkers/oss-releases/phantom-dsl/_latestVersion) [![ScalaDoc](http://javadoc-badge.appspot.com/com.outworkers/phantom-dsl_2.11.svg?label=scaladoc)](http://javadoc-badge.appspot.com/com.outworkers/phantom-dsl_2.11) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/outworkers/phantom?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
===============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
<a id="batch-statements">Batch statements</a>
=============================================

Phantom also brrings in support for batch statements. To use them, see [IterateeBigTest.scala](https://github.com/outworkers/phantom/blob/develop/phantom-dsl/src/test/scala/com/outworkers/phantom/builder/query/db/iteratee/IterateeBigReadPerformanceTest.scala). Before you read further, you should remember **batch statements are not used to improve performance**.

Read [the official docs](http://docs.datastax.com/en/cql/3.1/cql/cql_reference/batch_r.html) for more details, but in short **batches guarantee atomicity and they are about 30% slower on average than parallel writes** at least, as they require more round trips. If you think you're optimising performance with batches, you might need to find alternative means.

We have tested with 10,000 statements per batch, and 1000 batches processed simultaneously. Before you run the test, beware that it takes ~40 minutes.

Batches use lazy iterators and daisy chain them to offer thread safe behaviour. They are not memory intensive and you can expect consistent processing speed even with 1 000 000 statements per batch.

Batches are immutable and adding a new record will result in a new Batch, just like most things Scala, so be careful to chain the calls.

phantom also supports `COUNTER` batch updates and `UNLOGGED` batch updates.


<a id="logged-batch-statements">LOGGED batch statements</a>
===========================================================

```scala

import com.outworkers.phantom.dsl._

Batch.logged
.add(db.exampleTable.update.where(_.id eqs someId).modify(_.name setTo "blabla"))
.add(db.exampleTable.update.where(_.id eqs someOtherId).modify(_.name setTo "blabla2"))
.future()

```

<a id="counter-batch-statements">COUNTER batch statements</a>
============================================================
<a href="#table-of-contents">back to top</a>

```scala

import com.outworkers.phantom.dsl._

Batch.counter
.add(db.exampleTable.update.where(_.id eqs someId).modify(_.someCounter increment 500L))
.add(db.exampleTable.update.where(_.id eqs someOtherId).modify(_.someCounter decrement 300L))
.future()
```

Counter operations also offer a standard overloaded operator syntax, so instead of `increment` and `decrement`
you can also use `+=` and `-=` to achieve the same thing.

```scala

import com.outworkers.phantom.dsl._

Batch.counter
.add(db.exampleTable.update.where(_.id eqs someId).modify(_.someCounter += 500L))
.add(db.exampleTable.update.where(_.id eqs someOtherId).modify(_.someCounter _= 300L))
.future()
```

<a id="unlogged-batch-statements">UNLOGGED batch statements</a>
============================================================

```scala

import com.outworkers.phantom.dsl._

Batch.unlogged
.add(db.exampleTable.update.where(_.id eqs someId).modify(_.name setTo "blabla"))
.add(db.exampleTable.update.where(_.id eqs someOtherId).modify(_.name setTo "blabla2"))
.future()

```
Empty file added docs/basics/connectors.md
Empty file.
Loading

0 comments on commit 683500b

Please sign in to comment.