Skip to content

Commit

Permalink
Schema validator (#50)
Browse files Browse the repository at this point in the history
* Adds the schema provider and schema validator

* Improves the schema provider and validator

* Adds tests for the schema provider and validator
  • Loading branch information
Fede Fernández authored Aug 16, 2017
1 parent fda39a7 commit 9cfe86e
Show file tree
Hide file tree
Showing 16 changed files with 491 additions and 350 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ lazy val commonDependencies: Seq[ModuleID] = Seq(
%("cassandra-driver-core"),
%("cassandra-driver-mapping"),
%("cassandra-driver-extras"),
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.6"
"io.github.cassandra-scala" %% "troy-schema" % "0.4.0"
)

lazy val testDependencies: Seq[ModuleID] =
Expand All @@ -35,5 +35,6 @@ lazy val core = project
.in(file("core"))
.settings(moduleName := "freestyle-cassandra-core")
.settings(scalaMetaSettings)
.settings(resolvers += Resolver.bintrayRepo("tabdulradi", "maven"))
.settings(libraryDependencies ++= commonDependencies)
.settings(libraryDependencies ++= testDependencies)
86 changes: 0 additions & 86 deletions core/src/main/scala/schema/model.scala

This file was deleted.

37 changes: 37 additions & 0 deletions core/src/main/scala/schema/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2017 47 Degrees, LLC. <http://www.47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package freestyle.cassandra

import troy.cql.ast.{DataDefinition, DataManipulation}

package object schema {

sealed abstract class SchemaError(msg: String, maybeCause: Option[Throwable] = None)
extends RuntimeException(msg) {
maybeCause foreach initCause
}

case class SchemaDefinitionProviderError(msg: String, maybeCause: Option[Throwable] = None)
extends SchemaError(msg, maybeCause)

case class SchemaValidatorError(msg: String, maybeCause: Option[Throwable] = None)
extends SchemaError(msg, maybeCause)

type SchemaDefinition = Seq[DataDefinition]
type Statement = DataManipulation

}
47 changes: 0 additions & 47 deletions core/src/main/scala/schema/parser/decoders.scala

This file was deleted.

42 changes: 0 additions & 42 deletions core/src/main/scala/schema/parser/definitions.scala

This file was deleted.

75 changes: 0 additions & 75 deletions core/src/main/scala/schema/parser/parsers.scala

This file was deleted.

34 changes: 34 additions & 0 deletions core/src/main/scala/schema/provider/TroySchemaProvider.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2017 47 Degrees, LLC. <http://www.47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package freestyle.cassandra
package schema.provider

import freestyle.cassandra.schema._
import troy.cql.ast.CqlParser

class TroySchemaProvider(cql: String) extends SchemaDefinitionProvider {

override def schemaDefinition: Either[SchemaDefinitionProviderError, SchemaDefinition] =
CqlParser.parseSchema(cql) match {
case CqlParser.Success(res, _) => Right(res)
case CqlParser.Failure(msg, next) =>
Left(
SchemaDefinitionProviderError(
s"Parse Failure: $msg, line = ${next.pos.line}, column = ${next.pos.column}"))
case CqlParser.Error(msg, _) => Left(SchemaDefinitionProviderError(msg))
}
}
26 changes: 26 additions & 0 deletions core/src/main/scala/schema/provider/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2017 47 Degrees, LLC. <http://www.47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package freestyle.cassandra
package schema

package object provider {

trait SchemaDefinitionProvider {
def schemaDefinition: Either[SchemaDefinitionProviderError, SchemaDefinition]
}

}
Loading

0 comments on commit 9cfe86e

Please sign in to comment.