-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reusable types #10
Comments
Unfortunately there's no way to have them share the same generated type. What I'd like to do to support this in the future is let you specify paths to assemblies in rzsql.json. So in this case you might have something like this in MyRowInterfaceAssembly.dll, which should be built before MyAssemblyWithRezoomSQLQueries.dll: type IItem =
abstract ItemId : int
abstract DataField : string Then both I've held off on doing this because ultimately, I want it to be smart enough to do stuff like automatically map Current workaroundsRight now there are a couple things you can do to make this less painful. Inline functionsWrite a helper to convert to your domain type with F# inline functions. This is especially useful if you have some wrapper types in your domain model that RZSQL doesn't know about anyway, like type ItemId = ItemId of int
type Item =
{ Id : ItemId
Name : string
}
let inline itemFromRow x =
{ Id = ItemId (^a : (member get_Id : unit -> int)(x))
Name = (^a : (member get_Name : unit -> string)(x))
} Then you can use Configurable queriesWhere possible, use fewer queries but make them configurable with parameters. E.g. for the minimal example, you could use: select *
from Item i
where @activeFilter is null or i.IsActive = @activeFilter And pass |
Making identifiers to it's own types is quite clearly "the right way" and it's great that it's on your concern list. Auto generated interface implementations sounds good way to work with this. Although this makes me hope that F# should have better support for general purpose compile time programming. I think it should be also considered that should interfaces must be explicitly expressed like: |
Is there way / plans to create types reusable?
If types have somewhat big complexity and there is lot of queries which have different filter / order logic but result data is identical you still have to duplicate mapping.
Minimal example:
The text was updated successfully, but these errors were encountered: