There are not much embedded databases on .net, especially with F# data structures support. So it would be nice to have such option in LiteDB.
The main problem is storing F# specific types, such as DU, records, collections, options.
I created simple POC for (de)serialization DU types, it works, but extending BsonMapper is not very convenient.
First of all I'd like to ask: "Are you interested in it?" . And if the answer is yes, what is the best way to add F#-specific stuff for LiteDB?
I can add new project in main repo but ship nuget package separately. Or maintain f# project in separate repo. Anyway we should think about how it would be integrated, I mean how to extend BsonMapper. In my POC I inherited BsonMapper and override Serialize and Deserialize methods, but I'm not sure that it's the best way. Maybe it would be better to create custom EntityMapper.
Hi @p69, to be honest, I don't know how F# works and why current version is not enough (I don't know what is DU, records, ...) 馃槃
If you have some code so I can take a look will be nice.
Override BsonMapper is not that simple, could be much more easy only work with EntityMapper, but again, I need more information about F# to understand what is this.
If it's possible just create an external project (that uses LiteDB as dependency) is the best option. So, only who uses F# can download from nuget.
Hi @mbdavid and thanks for reply!
Yeah, I see that override BsonMapper is not that simple. Ok, I'll try to use EntityMapper.
Basically there are few problems:
null or some specific value.Hi @p69,
Keep F# version in same solution/repository its complicated to maintain just because I have no idea how F# works. I think could be an "extension" library, that implements a specific version (and can evolve independently).
If main difference in use of LiteDB in F# is how map this custom types, this could be using BsonMapper.GetTypeMembers and BuildEntityMapper.
If you have some F# example (about this types) that can help me with this will be nice.
HI @mbdavid
I've tried using EntityMapper for this, but no success. That's because of the flow for custom type deserialization. Mapper creates object first, and then set fields using Setter in MemberMapper. But DU types in f# couldn't be created this way.
Let me show you some example of DU and how it can be created using reflection.
type Shape =
| Circle of r:float
| Rectangle of w:float*h:float
| Point
It's simple example discremated union type. Type Shape it's sum of three types Circle, Rectangle, Point. Usually it calls cases. Each case can have fields, for example field r for Circle, and fields w and h for Rectangle (Point doesn't have any fields).
Here is how Circle case can be created using reflection.
let circle = FSharpValue.MakeUnion("Circle", [| 2.0 |] )
MakeUnion function takes case name as string and array of objects (fields). So to create DU object we need to have this information (case name and fields array).
And here is some example of overriding Serialize and Desrialize methods, but I made them public and virtual.
So what do you think?
Hello @p69, I saw this thread a couple of days ago and thought it would be nice to have an F# version of LiteDB. So I started working on the library LiteDB.FSharp. It already supports a lot of kinds of conversions (records, maps, generic discriminated unions) and all of the special bson properties ($date, $binary, $oid, $longNumber, $decimalNumber)
Take a look and contribute (tests, samples) if you are interested :smile:
@Zaid-Ajaj Ha, cool 馃憤 Thank you very much!
I've already taken a quick a look at it today in the morning. Looks good 馃憤
So this thread can be closed. F# community strong!
Most helpful comment
Hello @p69, I saw this thread a couple of days ago and thought it would be nice to have an F# version of LiteDB. So I started working on the library LiteDB.FSharp. It already supports a lot of kinds of conversions (records, maps, generic discriminated unions) and all of the special bson properties ($date, $binary, $oid, $longNumber, $decimalNumber)
Take a look and contribute (tests, samples) if you are interested :smile: