on dev help sign in
scrap your nils!

mostly scrapped, still got some problems with SListI

commit06a2d7b55a2d91ac304c971824f50e55999c0843 authorEitan Chatav <eitan.chatav@gmail.com> dateSun 1 Jul 2018, 23:43 (8 years ago) parentb3f6651
5 files changed+48−38
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+3−3 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+1−1 squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+16−16 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+12−12 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+16−6
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+3−3
@@ -27,7 +27,7 @@ let
2727 query :: Query '[]
2828 '[ 'NotNull 'PGint2, 'NotNull 'PGtext]
2929 '["col1" ::: 'NotNull 'PGint2, "col2" ::: 'NotNull 'PGtext]
30− query = values_ (param @1 `As` #col1 :* param @2 `As` #col2 :* Nil)
30+ query = values_ (param @1 `as` #col1 :* param @2 `as` #col2)
3131:}
3232
3333>>> :{
@@ -88,7 +88,7 @@ let
8888 querySchwarma :: Query Schema
8989 '[ 'NotNull (EnumFrom Schwarma)]
9090 '["fromOnly" ::: 'NotNull (EnumFrom Schwarma)]
91− querySchwarma = values_ (parameter @1 #schwarma `As` #fromOnly)
91+ querySchwarma = values_ (parameter @1 #schwarma `as` #fromOnly)
9292:}
9393
9494>>> :{
@@ -96,7 +96,7 @@ let
9696 queryPerson :: Query Schema
9797 '[ 'NotNull (CompositeFrom Person)]
9898 '["fromOnly" ::: 'NotNull (CompositeFrom Person)]
99− queryPerson = values_ (parameter @1 #person `As` #fromOnly :* Nil)
99+ queryPerson = values_ (parameter @1 #person `as` #fromOnly)
100100:}
101101
102102And finally drop the types.
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+1−1
@@ -396,7 +396,7 @@ instance (KnownSymbol label, label `In` labels) => IsPGlabel label
396396-- (also called a composite value) using values for its member fields.
397397--
398398-- >>> type Complex = PGcomposite '["real" ::: 'PGfloat8, "imaginary" ::: 'PGfloat8]
399−-- >>> let i = row (0 `As` #real :* 1 `As` #imaginary :* Nil) :: Expression '[] '[] 'Ungrouped '[] ('NotNull Complex)
399+-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '[] '[] 'Ungrouped '[] ('NotNull Complex)
400400-- >>> printSQL i
401401-- ROW(0, 1)
402402row
squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+16−16
@@ -36,9 +36,9 @@ let
3636 { name = "make users table"
3737 , up = void . define $
3838 createTable #users
39− ( serial `As` #id :*
40− (text & notNullable) `As` #name :* Nil )
41− ( primaryKey #id `As` #pk_users :* Nil )
39+ ( serial `as` #id :*
40+ (text & notNullable) `as` #name )
41+ ( primaryKey #id `as` #pk_users )
4242 , down = void . define $ dropTable #users
4343 }
4444:}
@@ -51,12 +51,12 @@ let
5151 { name = "make emails table"
5252 , up = void . define $
5353 createTable #emails
54− ( serial `As` #id :*
55− (int & notNullable) `As` #user_id :*
56− (text & nullable) `As` #email :* Nil )
57− ( primaryKey #id `As` #pk_emails :*
54+ ( serial `as` #id :*
55+ (int & notNullable) `as` #user_id :*
56+ (text & nullable) `as` #email )
57+ ( primaryKey #id `as` #pk_emails :*
5858 foreignKey #user_id #users #id
59− OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
59+ OnDeleteCascade OnUpdateCascade `as` #fk_user_id )
6060 , down = void . define $ dropTable #emails
6161 }
6262:}
@@ -71,7 +71,7 @@ let
7171 :: Has "schema_migrations" schema ('Table MigrationsTable)
7272 => PQ schema schema IO ()
7373 numMigrations = do
74− result <- runQuery (selectStar (from (table (#schema_migrations `As` #m))))
74+ result <- runQuery (selectStar (from (table (#schema_migrations `as` #m))))
7575 num <- ntuples result
7676 liftBase $ print num
7777:}
@@ -285,18 +285,18 @@ createMigrations
285285 => Definition schema schema
286286createMigrations =
287287 createTableIfNotExists #schema_migrations
288− ( (text & notNullable) `As` #name :*
288+ ( (text & notNullable) `as` #name :*
289289 (timestampWithTimeZone & notNullable & default_ currentTimestamp)
290− `As` #executed_at :* Nil )
291− ( unique (#name :* Nil) `As` #migrations_unique_name :* Nil )
290+ `as` #executed_at )
291+ ( unique #name `as` #migrations_unique_name )
292292
293293-- | Inserts a `Migration` into the `MigrationsTable`
294294insertMigration
295295 :: Has "schema_migrations" schema ('Table MigrationsTable)
296296 => Manipulation schema '[ 'NotNull 'PGtext] '[]
297297insertMigration = insertRow_ #schema_migrations
298− ( Set (param @1) `As` #name :*
299− Default `As` #executed_at :* Nil )
298+ ( Set (param @1) `as` #name :*
299+ Default `as` #executed_at )
300300
301301-- | Deletes a `Migration` from the `MigrationsTable`
302302deleteMigration
@@ -311,6 +311,6 @@ selectMigration
311311 => Query schema '[ 'NotNull 'PGtext ]
312312 '[ "executed_at" ::: 'NotNull 'PGtimestamptz ]
313313selectMigration = select
314− (#executed_at `As` #executed_at :* Nil)
315− ( from (table (#schema_migrations `As` #m))
314+ (#executed_at `as` #executed_at)
315+ ( from (table (#schema_migrations `as` #m))
316316 & where_ (#name .== param @1))
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+12−12
@@ -123,7 +123,7 @@ let
123123 , "col1" ::: 'NotNull 'PGint4 ]
124124 query =
125125 select
126− ((#col1 + #col2) `As` #sum :* #col1 :* Nil)
126+ ((#col1 + #col2) `as` #sum :* #col1)
127127 ( from (table #tab)
128128 & where_ (#col1 .> #col2)
129129 & where_ (#col2 .> 0) )
@@ -141,7 +141,7 @@ let
141141 '["col" ::: 'Null 'PGint4]
142142 query =
143143 selectStar
144− (from (subquery (selectStar (from (table #tab)) `As` #sub)))
144+ (from (subquery (selectStar (from (table #tab)) `as` #sub)))
145145in printSQL query
146146:}
147147SELECT * FROM (SELECT * FROM "tab" AS "tab") AS "sub"
@@ -186,8 +186,8 @@ let
186186 '[ "sum" ::: 'NotNull 'PGint4
187187 , "col1" ::: 'NotNull 'PGint4 ]
188188 query =
189− select (sum_ #col2 `As` #sum :* #col1 :* Nil)
190− ( from (table (#tab `As` #table1))
189+ select (sum_ #col2 `as` #sum :* #col1)
190+ ( from (table (#tab `as` #table1))
191191 & group (By #col1 :* Nil)
192192 & having (#col1 + sum_ #col2 .> 1) )
193193in printSQL query
@@ -240,13 +240,13 @@ let
240240 , "shipper_name" ::: 'NotNull 'PGtext
241241 ]
242242 query = select
243− ( #o ! #price `As` #order_price :*
244− #c ! #name `As` #customer_name :*
245− #s ! #name `As` #shipper_name :* Nil )
246− ( from (table (#orders `As` #o)
247− & innerJoin (table (#customers `As` #c))
243+ ( #o ! #price `as` #order_price :*
244+ #c ! #name `as` #customer_name :*
245+ #s ! #name `as` #shipper_name )
246+ ( from (table (#orders `as` #o)
247+ & innerJoin (table (#customers `as` #c))
248248 (#o ! #customer_id .== #c ! #id)
249− & innerJoin (table (#shippers `As` #s))
249+ & innerJoin (table (#shippers `as` #s))
250250 (#o ! #shipper_id .== #s ! #id)) )
251251in printSQL query
252252:}
@@ -261,7 +261,7 @@ let
261261 '[]
262262 '["col" ::: 'Null 'PGint4]
263263 query = selectDotStar #t1
264− (from (table (#tab `As` #t1) & crossJoin (table (#tab `As` #t2))))
264+ (from (table (#tab `as` #t1) & crossJoin (table (#tab `as` #t2))))
265265in printSQL query
266266:}
267267SELECT "t1".* FROM "tab" AS "t1" CROSS JOIN "tab" AS "t2"
@@ -463,7 +463,7 @@ selectDistinctDotStar rel relations = UnsafeQuery $
463463-- but it can be used on its own.
464464--
465465-- >>> type Row = '["a" ::: 'NotNull 'PGint4, "b" ::: 'NotNull 'PGtext]
466−-- >>> let query = values (1 `As` #a :* "one" `As` #b :* Nil) [] :: Query '[] '[] Row
466+-- >>> let query = values (1 `as` #a :* "one" `as` #b) [] :: Query '[] '[] Row
467467-- >>> printSQL query
468468-- SELECT * FROM (VALUES (1, E'one')) AS t ("a", "b")
469469values
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+16−6
@@ -402,14 +402,24 @@ instance (alias0 ~ alias1, alias0 ~ alias2, KnownSymbol alias2)
402402 => IsLabel alias0 (Aliased Alias (alias1 ::: alias2)) where
403403 fromLabel = fromLabel @alias2 `As` fromLabel @alias1
404404
405−class KnownSymbol alias => Aliasable expression alias aliased where
406− as :: expression -> Alias alias -> aliased
405+class KnownSymbol alias => Aliasable expression alias aliased
406+ | aliased -> expression
407+ , aliased -> alias
408+ where
409+ as :: expression -> Alias alias -> aliased
410+
407411instance KnownSymbol alias => Aliasable
408− (expression ty) alias (Aliased expression (alias ::: ty)) where as = As
412+ (expression ty)
413+ alias
414+ (Aliased expression (alias ::: ty))
415+ where as = As
409416instance KnownSymbol alias => Aliasable
410− (expression ty) alias (NP (Aliased expression) '[alias ::: ty])
411− where
412− expression `as` alias = expression `As` alias :* Nil
417+ (expression ty)
418+ alias
419+ (NP (Aliased expression) '[alias ::: ty])
420+ where
421+ expression `as` alias = expression `As` alias :* Nil
422+
413423-- | >>> let renderMaybe = fromString . maybe "Nothing" (const "Just")
414424-- >>> renderAliasedAs renderMaybe (Just (3::Int) `As` #an_int)
415425-- "Just AS \"an_int\""