Last active
August 29, 2015 14:00
-
-
Save liammclennan/11100906 to your computer and use it in GitHub Desktop.
F# postgresql document database WIP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Person = | |
{ _id: System.Guid; age: int; name: string } | |
interface IDocument with | |
member x.tableName() = "People" | |
member x.id() = x._id | |
[<Fact>] | |
let ``insert, read, update, delete a document`` () = | |
// insert | |
let id = System.Guid.NewGuid() | |
let o = { _id = id; age = 45; name = "Cecile" } | |
insert o | |
// read | |
let read = | |
[ "id", box (id.ToString()) ] | |
|> Map.ofList | |
|> query<Person> "select data from people where data->>'_id' = :id" | |
o |> should equal read.[0] | |
Array.length read |> should equal 1 | |
// update | |
let updated = {o with age = 46 } | |
update updated | |
// read again :{P | |
let readUpdated = | |
["id", box (id.ToString())] | |
|> Map.ofList | |
|> query<Person> "select data from people where data->>'_id' = :id" | |
updated |> should equal readUpdated.[0] | |
Array.length readUpdated |> should equal 1 | |
// delete | |
delete o | |
let readDeleted = | |
["id", box (id.ToString())] | |
|> Map.ofList | |
|> query<Person> "select data from people where data->>'_id' = :id" | |
Array.length readDeleted |> should equal 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment