Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing SQL schema in F#

Because of the presence of type providers for accessing SQL data in F#, there's not much focus on the use of ORMs, micro or otherwise. I can definitely see the logic behind this.

It also seems that many examples of using F# to play with relational data is to plug them into existing large databases, that would appear to be created elsewhere.

It feels like there's a bit of a gap here: is there a nice way to manage schema creation and migration directly from F#? The example linked to above suggests running your manual schema creation script as the first step. Is this the only option?

I've recently started a little project that is F# from the outset, and I'm looking at storing some data in a relational database (sqlite for now). I don't have an existing schema to explore, I'm designing from scratch. Is there a friendlier or more idiomatic way to manage my schema (creation and then migration) in F#?

like image 533
eddie.sholl Avatar asked Apr 26 '15 23:04

eddie.sholl


1 Answers

You /can/ use Entity Framework with F#, and therefore get the Migrations API that it comes with, but I've found it very painful in practice - all your entity classes will require member val get set style properties (I believe) and various other bits and pieces. Jamie Dixon did a blog post on this some months ago around the same time I was experimenting with it - I did not enjoy it!

To be honest, although this isn't a great answer for you given what you're asking for i.e. DB schema management in F# - I would recommend that you use something like VS Database Projects to manage your schema outside of your code, and use (yes) either one of the SQL Type Providers to manage data within your application.

If you're dead set on using a "schema migration in code" system, EF plays much better with C# in my experience, so you could experiment theoretically with e.g. a C# / EF data access project referenced by your F# application code.

Sorry.

like image 85
Isaac Abraham Avatar answered Oct 22 '22 18:10

Isaac Abraham