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

Commit 21b779b

Browse files
authored
Convert line endings (#11)
1 parent 7a5d306 commit 21b779b

12 files changed

+2398
-2389
lines changed

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*.{js,json,purs,less,yml}]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

README.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
# purescript-sqlsquare
2-
3-
[![Latest release](http://img.shields.io/github/release/slamdata/purescript-sqlsquare.svg)](https://github.com/slamdata/purescript-sqlsquare/releases)
4-
[![Build status](https://travis-ci.org/slamdata/purescript-sqlsquare.svg?branch=master)](https://travis-ci.org/slamdata/purescript-sqlsquare)
5-
6-
AST and printer for SQL² -- query language used by [quasar](https://github.com/quasar-analytics/quasar).
7-
8-
## Instalation
9-
10-
```
11-
bower install purescript-sqlsquare
12-
```
13-
14-
## Documentation
15-
16-
There is an example (extracted from [slamdata](https://github.com/slamdata/slamdata))
17-
+ Extraction sql fields from array of jsons: [here](test/src/Argonaut.purs)
18-
19-
Module documentation is published on Pursuit: [http://pursuit.purescript.org/packages/purescript-sqlsquare](http://pursuit.purescript.org/packages/purescript-sqlsquare)
1+
# purescript-sqlsquare
2+
3+
[![Latest release](http://img.shields.io/github/release/slamdata/purescript-sqlsquare.svg)](https://github.com/slamdata/purescript-sqlsquare/releases)
4+
[![Build status](https://travis-ci.org/slamdata/purescript-sqlsquare.svg?branch=master)](https://travis-ci.org/slamdata/purescript-sqlsquare)
5+
6+
AST and printer for SQL² -- query language used by [quasar](https://github.com/quasar-analytics/quasar).
7+
8+
## Instalation
9+
10+
```
11+
bower install purescript-sqlsquare
12+
```
13+
14+
## Documentation
15+
16+
There is an example (extracted from [slamdata](https://github.com/slamdata/slamdata))
17+
+ Extraction sql fields from array of jsons: [here](test/src/Argonaut.purs)
18+
19+
Module documentation is published on Pursuit: [http://pursuit.purescript.org/packages/purescript-sqlsquare](http://pursuit.purescript.org/packages/purescript-sqlsquare)

src/SqlSquare.purs

+41-41
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
module SqlSquared
2-
( Sql
3-
, print
4-
, encodeJson
5-
, decodeJson
6-
, arbitrarySqlOfSize
7-
, module Sig
8-
, module Lenses
9-
, module Constructors
10-
, module Parser
11-
) where
12-
13-
import Prelude
14-
15-
import Data.Argonaut as J
16-
import Data.Either (Either)
17-
import Data.Functor.Mu (Mu)
18-
import Data.Json.Extended as EJ
19-
20-
import Matryoshka (cata, anaM)
21-
22-
import SqlSquared.Signature as Sig
23-
import SqlSquared.Lenses as Lenses
24-
import SqlSquared.Constructors as Constructors
25-
import SqlSquared.Parser as Parser
26-
27-
import Test.StrongCheck.Gen as Gen
28-
29-
type Sql = Mu (Sig.SqlF EJ.EJsonF)
30-
31-
print Sql String
32-
print = cata $ Sig.printSqlF EJ.renderEJsonF
33-
34-
encodeJson Sql J.Json
35-
encodeJson = cata $ Sig.encodeJsonSqlF EJ.encodeJsonEJsonF
36-
37-
decodeJson J.Json Either String Sql
38-
decodeJson = anaM $ Sig.decodeJsonSqlF EJ.decodeJsonEJsonF
39-
40-
arbitrarySqlOfSize Int Gen.Gen Sql
41-
arbitrarySqlOfSize = anaM $ Sig.arbitrarySqlF EJ.arbitraryEJsonF
1+
module SqlSquared
2+
( Sql
3+
, print
4+
, encodeJson
5+
, decodeJson
6+
, arbitrarySqlOfSize
7+
, module Sig
8+
, module Lenses
9+
, module Constructors
10+
, module Parser
11+
) where
12+
13+
import Prelude
14+
15+
import Data.Argonaut as J
16+
import Data.Either (Either)
17+
import Data.Functor.Mu (Mu)
18+
import Data.Json.Extended as EJ
19+
20+
import Matryoshka (cata, anaM)
21+
22+
import SqlSquared.Signature as Sig
23+
import SqlSquared.Lenses as Lenses
24+
import SqlSquared.Constructors as Constructors
25+
import SqlSquared.Parser as Parser
26+
27+
import Test.StrongCheck.Gen as Gen
28+
29+
type Sql = Mu (Sig.SqlF EJ.EJsonF)
30+
31+
print Sql String
32+
print = cata $ Sig.printSqlF EJ.renderEJsonF
33+
34+
encodeJson Sql J.Json
35+
encodeJson = cata $ Sig.encodeJsonSqlF EJ.encodeJsonEJsonF
36+
37+
decodeJson J.Json Either String Sql
38+
decodeJson = anaM $ Sig.decodeJsonSqlF EJ.decodeJsonEJsonF
39+
40+
arbitrarySqlOfSize Int Gen.Gen Sql
41+
arbitrarySqlOfSize = anaM $ Sig.arbitrarySqlF EJ.arbitraryEJsonF

src/SqlSquare/Constructors.purs

+129-129
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,129 @@
1-
module SqlSquared.Constructors where
2-
3-
import Prelude
4-
5-
import Data.Array as Arr
6-
import Data.Json.Extended.Signature (EJsonF(..), EJsonMap(..))
7-
import Data.Foldable as F
8-
import Data.HugeNum as HN
9-
import Data.List as L
10-
import Data.Map as Map
11-
import Data.Maybe (Maybe(..))
12-
13-
import Matryoshka (class Corecursive, embed)
14-
15-
import SqlSquared.Signature as Sig
16-
import SqlSquared.Utils ((∘))
17-
18-
vari t f. Corecursive t (Sig.SqlF f) String t
19-
vari = embed ∘ Sig.Vari
20-
21-
bool t. Corecursive t (Sig.SqlF EJsonF) Boolean t
22-
bool = embed ∘ Sig.LiteralBoolean
23-
24-
null t. Corecursive t (Sig.SqlF EJsonF) t
25-
null = embed $ Sig.Literal Null
26-
27-
int t. Corecursive t (Sig.SqlF EJsonF) Int t
28-
int = embed ∘ Sig.LiteralInteger
29-
30-
num t. Corecursive t (Sig.SqlF EJsonF) Number t
31-
num = embed ∘ Sig.LiteralDecimalHN.fromNumber
32-
33-
hugeNum t. Corecursive t (Sig.SqlF EJsonF) HN.HugeNum t
34-
hugeNum = embed ∘ Sig.LiteralDecimal
35-
36-
string t. Corecursive t (Sig.SqlF EJsonF) String t
37-
string = embed ∘ Sig.LiteralString
38-
39-
unop t f. Corecursive t (Sig.SqlF f) Sig.UnaryOperator t t
40-
unop op expr = embed $ Sig.Unop { op, expr }
41-
42-
binop t f. Corecursive t (Sig.SqlF f) Sig.BinaryOperator t t t
43-
binop op lhs rhs = embed $ Sig.Binop { op, lhs, rhs }
44-
45-
set t f g. Corecursive t (Sig.SqlF g) F.Foldable f f t t
46-
set = embed ∘ Sig.SetLiteralL.fromFoldable
47-
48-
array t f. Corecursive t (Sig.SqlF EJsonF) F.Foldable f f t t
49-
array = embed ∘ Sig.LiteralArrayArr.fromFoldable
50-
51-
map_ t. Corecursive t (Sig.SqlF EJsonF) Ord t Map.Map t t t
52-
map_ = embed ∘ Sig.LiteralMapEJsonMapMap.toUnfoldable
53-
54-
splice t f. Corecursive t (Sig.SqlF f) Maybe t t
55-
splice = embed ∘ Sig.Splice
56-
57-
ident t f. Corecursive t (Sig.SqlF f) String t
58-
ident = embed ∘ Sig.Ident
59-
60-
match t f. Corecursive t (Sig.SqlF f) t L.List (Sig.Case t) Maybe t t
61-
match expr cases else_ = embed $ Sig.Match { expr, cases, else_ }
62-
63-
switch t f. Corecursive t (Sig.SqlF f) L.List (Sig.Case t) Maybe t t
64-
switch cases else_ = embed $ Sig.Switch { cases, else_ }
65-
66-
let_ t f. Corecursive t (Sig.SqlF f) String t t t
67-
let_ id bindTo in_ = embed $ Sig.Let { ident: id, bindTo, in_ }
68-
69-
invokeFunction t f. Corecursive t (Sig.SqlF f) String L.List t t
70-
invokeFunction name args = embed $ Sig.InvokeFunction {name, args}
71-
72-
-- when (bool true) # then_ (num 1.0) :P
73-
when t. t (t Sig.Case t)
74-
when cond = Sig.Case ∘ { cond, expr: _ }
75-
76-
then_ t. t (t Sig.Case t) Sig.Case t
77-
then_ t f = f t
78-
79-
select
80-
t f
81-
. Corecursive t (Sig.SqlF EJsonF)
82-
F.Foldable f
83-
Boolean
84-
f (Sig.Projection t)
85-
Maybe (Sig.Relation t)
86-
Maybe t
87-
Maybe (Sig.GroupBy t)
88-
Maybe (Sig.OrderBy t)
89-
t
90-
select isDistinct projections relations filter gb orderBy =
91-
embed
92-
$ Sig.Select
93-
{ isDistinct
94-
, projections: L.fromFoldable projections
95-
, relations
96-
, filter
97-
, groupBy: gb
98-
, orderBy
99-
}
100-
101-
102-
-- project (ident "foo") # as "bar"
103-
-- project (ident "foo")
104-
projection t. t Sig.Projection t
105-
projection expr = Sig.Projection {expr, alias: Nothing}
106-
107-
as t. String Sig.Projection t Sig.Projection t
108-
as s (Sig.Projection r) = Sig.Projection r { alias = Just s }
109-
110-
groupBy t f. F.Foldable f f t Sig.GroupBy t
111-
groupBy f = Sig.GroupBy { keys: L.fromFoldable f, having: Nothing }
112-
113-
having t. t Sig.GroupBy t Sig.GroupBy t
114-
having t (Sig.GroupBy r) = Sig.GroupBy r{ having = Just t }
115-
116-
buildSelect t f. Corecursive t (Sig.SqlF f) (Sig.SelectR t Sig.SelectR t) t
117-
buildSelect f =
118-
embed
119-
$ Sig.Select
120-
$ f { isDistinct: false
121-
, projections: L.Nil
122-
, relations: Nothing
123-
, filter: Nothing
124-
, groupBy: Nothing
125-
, orderBy: Nothing
126-
}
127-
128-
pars t f. Corecursive t (Sig.SqlF f) t t
129-
pars = embed ∘ Sig.Parens
1+
module SqlSquared.Constructors where
2+
3+
import Prelude
4+
5+
import Data.Array as Arr
6+
import Data.Json.Extended.Signature (EJsonF(..), EJsonMap(..))
7+
import Data.Foldable as F
8+
import Data.HugeNum as HN
9+
import Data.List as L
10+
import Data.Map as Map
11+
import Data.Maybe (Maybe(..))
12+
13+
import Matryoshka (class Corecursive, embed)
14+
15+
import SqlSquared.Signature as Sig
16+
import SqlSquared.Utils ((∘))
17+
18+
vari t f. Corecursive t (Sig.SqlF f) String t
19+
vari = embed ∘ Sig.Vari
20+
21+
bool t. Corecursive t (Sig.SqlF EJsonF) Boolean t
22+
bool = embed ∘ Sig.LiteralBoolean
23+
24+
null t. Corecursive t (Sig.SqlF EJsonF) t
25+
null = embed $ Sig.Literal Null
26+
27+
int t. Corecursive t (Sig.SqlF EJsonF) Int t
28+
int = embed ∘ Sig.LiteralInteger
29+
30+
num t. Corecursive t (Sig.SqlF EJsonF) Number t
31+
num = embed ∘ Sig.LiteralDecimalHN.fromNumber
32+
33+
hugeNum t. Corecursive t (Sig.SqlF EJsonF) HN.HugeNum t
34+
hugeNum = embed ∘ Sig.LiteralDecimal
35+
36+
string t. Corecursive t (Sig.SqlF EJsonF) String t
37+
string = embed ∘ Sig.LiteralString
38+
39+
unop t f. Corecursive t (Sig.SqlF f) Sig.UnaryOperator t t
40+
unop op expr = embed $ Sig.Unop { op, expr }
41+
42+
binop t f. Corecursive t (Sig.SqlF f) Sig.BinaryOperator t t t
43+
binop op lhs rhs = embed $ Sig.Binop { op, lhs, rhs }
44+
45+
set t f g. Corecursive t (Sig.SqlF g) F.Foldable f f t t
46+
set = embed ∘ Sig.SetLiteralL.fromFoldable
47+
48+
array t f. Corecursive t (Sig.SqlF EJsonF) F.Foldable f f t t
49+
array = embed ∘ Sig.LiteralArrayArr.fromFoldable
50+
51+
map_ t. Corecursive t (Sig.SqlF EJsonF) Ord t Map.Map t t t
52+
map_ = embed ∘ Sig.LiteralMapEJsonMapMap.toUnfoldable
53+
54+
splice t f. Corecursive t (Sig.SqlF f) Maybe t t
55+
splice = embed ∘ Sig.Splice
56+
57+
ident t f. Corecursive t (Sig.SqlF f) String t
58+
ident = embed ∘ Sig.Ident
59+
60+
match t f. Corecursive t (Sig.SqlF f) t L.List (Sig.Case t) Maybe t t
61+
match expr cases else_ = embed $ Sig.Match { expr, cases, else_ }
62+
63+
switch t f. Corecursive t (Sig.SqlF f) L.List (Sig.Case t) Maybe t t
64+
switch cases else_ = embed $ Sig.Switch { cases, else_ }
65+
66+
let_ t f. Corecursive t (Sig.SqlF f) String t t t
67+
let_ id bindTo in_ = embed $ Sig.Let { ident: id, bindTo, in_ }
68+
69+
invokeFunction t f. Corecursive t (Sig.SqlF f) String L.List t t
70+
invokeFunction name args = embed $ Sig.InvokeFunction {name, args}
71+
72+
-- when (bool true) # then_ (num 1.0) :P
73+
when t. t (t Sig.Case t)
74+
when cond = Sig.Case ∘ { cond, expr: _ }
75+
76+
then_ t. t (t Sig.Case t) Sig.Case t
77+
then_ t f = f t
78+
79+
select
80+
t f
81+
. Corecursive t (Sig.SqlF EJsonF)
82+
F.Foldable f
83+
Boolean
84+
f (Sig.Projection t)
85+
Maybe (Sig.Relation t)
86+
Maybe t
87+
Maybe (Sig.GroupBy t)
88+
Maybe (Sig.OrderBy t)
89+
t
90+
select isDistinct projections relations filter gb orderBy =
91+
embed
92+
$ Sig.Select
93+
{ isDistinct
94+
, projections: L.fromFoldable projections
95+
, relations
96+
, filter
97+
, groupBy: gb
98+
, orderBy
99+
}
100+
101+
102+
-- project (ident "foo") # as "bar"
103+
-- project (ident "foo")
104+
projection t. t Sig.Projection t
105+
projection expr = Sig.Projection {expr, alias: Nothing}
106+
107+
as t. String Sig.Projection t Sig.Projection t
108+
as s (Sig.Projection r) = Sig.Projection r { alias = Just s }
109+
110+
groupBy t f. F.Foldable f f t Sig.GroupBy t
111+
groupBy f = Sig.GroupBy { keys: L.fromFoldable f, having: Nothing }
112+
113+
having t. t Sig.GroupBy t Sig.GroupBy t
114+
having t (Sig.GroupBy r) = Sig.GroupBy r{ having = Just t }
115+
116+
buildSelect t f. Corecursive t (Sig.SqlF f) (Sig.SelectR t Sig.SelectR t) t
117+
buildSelect f =
118+
embed
119+
$ Sig.Select
120+
$ f { isDistinct: false
121+
, projections: L.Nil
122+
, relations: Nothing
123+
, filter: Nothing
124+
, groupBy: Nothing
125+
, orderBy: Nothing
126+
}
127+
128+
pars t f. Corecursive t (Sig.SqlF f) t t
129+
pars = embed ∘ Sig.Parens

0 commit comments

Comments
 (0)