1
Fork 0

fsharp(todolist-api): feat: query for getting todos by id

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2020-01-02 13:48:35 +02:00 committed by prescientmoon
parent 973fb2c537
commit 3e1615f0a2
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4

View file

@ -7,6 +7,26 @@ let ConnectionString = "Server=127.0.0.1; Database=todo_api_db; User Id=suave; P
type Sql = SqlDataProvider<ConnectionString=ConnectionString, DatabaseVendor=Common.DatabaseProviderTypes.POSTGRESQL, CaseSensitivityChange=Common.CaseSensitivityChange.ORIGINAL>
module Context =
type DbContext = Sql.dataContext
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