Package

io.getquill.codegen

jdbc

Permalink

package jdbc

Visibility
  1. Public
  2. All

Type Members

  1. class ComposeableTraitsJdbcCodegen extends JdbcGeneratorBase

    Permalink

    This generator generates a query schema trait which can be composed with a custom context that you create in your client code (called MySchemaExtensions below because it extends and existing quill context with your query schemas).

    This generator generates a query schema trait which can be composed with a custom context that you create in your client code (called MySchemaExtensions below because it extends and existing quill context with your query schemas). Here is what that looks like:

    
    case class Person(firstName:String, lastName:String, age:Int)
    case class Address(...)
    
    trait PublicExtensions[+Idiom <: io.getquill.idiom.Idiom, Naming <: io.getquill.NamingStrategy] {
      this:io.getquill.context.Context[Idiom, Naming] =>
    
      object PersonDao { def query = querySchema[Person](...) 
      object AddressDao { def query = querySchema[Address](...) }
    }
    
    // Then when declaring your context:
    import io.getquill._
    object MyCustomContext extends SqlMirrorContext[H2Dialect, Literal](H2Dialect, Literal)
      with PublicExtensions[H2Dialect, Literal]
    
    }
    

    A Note on Stereotyping

    Stereotyping using the ComposeableTraitsGen is done in the following manner. Firstly, extend a ComposeableTraitsGen and add the Namespacer of your choice. Let's take the alpha and bravo namespaces and combine them into a common namespace. Also be sure to set the memberNamer correctly so that the different querySchemas generated won't all be called '.query' in the Common object.

      class MyStereotypingGen(...) extends ComposeableTraitsGen(...) {
        override def namespacer: Namespacer =
           ts=> if(ts.tableSchem == "alpha" || ts.tableSchem == "bravo") "common" else ts.tableSchem
    
        override def memberNamer: MemberNamer =
           ts => ts.tableName.snakeToLowerCamel
      }
    

    The following schema should result:

    trait CommonExtensions[+Idiom <: io.getquill.idiom.Idiom, Naming <: io.getquill.NamingStrategy] {
      this:io.getquill.context.Context[Idiom, Naming] =>
    
      object PersonDao {
        // you don't want each of these to be called 'query' so choose an appropriate memberNamer
        def alphaPerson = querySchema[Person](...)
        def bravoPerson = querySchema[Person](...)
      }
    }
    
    trait PublicExtensions[+Idiom <: io.getquill.idiom.Idiom, Naming <: io.getquill.NamingStrategy] {
      this:io.getquill.context.Context[Idiom, Naming] =>
    
      object AddressDao {
        def publicAddress = querySchema[Address](...)
      }
    }
    

    When DAO Objects Collide

    Now when you are trying to generate schemas which are not being stereotyped but have equivalent table names for example:

    trait AlphaExtensions[+Idiom <: io.getquill.idiom.Idiom, Naming <: io.getquill.NamingStrategy] {
      this:io.getquill.context.Context[Idiom, Naming] =>
    
      object PersonDao { def query = querySchema[Person](...) }
    }
    
    trait BravoExtensions[+Idiom <: io.getquill.idiom.Idiom, Naming <: io.getquill.NamingStrategy] {
      this:io.getquill.context.Context[Idiom, Naming] =>
    
      object PersonDao { def query = querySchema[Person](...) }
    }
    
    // Invalid because MyCustomContext has a PersonDao from AlphaExtensions and and a PersonDao from BravoExtensions which collide.
    object MyCustomContext extends SqlMirrorContext[H2Dialect, Literal](H2Dialect, Literal)
      with AlphaExtensions[H2Dialect, Literal] with BravoExtensions[H2Dialect, Literal]
    

    You will not be able to append these two traits to the same quill context because the PersonDao inside alpha and bravo will collide inside of MyCustomContext. Use the parameter nestedTrait=true in order to get around this.

    trait AlphaExtensions[+Idiom <: io.getquill.idiom.Idiom, Naming <: io.getquill.NamingStrategy] {
      this:io.getquill.context.Context[Idiom, Naming] =>
    
      trait AlphaSchema {
        object PersonDao { def query = querySchema[Person](...) }
      }
    }
    
    trait BravoExtensions[+Idiom <: io.getquill.idiom.Idiom, Naming <: io.getquill.NamingStrategy] {
      this:io.getquill.context.Context[Idiom, Naming] =>
    
      trait BravoSchema {
        object PersonDao { def query = querySchema[Person](...) }
      }
    }
    
    // Since PersonDao is inside MyCustomContext.alpha and MyCustomContext.bravo as opposed to MyCustomContext
    // there will be no collision.
    object MyCustomContext extends SqlMirrorContext[H2Dialect, Literal](H2Dialect, Literal)
      with AlphaExtnsions[H2Dialect, Literal] with BravoExtensions[H2Dialect, Literal]
    

  2. class SimpleJdbcCodegen extends JdbcGeneratorBase

    Permalink

    The purpose of the simple code generator is to generate simple case classes representing tables in a database.

    The purpose of the simple code generator is to generate simple case classes representing tables in a database. Create one or multiple CodeGeneratorConfig objects and call the .writeFiles or .writeStrings methods on the code generator and the reset happens automatically.

Value Members

  1. object DatabaseTypes

    Permalink
  2. package gen

    Permalink
  3. package model

    Permalink
  4. package util

    Permalink

Ungrouped