From: Kei H. <ex8...@gm...> - 2012-12-12 02:52:17
|
Hi, I have an idea to extend Relation types and Record types into tuple-ed ones. I wrote experimentally implementation to achieve this. https://github.com/khibino/haskelldb/tree/tuple_join Query of single table case is like below. type RelX = RecCons X0 (Expr p0) (RecCons X1 ... ) tableX :: Table RelX ... type RecordX = RecCons X0 p0 (RecCons X1 ... ) single :: Query (Rel RelX) single = do tx <- table tableX ... project $ copyAll tx querySingle :: Database -> IO [Record RecordX] querySingle = (`query` single) As usual, joined query case, we have been required to re-compose joined type other than defined Relation and Record types. type RelY = RecCons Y0 (Expr q0) (RecCons Y1 ... ) tableY :: Table RelY ... type RelJoined = RecCons X0 (Expr p0) ( ... (RecCons Y0 (Expr q0) ... ) ... ) type RecordJoined = RecCons X0 p0 ( ... (RecCons Y0 q0 ... ) ... ) joined' :: Query (Rel Joined) joined' = do tx <- table tableX ty <- table tableY ... project $ copy x0 tx # copy x1 tx ... # copy y0 ty # copy y0 ty ... queryJoined' :: Database -> IO [Record RecordJoined] queryJoined' = (`query` joined') On my implementation, we can simply use tuple type in joined query case. Not required to re-compose joined Reltion and Record types. type RecordY = RecCons Y0 q0 (RecCons Y1 ... ) joined :: Query (Rel (RelX, RelY)) joined = do tx <- table tableX ty <- table tableY ... project $ (,) <$> copyAll tx <*> copyAll ty queryJoined :: Database -> IO [Record (RecordX, RecordY)] queryJoined = (`query` joined) -- -- Kei Hibino -- ex8...@gm... -- |