module Db open FSharp.Data.Sql [] let ConnectionString = "Server=127.0.0.1; Database=todo_api_db; User Id=suave; Password=1234;" type Sql = SqlDataProvider module Context = type DbContext = Sql.dataContext let getContext() = Sql.GetDataContext() module Types = open Context open System.Runtime.Serialization type DbTodo = DbContext.``public.todosEntity`` [] type Todo = { [] id: int [] description: string [] name: string } [] type TodoDetails = { [] description: string [] name: string } module Queries = open Context open Types let getTodosById id (ctx: DbContext): DbTodo option = query { for todo in ctx.Public.Todos do where (todo.Id = id) select todo } |> Seq.tryHead let updateTodosById (todo: DbTodo) (details: TodoDetails) (ctx: DbContext) = todo.Name <- details.name todo.Description <- details.description ctx.SubmitUpdatesAsync()