From 3e1615f0a27c38c002573a8fd3c9f4ba9ed97b0a Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Thu, 2 Jan 2020 13:48:35 +0200 Subject: [PATCH] fsharp(todolist-api): feat: query for getting todos by id Signed-off-by: prescientmoon --- fsharp/todolist-api/src/Db.fs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) 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