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

Commit f066823

Browse files
committed
Accept any path for table relations
1 parent 0e6fdf4 commit f066823

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

src/SqlSquared/Parser.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ parenRelation = do
570570
tableRelation m t. SqlParser m t (Sig.Relation t)
571571
tableRelation = do
572572
i ← ident
573-
path ← Pt.parseAnyFilePath P.fail i
573+
path ← Pt.parseAnyPath P.fail i
574574
a ← PC.optionMaybe do
575575
_ ← keyword "as"
576576
ident

src/SqlSquared/Path.purs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module SqlSquared.Path
33
, printAnyFilePath
44
, parseAnyDirPath
55
, printAnyDirPath
6+
, parseAnyPath
7+
, printAnyPath
68
, genAnyFilePath
79
, genAnyDirPath
810
, module PathyTypeReexprts
@@ -20,7 +22,6 @@ import Pathy (AnyDir, AnyFile)
2022
import Pathy.Gen as PtGen
2123
import SqlSquared.Utils ((∘))
2224

23-
2425
printAnyDirPath :: AnyDir -> String
2526
printAnyDirPath = E.either
2627
(Pt.sandboxAny >>> Pt.unsafePrintPath Pt.posixPrinter)
@@ -47,6 +48,17 @@ parseAnyFilePath fail = Pt.parsePath Pt.posixParser
4748
(pure ∘ E.Left)
4849
(fail "Expected valid path")
4950

51+
printAnyPath :: E.Either AnyDir AnyFile -> String
52+
printAnyPath = E.either printAnyDirPath printAnyFilePath
53+
54+
parseAnyPath :: forall m. Applicative m => (forall a. String -> m a) -> String -> m (E.Either AnyDir AnyFile)
55+
parseAnyPath fail = Pt.parsePath Pt.posixParser
56+
(pure ∘ E.LeftE.Right)
57+
(pure ∘ E.LeftE.Left)
58+
(pure ∘ E.RightE.Right)
59+
(pure ∘ E.RightE.Left)
60+
(fail "Expected valid path")
61+
5062
genAnyFilePath :: forall m. Gen.MonadGen m => MonadRec m => m AnyFile
5163
genAnyFilePath = Gen.oneOf
5264
$ (E.Left <$> PtGen.genAbsFilePath)

src/SqlSquared/Signature/Relation.purs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Prelude
55
import Control.Monad.Gen as Gen
66
import Control.Monad.Gen.Common as GenC
77
import Control.Monad.Rec.Class (class MonadRec)
8+
import Data.Either (Either(..), either)
89
import Data.Foldable as F
910
import Data.Maybe (Maybe)
1011
import Data.NonEmpty ((:|))
@@ -15,6 +16,7 @@ import SqlSquared.Path as Pt
1516
import SqlSquared.Signature.Ident as ID
1617
import SqlSquared.Signature.JoinType as JT
1718
import SqlSquared.Utils ((∘))
19+
1820
type JoinRelR a =
1921
{ left Relation a
2022
, right Relation a
@@ -33,7 +35,7 @@ type VariRelR =
3335
}
3436

3537
type TableRelR =
36-
{ path Pt.AnyFile
38+
{ path Either Pt.AnyDir Pt.AnyFile
3739
, alias Maybe String
3840
}
3941

@@ -86,7 +88,7 @@ printRelation = case _ of
8688
":" <> ID.printIdent vari <> F.foldMap (\a → " AS " <> ID.printIdent a) alias
8789
TableRelation { path, alias } →
8890
"`"
89-
<> Pt.printAnyFilePath path
91+
<> either Pt.printAnyDirPath Pt.printAnyFilePath path
9092
<> "`"
9193
<> F.foldMap (\x → " AS " <> ID.printIdent x) alias
9294
JoinRelation { left, right, joinType, clause } →
@@ -117,7 +119,7 @@ genRelation n =
117119
alias ← GenC.genMaybe GenS.genUnicodeString
118120
pure $ VariRelation { vari, alias }
119121
genTable = do
120-
path ← Pt.genAnyFilePath
122+
path ← Right <$> Pt.genAnyFilePath
121123
alias ← GenC.genMaybe GenS.genUnicodeString
122124
pure $ TableRelation { path, alias }
123125
genExpr = do

test/src/Constructors.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ selectQuery =
2323
]
2424
( Just $ S.TableRelation
2525
{ alias: Nothing
26-
, path: E.Left
26+
, path: E.Right $ E.Left
2727
$ Pt.rootDir
2828
Pt.</> Pt.dir (SProxy :: SProxy "mongo")
2929
Pt.</> Pt.dir (SProxy :: SProxy "testDb")
@@ -50,7 +50,7 @@ buildSelectQuery =
5050
∘ (S._relations ?~
5151
(S.TableRelation
5252
{ alias: Nothing
53-
, path: E.Left
53+
, path: E.Right $ E.Left
5454
$ Pt.rootDir
5555
Pt.</> Pt.dir (SProxy :: SProxy "mongo")
5656
Pt.</> Pt.dir (SProxy :: SProxy "testDb")

0 commit comments

Comments
 (0)