Skip to content

Commit

Permalink
Add a test case for SELECT_DISTINCT
Browse files Browse the repository at this point in the history
  • Loading branch information
emdash committed Dec 5, 2023
1 parent b5e3240 commit 0aed00d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/src/Main.idr
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ app = withDB ":memory:" $ do
, IF_NOT_EXISTS createFiles
, IF_NOT_EXISTS createUnits
, IF_NOT_EXISTS createEmployees
, IF_NOT_EXISTS createEdges
, insertMol $ M "Ethanol" (Just "64-17-5") (Just 46.069) Compound
, insertMol $ M "Strychnine" (Just "57-24-9") (Just 334.419) Compound
, insertMol $ M "Atropine" (Just "51-55-8") (Just 289.375) Compound
Expand All @@ -55,6 +56,14 @@ app = withDB ":memory:" $ do
, insertEmployee $ E "Gundi" 2050.0 1
, insertEmployee $ E "Valeri" 5010.0 1
, insertEmployee $ E "Ronja" 4010.0 1
, insertEdge "A" "B"
, insertEdge "B" "C"
, insertEdge "B" "D"
, insertEdge "C" "E"
, insertEdge "C" "F"
, insertEdge "D" "F"
, insertEdge "F" "G"
, insertEdge "B" "F"
] ++ fromList (insertFile . file <$> [0..255])

queryTable (mol TRUE) 1000 >>= printTable
Expand All @@ -78,5 +87,7 @@ app = withDB ":memory:" $ do
queryTable unitStats 1000 >>= printTable
putStrLn ""

queryTable parents 1000 >>= printTable

main : IO ()
main = runApp handlers app
28 changes: 28 additions & 0 deletions test/src/Schema.idr
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ Files =
, C "content" BLOB
]

public export
Edges : SQLTable
Edges =
table "edges"
[ C "u" TEXT
, C "v" TEXT
]

export
createMolecules : Cmd TCreate
createMolecules =
Expand Down Expand Up @@ -92,6 +100,15 @@ createEmployees =
, UNIQUE ["name"]
]

export
createEdges : Cmd TCreate
createEdges =
CREATE_TABLE Edges
[ PRIMARY_KEY ["u", "v"]
, NOT_NULL "u"
, NOT_NULL "v"
]

--------------------------------------------------------------------------------
-- Idris Types
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -157,6 +174,10 @@ export
insertFile : File -> Cmd TInsert
insertFile = insert Files ["content"]

export
insertEdge : String -> String -> Cmd TInsert
insertEdge u v = INSERT Edges ["u", "v"] [val u, val v]

--------------------------------------------------------------------------------
-- Query
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -232,3 +253,10 @@ tuples =
]
`WHERE` ("m1.molweight" < "m2.molweight")
`OFFSET` 2

public export
parents : LQuery [String]
parents =
SELECT_DISTINCT
["u"]
[< FROM $ Edges `AS` "e"]

0 comments on commit 0aed00d

Please sign in to comment.