如果Option[String]为None,正确的插入方法是什么?下面的代码插入了一个空字符串,但这与mysql中的NULL不同。
根据partnerCode的内容事先构建SQL字符串是唯一的方法吗?哎呀...Anorm...
DB.withConnection { implicit connection =>
val id: Option[Long] = SQL(
"""
INSERT INTO users (email, partner_code, is_active, created, pass) VALUES ({email}, {partnerCode}, 0, NOW(), {pass})
"""
).on(
'email -> user.email,
'partnerCode -> user.partnerCode.getOrElse(""), // FIXME: how to use NULL keyword instead of empty string? Is Anorm just this dumb?
'pass -> hashPassword(user.password.get)
).executeInsert()
id.get
}