Skip to content

Instantly share code, notes, and snippets.

@MMcM
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MMcM/e04bd2b329b4b374a4fb to your computer and use it in GitHub Desktop.
Save MMcM/e04bd2b329b4b374a4fb to your computer and use it in GitHub Desktop.
Slick driver for FDB SQL Layer.
package com.foundationdb.slick.driver
import java.sql.{PreparedStatement, ResultSet}
import java.util.UUID
import scala.slick.ast._
import scala.slick.lifted._
import scala.slick.driver.JdbcDriver
import scala.slick.jdbc.JdbcType
import scala.slick.jdbc.meta.MTable
import scala.slick.model.Model
import scala.slick.profile.{SqlProfile, RelationalProfile, Capability}
/** Slick driver for FDB SQL Layer.
*
* This driver implements [[scala.slick.driver.JdbcProfile]]
* ''without'' the following capabilities:
*
* <ul>
* <li>[[scala.slick.profile.RelationalProfile.capabilities.typeBlob]]:
* Blobs are not fully supported in release 2.0</li>
* </ul>
*/
trait FDBSQLDriver extends JdbcDriver { driver =>
override protected def computeCapabilities: Set[Capability] = (super.computeCapabilities
- RelationalProfile.capabilities.typeBlob
)
// The default has a type wildcard and so gets INDEX and so gets what it thinks are duplicates.
override def defaultTables(implicit session: Backend#Session) = MTable.getTables(None, None, None, Some(Seq("TABLE"))).list
override val columnTypes = new JdbcTypes
class JdbcTypes extends super.JdbcTypes {
override val uuidJdbcType = new UUIDJdbcType
// UUID is fully supported by the JDBC driver.
class UUIDJdbcType extends super.UUIDJdbcType {
override def sqlTypeName = "GUID"
override def setValue(v: UUID, p: PreparedStatement, idx: Int) = p.setObject(idx, v, sqlType)
override def getValue(r: ResultSet, idx: Int) = r.getObject(idx).asInstanceOf[UUID]
override def updateValue(v: UUID, r: ResultSet, idx: Int) = r.updateObject(idx, v)
override def valueToSQLLiteral(value: UUID) = "'" + value + "'"
override def hasLiteralForm = true
}
}
}
object FDBSQLDriver extends FDBSQLDriver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment