Class/Object

slick.codegen

SourceCodeGenerator

Related Docs: object SourceCodeGenerator | package codegen

Permalink

class SourceCodeGenerator extends AbstractSourceCodeGenerator with OutputHelpers

A customizable code generator for working with Slick.

For usage information please see the corresponding part of the Slick documentation.

The implementation is structured into a small hierarchy of sub-generators responsible for different fragments of the complete output. The implementation of each sub-generator can be swapped out for a customized one by overriding the corresponding factory method. SourceCodeGenerator contains a factory method Table, which it uses to generate a sub-generator for each table. The sub-generator Table in turn contains sub-generators for Table classes, entity case classes, columns, key, indices, etc. Custom sub-generators can easily be added as well.

Within the sub-generators the relevant part of the Slick data model can be accessed to drive the code generation.

Of coures it makes sense to integrate this into your build process.

Source
SourceCodeGenerator.scala
Linear Supertypes
OutputHelpers, AbstractSourceCodeGenerator, StringGeneratorHelpers, AbstractGenerator[String, String, String], GeneratorHelpers[String, String, String], AnyRef, Any
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. SourceCodeGenerator
  2. OutputHelpers
  3. AbstractSourceCodeGenerator
  4. StringGeneratorHelpers
  5. AbstractGenerator
  6. GeneratorHelpers
  7. AnyRef
  8. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new SourceCodeGenerator(model: Model)

    Permalink

    model

    Slick data model for which code should be generated.

