diff --git a/fsharp/todolist-api/src/Db.fs b/fsharp/todolist-api/src/Db.fs index e3a7799..a8615e3 100644 --- a/fsharp/todolist-api/src/Db.fs +++ b/fsharp/todolist-api/src/Db.fs @@ -7,6 +7,26 @@ let ConnectionString = "Server=127.0.0.1; Database=todo_api_db; User Id=suave; P type Sql = SqlDataProvider -type DbContext = Sql.dataContext +module Context = + type DbContext = Sql.dataContext -type Todo = DbContext.``public.todosEntity`` + let getContext() = Sql.GetDataContext() + + +module Types = + open Context + + type Todo = DbContext.``public.todosEntity`` + +module Queries = + open Context + open Types + + let getTodosById id (ctx: DbContext): Todo option = + query { + for todo in ctx.Public.Todos do + where (todo.Id = id) + select todo + } + |> Seq.tryHead + \ No newline at end of file