Raw Queries
For situations where the high-level ORM API is not enough — reporting queries, dynamic
SQL, stored procedures — Stormify exposes a low-level SQL API that works on any platform
with no entity registration required. This page covers the patterns you use alongside the
plain read / executeUpdate methods.
Reading and Executing SQL
The direct methods take a query string and bind parameters positionally:
List<User> users = stormify.read(User.class, "SELECT * FROM users WHERE age > ?", 25);
User one = stormify.readOne(User.class, "SELECT * FROM users WHERE id = ?", 1);
stormify.readCursor(User.class, "SELECT * FROM users", user -> processUser(user));
stormify.executeUpdate("DELETE FROM users WHERE age < ?", 18);
// Requires a default instance via stormify.asDefault().
// SQL strings gain read / readOne / readCursor / executeUpdate extensions.
val users = "SELECT * FROM users WHERE age > ?".read<User>(25)
val one = "SELECT * FROM users WHERE id = ?".readOne<User>(1)
"SELECT * FROM users".readCursor<User> { user -> processUser(user) }
"DELETE FROM users WHERE age < ?".executeUpdate(18)
Collection Parameter Expansion
When a ? placeholder receives a Collection or array, Stormify automatically expands
it into multiple placeholders:
This also works with entity collections — Stormify extracts each entity's primary key automatically:
This works with any Iterable or array type.
Stored Procedures
Stormify supports calling stored procedures with IN, OUT, and INOUT parameters:
Parameter types:
| Type | Kotlin | Java |
|---|---|---|
| Input | spIn(value) or raw value |
Sp.In(value) or raw value |
| Output | spOut<T>() |
Sp.outParam(Type.class) |
| Bidirectional | spInOut(value) |
Sp.inOutParam(Type.class, value) |
Microsoft SQL Server NULL into VARBINARY
The Microsoft JDBC driver maps an untyped null bind to NVARCHAR, which
Microsoft SQL Server refuses to coerce into a VARBINARY column. The same
limitation applies to entity inserts/updates — a ByteArray? property
holding null reaches the driver as a null bind. To write NULL into a
binary column on Microsoft SQL Server, use one of:
- Set the property (or the bound argument) to
ByteArray(0)— an empty blob instead ofnull. - Write a literal NULL in the SQL when issuing a raw statement:
... VALUES (?, NULL). - Cast the placeholder explicitly:
... VALUES (?, CAST(? AS VARBINARY(MAX))).
Every other column type (numeric, date, string) accepts null binds without issue on Microsoft SQL Server, and every other supported database (PostgreSQL, MySQL, MariaDB, Oracle, SQLite) accepts null into binary columns natively.