Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
Add query/module productions (#12)
Browse files Browse the repository at this point in the history
* Add query/module productions

* Split query/module. Fix decl parser

* Modules can't end in ;
  • Loading branch information
natefaubion authored May 25, 2017
1 parent 21b779b commit 81d2ef1
Show file tree
Hide file tree
Showing 6 changed files with 419 additions and 81 deletions.
39 changes: 39 additions & 0 deletions src/SqlSquare.purs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
module SqlSquared
( Sql
, SqlQuery
, SqlModule
, print
, printQuery
, printModule
, encodeJson
, encodeJsonQuery
, encodeJsonModule
, decodeJson
, decodeJsonQuery
, decodeJsonModule
, arbitrarySqlOfSize
, arbitrarySqlQueryOfSize
, arbitrarySqlModuleOfSize
, module Sig
, module Lenses
, module Constructors
Expand All @@ -16,6 +26,7 @@ import Data.Argonaut as J
import Data.Either (Either)
import Data.Functor.Mu (Mu)
import Data.Json.Extended as EJ
import Data.Traversable (traverse)

import Matryoshka (cata, anaM)

Expand All @@ -28,14 +39,42 @@ import Test.StrongCheck.Gen as Gen

type Sql = Mu (Sig.SqlF EJ.EJsonF)

type SqlQuery = Sig.SqlQueryF Sql

type SqlModule = Sig.SqlModuleF Sql

print Sql String
print = cata $ Sig.printSqlF EJ.renderEJsonF

printQuery SqlQuery String
printQuery = Sig.printSqlQueryF <<< map print

printModule SqlModule String
printModule = Sig.printSqlModuleF <<< map print

encodeJson Sql J.Json
encodeJson = cata $ Sig.encodeJsonSqlF EJ.encodeJsonEJsonF

encodeJsonQuery SqlQuery J.Json
encodeJsonQuery = Sig.encodeJsonSqlQueryF <<< map encodeJson

encodeJsonModule SqlModule J.Json
encodeJsonModule = Sig.encodeJsonSqlModuleF <<< map encodeJson

decodeJson J.Json Either String Sql
decodeJson = anaM $ Sig.decodeJsonSqlF EJ.decodeJsonEJsonF

decodeJsonQuery J.Json Either String SqlQuery
decodeJsonQuery = traverse decodeJson <=< Sig.decodeJsonSqlQueryF

decodeJsonModule J.Json Either String SqlModule
decodeJsonModule = traverse decodeJson <=< Sig.decodeJsonSqlModuleF

arbitrarySqlOfSize Int Gen.Gen Sql
arbitrarySqlOfSize = anaM $ Sig.arbitrarySqlF EJ.arbitraryEJsonF

arbitrarySqlQueryOfSize Int Gen.Gen SqlQuery
arbitrarySqlQueryOfSize = traverse arbitrarySqlOfSize <=< Sig.arbitrarySqlQueryF

arbitrarySqlModuleOfSize Int Gen.Gen SqlModule
arbitrarySqlModuleOfSize = traverse arbitrarySqlOfSize <=< Sig.arbitrarySqlModuleF
Loading

0 comments on commit 81d2ef1

Please sign in to comment.