All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scalikejdbc.orm.timstamps.TimestampsFeatureBase.scala Maven / Gradle / Ivy

The newest version!
package scalikejdbc.orm.timstamps

import org.joda.time.DateTime
import scalikejdbc.SQLSyntax
import scalikejdbc.orm.basic.SQLSyntaxSupportBase

trait TimestampsFeatureBase[Entity] {
  self: SQLSyntaxSupportBase[Entity] =>

  /**
   * createdAt field name.
   */
  def createdAtFieldName = "createdAt"

  /**
   * updatedAt field name.
   */
  def updatedAtFieldName = "updatedAt"

  protected def timestampValues(
    exists: String => Boolean
  ): Seq[(SQLSyntax, Any)] = {
    val (column, now) = (defaultAlias.support.column, DateTime.now)
    val builder = List.newBuilder[(SQLSyntax, Any)]
    if (!exists(createdAtFieldName))
      builder += column.field(createdAtFieldName) -> now
    if (!exists(updatedAtFieldName))
      builder += column.field(updatedAtFieldName) -> now
    builder.result()
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy