Dzoukr / Dapper.FSharp

Lightweight F# extension for StackOverflow Dapper with support for MSSQL, MySQL, PostgreSQL, and SQLite
MIT License
365 stars 35 forks source link

Structures in columns #79

Closed Slesa closed 1 year ago

Slesa commented 1 year ago

I'm trying out some proof of concepts, using the example from another F# implementation. There is a user database, with name and passwort, where the pw is a discriminated union - either plain text or a hash with its salt.

As I am questioning the sense of storing plain text pws, I've removed the union, so I want to store the following in the db:

type Password = {
  Hash: string
  Salt: string
}
type User = {
  Id: int64 option
  Name: string
  Password: Password
}

Is there an example how to store this in a database-agnostic way?

JordanMarr commented 1 year ago

This library does not provide ORM style mappings, so if you want to insert a record, it needs to map one-to-one with the table. Your example shows a parent-child object graph (User-Password). If you want to insert this with D.FS, you would need to flatten it by moving the Password fields into the User record (depending on your table schema).

Dzoukr commented 1 year ago

Yup, as @JordanMarr says - it needs to be flattened as it's written in the documentation 👉 https://github.com/Dzoukr/Dapper.FSharp#do-i-need-to-create-a-record-with-all-columns

Dzoukr commented 1 year ago

Closing as it's not an issue 😁