-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Description
Hi there,
Wondering if Enumerated Types would ever be supported at a library level? Would you be open to that type of feature as a contribution?
Example: let's say I have a union type
type User = Developer | API | Personand in my Postgres database i have
CREATE TYPE user AS ENUM ('Developer', 'API', 'Person');Would this make sense as an API?
open Npgsql.FSharp
open System
type UserData = {
id: Guid
kind: User
}
let getUser (uuid:Guid) : UserData =
Sql.connect Storage.connectionString
|> Sql.query $"SELECT * FROM {Storage.Users.table} WHERE id={uuid}"
|> Sql.execute (fun read ->
{
id = read.uuid "id"
kind = read.enum<User> "kind"
}
)Or perhaps something even simpler, like:
open Npgsql.FSharp
open System
let toUser =
function
| "Developer" -> User.Developer
| "API" -> User.API
| "Person" -> User.Person
| _ -> failwith "FATAL: Unrecognized User Type"
type UserData = {
id: Guid
kind: User
}
let getUser (uuid:Guid) : UserData =
Sql.connect Storage.connectionString
|> Sql.query $"SELECT * FROM {Storage.Users.table} WHERE id={uuid}"
|> Sql.execute (fun read ->
{
id = read.uuid "id"
kind = (read.enum "kind" |> toUser)
}
)Or is this a solved problem that I'm just not finding anywhere?
Thank you for your great library.
Best,
Gina
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels