-
Notifications
You must be signed in to change notification settings - Fork 5
Type safety
SqlFun relies on hand-written SQL and runtime code generation. It's not type-safe in a usual meaning. But there is quite nice equivalent. Since all query functions are generated during their module initialization, we need only one test for each data access module. E.g. to type-check the module:
module Blogging =
let getBlog: int -> DataContext -> Blog = ...
let getNumberOfPosts: int -> DataContext -> int = ...
let getPostAndItsComments: int -> DataContext -> (Post * Comment list) = ...
the followin test is enough:
[<Test>]
member this.``Blogging module passes type checks``() =
let x = Blogging.getBlog
Accessing one module member triggers initialization of remaining members. During code generation SqlFun executes query in SchemaOnly
mode and tries to generate all needed type conversions. Typos in SQL and incorrect parameter or return types results in exceptions.
The downside is, that NULL checks can not be performed this way.
Unfortunately, composite queries are not checked during module initialization, since they must be defined as functions, not variables. Each of them should have its own test, sometimes even more, than one.