Permalink
Browse files

Replace fakeNullable with asOption. Backward compatibility.

  • Loading branch information...
1 parent e29c091 commit 82d39b41ee22da14ad265e0deedf06191e50c628 @rfuerst87 rfuerst87 committed Aug 30, 2016
@@ -88,13 +88,15 @@ abstract class AbstractGenerator[Code,TermName,TypeName](model: m.Model)
/** If HList should be used as a compound type instead of tuples. Default to true for > 22 columns.
@group Basic customization overrides */
def hlistEnabled = columns.size > 22
- /** Indicates whether auto increment columns should be put last.
+ /** Indicates whether auto increment columns should be put last and made an Option with a None default.
Please set to !hlistEnabled for switching this on.
@group Basic customization overrides */
- def autoIncLast = false
- /** Indicates whether auto increment columns should be made an Option with a None default.
+ @deprecated("Use autoIncLast and ColumnDef.asOption instead.", "3.2.0")
+ def autoIncLastAsOption = false
+ /** Indicates whether auto increment columns should be put last.
+ Please set to !hlistEnabled for switching this on.
@group Basic customization overrides */
- def autoIncAsOption = false
+ def autoIncLast = autoIncLastAsOption
/** Indicates if this table should be mapped using factory and extractor or not, in which case tuples are used. (Consider overriding EntityType.enabled instead, which affects this, too.) Disabled by default when using hlists.
@group Basic customization overrides */
def mappingEnabled = !hlistEnabled
@@ -218,18 +220,20 @@ abstract class AbstractGenerator[Code,TermName,TypeName](model: m.Model)
*/
def rawType: Code = parseType(model.tpe)
/**
- * Indicates whether the exposed type of this column should be wrapped in an Option. Useful for automatically created columns.
+ * Indicates whether the exposed type of this column should be wrapped in an Option. Useful for autoInc and automatically created columns.
+ * Set to autoInc to expose autoInc columns as Option.
* @group Basic customization overrides
*/
- def exposeOption = false
+ def asOption = fakeNullable
/** Possibly Option-wrapped Scala type of this column. @see rawType and @see exposedType */
final def actualType: Code = if(model.nullable) optionType(rawType) else rawType
/** Option of actualType if fakeNullable else actualType. */
- final def exposedType: Code = if(fakeNullable) optionType(actualType) else actualType
- /** Indicates whether this column should be user facing as a nullable column with default None even though it is not. Useful for autoInc and automatically created columns. */
- final def fakeNullable = exposeOption || (autoIncAsOption && autoInc)
+ final def exposedType: Code = if(asOption) optionType(actualType) else actualType
+ /** Indicates whether this column should be user facing as a nullable column with default None even though it is not. Useful for autoInc columns. */
+ @deprecated("Use asOption instead.", "3.2.0")
+ final def fakeNullable = autoIncLastAsOption && autoInc
- assert(!(model.nullable && fakeNullable),s"Cannot enable 'fakeNullable' for a 'nullable' column. $model")
+ assert(!(model.nullable && asOption),s"Cannot enable 'fakeNullable' for a 'nullable' column. $model")
/** Indicates whether this is an auto increment column */
final def autoInc = model.options.contains(ColumnOption.AutoInc)
@@ -247,7 +251,7 @@ abstract class AbstractGenerator[Code,TermName,TypeName](model: m.Model)
/** Generates a literal represenation of the default value or None in case of an Option-typed autoinc column */
def default: Option[Code] = model.options.collect{
case RelationalProfile.ColumnOption.Default(value) => value
- case _ if fakeNullable => None
+ case _ if asOption => None
}.map(defaultCode).headOption
def rawName: String = model.name.toCamelCase.uncapitalize
@@ -93,7 +93,7 @@ def $name($args): $name = {
trait PlainSqlMapperDef extends super.PlainSqlMapperDef{
def code = {
- val positional = compoundValue(columnsPositional.map(c => (if(c.fakeNullable || c.model.nullable)s"<<?[${c.rawType}]"else s"<<[${c.rawType}]")))
+ val positional = compoundValue(columnsPositional.map(c => (if(c.asOption || c.model.nullable)s"<<?[${c.rawType}]"else s"<<[${c.rawType}]")))
val dependencies = columns.map(_.exposedType).distinct.zipWithIndex.map{ case (t,i) => s"""e$i: GR[$t]"""}.mkString(", ")
val rearranged = compoundValue(desiredColumnOrder.map(i => if(hlistEnabled) s"r($i)" else tuple(i)))
def result(args: String) = if(mappingEnabled) s"$factory($args)" else args
@@ -117,7 +117,7 @@ implicit def ${name}(implicit $dependencies): GR[${TableClass.elementType}] = GR
trait TableClassDef extends super.TableClassDef{
def star = {
- val struct = compoundValue(columns.map(c=>if(c.fakeNullable)s"Rep.Some(${c.name})" else s"${c.name}"))
+ val struct = compoundValue(columns.map(c=>if(c.asOption)s"Rep.Some(${c.name})" else s"${c.name}"))
val rhs = if(mappingEnabled) s"$struct <> ($factory, $extractor)" else struct
s"def * = $rhs"
}
@@ -129,7 +129,7 @@ implicit def ${name}(implicit $dependencies): GR[${TableClass.elementType}] = GR
def optionFactory = {
val accessors = columns.zipWithIndex.map{ case(c,i) =>
val accessor = if(columns.size > 1) tuple(i) else "r"
- if(c.fakeNullable || c.model.nullable) accessor else s"$accessor.get"
+ if(c.asOption || c.model.nullable) accessor else s"$accessor.get"
}
val fac = s"$factory(${compoundValue(accessors)})"
val discriminator = columns.zipWithIndex.collect{ case (c,i) if !c.model.nullable => if(columns.size > 1) tuple(i) else "r" }.headOption
@@ -76,7 +76,9 @@ val SimpleA = CustomTyping.SimpleA
override def generator = tdb.profile.createModel(ignoreInvalidDefaults=false).map(new MyGen(_) {
override def Table = new Table(_){
override def autoIncLast = true
- override def autoIncAsOption = true
+ override def Column = new Column(_){
+ override def asOption = autoInc
+ }
}
})
},
@@ -85,7 +87,7 @@ val SimpleA = CustomTyping.SimpleA
override def generator = tdb.profile.createModel(ignoreInvalidDefaults=false).map(new MyGen(_) {
override def Table = new Table(_){
override def Column = new Column(_){
- override def exposeOption = true
+ override def asOption = true
}
}
})
@@ -30,7 +30,9 @@ object GenerateRoundtripSources {
val a2 = profile.createModel(ignoreInvalidDefaults=false).map(m => new SourceCodeGenerator(m) {
override def Table = new Table(_){
override def autoIncLast = true
- override def autoIncAsOption = true
+ override def Column = new Column(_){
+ override def asOption = autoInc
+ }
}
})
val db = Database.forURL(url=url, driver=jdbcDriver, keepAliveConnection=true)

0 comments on commit 82d39b4

Please sign in to comment.