AugustNagro / magnum

A 'new look' for database access in Scala
Apache License 2.0
153 stars 10 forks source link

Usage of id type of Null #23

Closed cornerman closed 3 months ago

cornerman commented 3 months ago

Following the readme, I wanted to work with a table that has not id. Therefore, I tried to instantiate a Repo[MyTableCreator, MyTable, Null], but I got two compile errors:

First, missing an implicit ClassTag[Null]:

[error]    |    /* missing */summon[scala.reflect.ClassTag[Null]])
[error]    |
[error]    |But no implicit values were found that match type scala.reflect.ClassTag[Null]
[error]    |
[error]    |where:    derived$DbCodec  is a given instance in object Creator
[error]    |          derived$DbCodec² is a given instance in object Foo
[error]    |          magnum           is a package in package com.augustnagro
[error]    |          magnum²          is a package in package kicks.db

Then a missing DbCodec[Null] (we can maybe improve the error message in the future):

[error]    |java.util.NoSuchElementException: None.get
[error]    |    at scala.None$.get(Option.scala:627)
[error]    |    at scala.None$.get(Option.scala:626)
[error]    |    at com.augustnagro.magnum.RepoDefaults$.genImpl(RepoDefaults.scala:47)
[error]    |    at com.augustnagro.magnum.RepoDefaults$.inline$genImpl(RepoDefaults.scala:39)

My current workaround:

given scala.reflect.ClassTag[Null] = new scala.reflect.ClassTag[Null] { def runtimeClass = classOf[Null] }
given DbCodec[Null] with {
  val cols = IArray(java.sql.Types.NULL)
  def readSingle(rs: java.sql.ResultSet, pos: Int) = null
  def writeSingle(a: Null, ps: java.sql.PreparedStatement, pos: Int) = ()
  def queryRepr = "NULL"
}

Is this expected or am I missing something in the setup?

Using scala 3.4.1 and magnum 1.1.1.

AugustNagro commented 3 months ago

Thanks for the report; that's a bug. Please review the linked MR and I can cut a new release.

cornerman commented 3 months ago

Thank you this quick fix and for the great work! I really like the simplicity of magnum 👍