Type Members

  1. implicit class StringExtensions extends AnyRef

    Permalink

    Slick code generator string extension methods.

    Slick code generator string extension methods. (Warning: Not unicode-safe, uses String#apply)

    Definition Classes
    GeneratorHelpers
  2. type Table = TableDef

    Permalink

    Table generator virtual class

    Table generator virtual class

    Definition Classes
    SourceCodeGeneratorAbstractGenerator
  3. class TableDef extends SourceCodeGenerator.TableDef

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from SourceCodeGenerator to any2stringadd[SourceCodeGenerator] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (SourceCodeGenerator, B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from SourceCodeGenerator to ArrowAssoc[SourceCodeGenerator] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  6. def Table: (model.Table) ⇒ TableDef

    Permalink

    Table generator factory.

    Table generator factory. Override for customization.

    Definition Classes
    SourceCodeGeneratorAbstractGenerator
  7. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  8. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. def code: String

    Permalink

    Generates code for the complete model (not wrapped in a package yet)

    Generates code for the complete model (not wrapped in a package yet)

    Definition Classes
    AbstractSourceCodeGenerator
  10. def codeForContainer: String

    Permalink

    Generates code for the container class (not wrapped in a package yet)

    Generates code for the container class (not wrapped in a package yet)

    Definition Classes
    AbstractSourceCodeGenerator
  11. def codeForDDL: String

    Permalink

    Generates code for the DDL statement.

    Generates code for the DDL statement.

    Definition Classes
    AbstractSourceCodeGenerator
  12. def codePerTable: Map[String, String]

    Permalink

    Generates a map that associates the table name with its generated code (not wrapped in a package yet).

    Generates a map that associates the table name with its generated code (not wrapped in a package yet).

    Definition Classes
    AbstractSourceCodeGenerator
  13. val ddlEnabled: Boolean

    Permalink

    Enables DDL Generation.

    Enables DDL Generation.

    Definition Classes
    AbstractGenerator
  14. def docWithCode(doc: String, code: String): String

    Permalink

    Assemble doc comment with scala code

    Assemble doc comment with scala code

    Definition Classes
    StringGeneratorHelpersGeneratorHelpers
  15. def ensuring(cond: (SourceCodeGenerator) ⇒ Boolean, msg: ⇒ Any): SourceCodeGenerator

    Permalink
    Implicit information
    This member is added by an implicit conversion from SourceCodeGenerator to Ensuring[SourceCodeGenerator] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  16. def ensuring(cond: (SourceCodeGenerator) ⇒ Boolean): SourceCodeGenerator

    Permalink
    Implicit information
    This member is added by an implicit conversion from SourceCodeGenerator to Ensuring[SourceCodeGenerator] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  17. def ensuring(cond: Boolean, msg: ⇒ Any): SourceCodeGenerator

    Permalink
    Implicit information
    This member is added by an implicit conversion from SourceCodeGenerator to Ensuring[SourceCodeGenerator] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  18. def ensuring(cond: Boolean): SourceCodeGenerator

    Permalink
    Implicit information
    This member is added by an implicit conversion from SourceCodeGenerator to Ensuring[SourceCodeGenerator] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  19. def entityName: (String) ⇒ String

    Permalink

    Maps database table name to entity case class name

    Maps database table name to entity case class name

    Definition Classes
    AbstractGenerator
  20. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  21. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  22. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  23. def formatted(fmtstr: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from SourceCodeGenerator to StringFormat[SourceCodeGenerator] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  24. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  25. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  26. def indent(code: String): String

    Permalink
    Definition Classes
    GeneratorHelpers
  27. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  28. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  29. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  30. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  31. final def optionType(t: String): String

    Permalink

    Wrap the given type into an Option type

    Wrap the given type into an Option type

    Definition Classes
    StringGeneratorHelpersGeneratorHelpers
  32. def packageCode(profile: String, pkg: String, container: String, parentType: Option[String]): String

    Permalink

    Generates code providing the data model as trait and object in a Scala package

    Generates code providing the data model as trait and object in a Scala package

    profile

    Slick profile that is imported in the generated package (e.g. slick.jdbc.H2Profile)

    pkg

    Scala package the generated code is placed in

    container

    The name of a trait and an object the generated code will be placed in within the specified package.

    Definition Classes
    OutputHelpers
  33. def packageContainerCode(profile: String, pkg: String, container: String = "Tables"): String

    Permalink

    Generates code providing the stand-alone slick data model for immediate use.

    Generates code providing the stand-alone slick data model for immediate use.

    profile

    Slick profile that is imported in the generated package (e.g. scala.slick.driver.H2Driver)

    pkg

    Scala package the generated code is placed in

    container

    The name of a trait and an object the generated code will be placed in within the specified package.

    Definition Classes
    OutputHelpers
  34. def packageTableCode(tableName: String, tableCode: String, pkg: String, container: String): String

    Permalink

    Generates code for the given table.

    Generates code for the given table. The tableName and tableCode parameters should come from the #codePerTable map.

    tableName

    : the name of the table

    tableCode

    : the generated code for the table.

    pkg

    Scala package the generated code is placed in

    container

    The name of the container

    Definition Classes
    OutputHelpers
  35. def parentType: Option[String]

    Permalink

    The parent type of the generated main trait.

    The parent type of the generated main trait. This can be overridden in subclasses.

    Definition Classes
    OutputHelpers
  36. def parseType(tpe: String): String

    Permalink

    Generates code for a qualified Scala type

    Generates code for a qualified Scala type

    Definition Classes
    StringGeneratorHelpersGeneratorHelpers
  37. val scalaKeywords: Seq[String]

    Permalink

    Words that are reserved keywords in Scala

    Words that are reserved keywords in Scala

    Definition Classes
    GeneratorHelpers
  38. def shouldQuoteIdentifier(s: String): Boolean

    Permalink
    Definition Classes
    StringGeneratorHelpers
  39. val slickTableTermMembersNoArgs: Seq[String]

    Permalink

    Existing term member names in Table[_] that do not take parameters

    Existing term member names in Table[_] that do not take parameters

    Definition Classes
    GeneratorHelpers
  40. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  41. def tableName: (String) ⇒ String

    Permalink

    Maps database table name to Table class and value name

    Maps database table name to Table class and value name

    Definition Classes
    AbstractGenerator
  42. final lazy val tables: Seq[Table]

    Permalink

    Table code generators.

    Table code generators.

    Definition Classes
    AbstractGenerator
  43. final lazy val tablesByName: Map[QualifiedName, Table]

    Permalink

    Table code generators indexed by db table name.

    Table code generators indexed by db table name.

    Definition Classes
    AbstractGenerator
  44. def termName(name: String): String

    Permalink

    Marks a String as a TermName (e.g.

    Marks a String as a TermName (e.g. for escaping scala keywords)

    Definition Classes
    StringGeneratorHelpersGeneratorHelpers
  45. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  46. def tuple(i: Int): String

    Permalink
    Attributes
    protected
    Definition Classes
    AbstractSourceCodeGenerator
  47. def typeName(name: String): String

    Permalink

    Marks a String as a TypeName (e.g.

    Marks a String as a TypeName (e.g. for escaping scala keywords)

    Definition Classes
    StringGeneratorHelpersGeneratorHelpers
  48. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  49. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  50. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  51. def writeStringToFile(content: String, folder: String, pkg: String, fileName: String): Unit

    Permalink

    Writes given content to a file.

    Writes given content to a file. Ensures the file ends with a newline character.

    Definition Classes
    OutputHelpers
  52. def writeToFile(profile: String, folder: String, pkg: String, container: String = "Tables", fileName: String = "Tables.scala"): Unit

    Permalink

    Generates code and writes it to a file.

    Generates code and writes it to a file. Creates a folder structure for the given package inside the given srcFolder and places the new file inside or overrides the existing one.

    profile

    Slick profile that is imported in the generated package (e.g. slick.jdbc.H2Profile)

    folder

    target folder, in which the package structure folders are placed

    pkg

    Scala package the generated code is placed in (a subfolder structure will be created within srcFolder)

    container

    The name of a trait and an object the generated code will be placed in within the specified package.

    fileName

    Name of the output file, to which the code will be written

    Definition Classes
    OutputHelpers
  53. def writeToMultipleFiles(profile: String, folder: String, pkg: String, container: String = "Tables"): Unit

    Permalink

    Generates code and writes it to multiple files.

    Generates code and writes it to multiple files. Creates a folder structure for the given package inside the given srcFolder and places the new files inside or overrides the existing one.

    profile

    Slick profile that is imported in the generated package (e.g. scala.slick.driver.H2Driver)

    folder

    target folder, in which the output files are placed

    pkg

    Scala package the generated code is placed in (a subfolder structure will be created within srcFolder)

    container

    The name of a trait and an object the generated code will be placed in within the specified package.

    Definition Classes
    OutputHelpers
  54. def [B](y: B): (SourceCodeGenerator, B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from SourceCodeGenerator to ArrowAssoc[SourceCodeGenerator] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from OutputHelpers

Inherited from StringGeneratorHelpers

Inherited from AbstractGenerator[String, String, String]

Inherited from GeneratorHelpers[String, String, String]

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from SourceCodeGenerator to any2stringadd[SourceCodeGenerator]

Inherited by implicit conversion StringFormat from SourceCodeGenerator to StringFormat[SourceCodeGenerator]

Inherited by implicit conversion Ensuring from SourceCodeGenerator to Ensuring[SourceCodeGenerator]

Inherited by implicit conversion ArrowAssoc from SourceCodeGenerator to ArrowAssoc[SourceCodeGenerator]

Basic customization overrides

Output

Ungrouped