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.
- Grouped
- Alphabetic
- By Inheritance
- SourceCodeGenerator
- OutputHelpers
- AbstractSourceCodeGenerator
- StringGeneratorHelpers
- AbstractGenerator
- GeneratorHelpers
- AnyRef
- Any
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new SourceCodeGenerator(model: Model)
- model
Slick data model for which code should be generated.
Type Members
- abstract case class AbstractTableDef(model: model.Table) extends Product with Serializable
Code generator for table related code
Code generator for table related code
- model
corresponding Slick meta model component
- Definition Classes
- AbstractGenerator
- abstract class AbstractSourceCodeTableDef extends AbstractTableDef
- Definition Classes
- AbstractSourceCodeGenerator
- implicit class StringExtensions extends AnyRef
Slick code generator string extension methods.
Slick code generator string extension methods. (Warning: Not unicode-safe, uses String#apply)
- Definition Classes
- GeneratorHelpers
- class SourceCodeTableDef extends AbstractSourceCodeTableDef
- type Table = SourceCodeTableDef
Table generator virtual class
Table generator virtual class
- Definition Classes
- SourceCodeGenerator → AbstractGenerator
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- def ->[B](y: B): (SourceCodeGenerator, B)
- Implicit
- This member is added by an implicit conversion from SourceCodeGenerator toArrowAssoc[SourceCodeGenerator] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
- Annotations
- @inline()
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def Table: (model.Table) => Table
Table generator factory.
Table generator factory. Override for customization.
- Definition Classes
- SourceCodeGenerator → AbstractGenerator
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @HotSpotIntrinsicCandidate() @native()
- def code: String
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
- def codeForContainer: String
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
- def codeForDDL: String
Generates code for the DDL statement.
Generates code for the DDL statement.
- Definition Classes
- AbstractSourceCodeGenerator
- def codePerTable: Map[String, String]
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
- val ddlEnabled: Boolean
Enables DDL Generation.
Enables DDL Generation.
- Definition Classes
- AbstractGenerator
- def docWithCode(doc: String, code: String): String
Assemble doc comment with scala code
Assemble doc comment with scala code
- Definition Classes
- StringGeneratorHelpers → GeneratorHelpers
- def ensuring(cond: (SourceCodeGenerator) => Boolean, msg: => Any): SourceCodeGenerator
- Implicit
- This member is added by an implicit conversion from SourceCodeGenerator toEnsuring[SourceCodeGenerator] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- def ensuring(cond: (SourceCodeGenerator) => Boolean): SourceCodeGenerator
- Implicit
- This member is added by an implicit conversion from SourceCodeGenerator toEnsuring[SourceCodeGenerator] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- def ensuring(cond: Boolean, msg: => Any): SourceCodeGenerator
- Implicit
- This member is added by an implicit conversion from SourceCodeGenerator toEnsuring[SourceCodeGenerator] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- def ensuring(cond: Boolean): SourceCodeGenerator
- Implicit
- This member is added by an implicit conversion from SourceCodeGenerator toEnsuring[SourceCodeGenerator] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- def entityName: (String) => String
Maps database table name to entity case class name
Maps database table name to entity case class name
- Definition Classes
- AbstractGenerator
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def foreignKeysPerTable: Map[String, List[String]]
- Definition Classes
- AbstractSourceCodeGenerator
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- def indent(code: String): String
- Definition Classes
- GeneratorHelpers
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- final def optionType(t: String): String
Wrap the given type into an Option type
Wrap the given type into an Option type
- Definition Classes
- StringGeneratorHelpers → GeneratorHelpers
- def packageCode(profile: String, pkg: String, container: String, parentType: Option[String]): String
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
- def packageContainerCode(profile: String, pkg: String, container: String = "Tables"): String
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
- def packageTableCode(tableName: String, tableCode: String, pkg: String, container: String): String
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
- def parentType: Option[String]
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
- def parseType(tpe: String): String
Generates code for a qualified Scala type
Generates code for a qualified Scala type
- Definition Classes
- StringGeneratorHelpers → GeneratorHelpers
- def rootTraitCode(profile: String, pkg: String, container: String = "Tables"): String
- Definition Classes
- OutputHelpers
- val scalaKeywords: Seq[String]
Words that are reserved keywords in Scala
Words that are reserved keywords in Scala
- Definition Classes
- GeneratorHelpers
- def shouldQuoteIdentifier(s: String): Boolean
- Definition Classes
- StringGeneratorHelpers
- val slickTableTermMembersNoArgs: Seq[String]
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
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def tableName: (String) => String
Maps database table name to Table class and value name
Maps database table name to Table class and value name
- Definition Classes
- AbstractGenerator
- final lazy val tables: Seq[Table]
Table code generators.
Table code generators.
- Definition Classes
- AbstractGenerator
- final lazy val tablesByName: Map[QualifiedName, Table]
Table code generators indexed by db table name.
Table code generators indexed by db table name.
- Definition Classes
- AbstractGenerator
- def termName(name: String): String
Marks a String as a TermName (e.g.
Marks a String as a TermName (e.g. for escaping scala keywords)
- Definition Classes
- StringGeneratorHelpers → GeneratorHelpers
- def toString(): String
- Definition Classes
- AnyRef → Any
- def tuple(i: Int): String
- Attributes
- protected
- Definition Classes
- AbstractSourceCodeGenerator
- def typeName(name: String): String
Marks a String as a TypeName (e.g.
Marks a String as a TypeName (e.g. for escaping scala keywords)
- Definition Classes
- StringGeneratorHelpers → GeneratorHelpers
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- def writeStringToFile(content: String, folder: String, pkg: String, fileName: String): Unit
Writes given content to a file.
Writes given content to a file. Ensures the file ends with a newline character.
- Definition Classes
- OutputHelpers
- def writeToFile(profile: String, folder: String, pkg: String, container: String = "Tables", fileName: String = "Tables.scala"): Unit
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
- def writeToMultipleFiles(profile: String, folder: String, pkg: String, container: String = "Tables"): Unit
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
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
(Since version 9)
- def formatted(fmtstr: String): String
- Implicit
- This member is added by an implicit conversion from SourceCodeGenerator toStringFormat[SourceCodeGenerator] performed by method StringFormat in scala.Predef.
- Definition Classes
- StringFormat
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 2.12.16) Use
formatString.format(value)
instead ofvalue.formatted(formatString)
, or use thef""
string interpolator. In Java 15 and later,formatted
resolves to the new method in String which has reversed parameters.
- def →[B](y: B): (SourceCodeGenerator, B)
- Implicit
- This member is added by an implicit conversion from SourceCodeGenerator toArrowAssoc[SourceCodeGenerator] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
- Annotations
- @deprecated
- Deprecated
(Since version 2.13.0) Use
->
instead. If you still wish to display it as one character, consider using a font with programming ligatures such as Fira Code.