agentgt / jirm

A Java Immutable object Relational Mapper focused on simplicity, convenience, and thread safety.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type annotations in SQL template placeholders

agentgt opened this issue · comments

To keep accidentally data coercion with JDBC happening with SQL templates type annotations might be useful using the format -- {name:type} and --{:type}.

Example:

SELECT * FROM STUFF
WHERE ID = 1 -- {id:long}

Obviously this is not compile time type safety but run time type checking. That is for example if you bind a int, Integer, or String or anything else that is not a long or Long an error will happen when the place holders parameters are merged (.mergedParameters()). The type annotations will need to be consistent. That is you cannot later set -- {id:String} with in the same SQL template.