Commit Graph

99 Commits

Author SHA1 Message Date
Ben Levy
ea4ff33b93
Destroy all GADTs; Removes the From GADT and SqlExpr GADT (#228)
* Explode the From GADT. Move runFrom into the ToFrom typeclass removing the need for the intermediate structure. Extract the parts of the Experimental module into submodules.

* Reorganize Experimental folder. Move Subquery into core Experimental.From module.

* Cleanup hackage documentation. Make sure stylish ran correctly. Update changelog and bump version

* Update ERaw to change the direction of NeedParens (parent now tells child context). Removed need for composite key constructor

* Get rid of AliasedValue and ValueReference; added sqlExprMetaAlias to SqlExprMeta

* Remove EList and EEmptyList; ERaw is now technically possible in each case since it is generalized to all

* Remove entity specific constructors from SqlExpr

* Remove EOrderBy, EDistinctOn; Change PreprocessedFrom a to just be an independent datatype

* Remove EOrderByRandom, calling distinctOnOrderBy with rand will choke the db but you shouldnt be using rand anyway. distinctOnOrderBy seems dangerous though

* Remove ESet

* Remove EInsert and EInsertFinal

* Make postgres tests pass

* Change aliased val to be legal value by waiting until expr materialization in select clause before adding AS <alias>

* Cleanup ToAliasRefernce; Add isReference meta to value reference even though that info isnt currently used anywhere

* Expose Experimental submodules

* Update changelog

* Create a FromRaw to replace FromSubquery and FromIdent in from clause. Modify Experimental to only use FromRaw.

* Convert all of experimental to use new From type instead of From type class. Make the data constructors second class, functions should be used. Introduce *Lateral functions, using the same type for lateral and non lateral queries was probably a mistake.

* Expose the new functions and fix the mysql test compilation error (type inference was wonky with `Union` replaced with `union_`

* Bump version and add more comments

* ValidOnClause was too restrictive, ToFrom is actually the correct amount of leniency. ValidOnClause would not catch use of on for a cross join but would prevent nested joins

* Unbreak lateral joins by introducing a completely different ValidOnClause constraint

* Fixe error introduced in merge with master

* Dont realias alias references

* Never realias an already aliased Entity or Value

* reindex value references to the latest 'source'
2021-05-26 12:12:11 -06:00
Ben Levy
a319d13bee
[Experimental] More powerful queries (#215)
* Initial attempt at Lateral joins

* Fix lateral queries for Inner and Left joins. Remove for Full and Right as this is apparently illegal(who knew). Add TypeError on Full and Right joins. Update on clause to use a custom constraint instead of relying on ToFrom.

* Fix typo leading to erroneous ToFrom instance

* Implement non-recursive CTE's

* add withRecursive; cleanup whitespace

* Fix multiple recursive CTEs. Apparently the spec just wants RECURSIVE if any of the queries are recursive.

* Add test to verify that a CTE can reference a previously defined CTE

* Update with/Recursive to return an element of a from clause to allow for joins against CTEs

* Modify set operations to use a custom data type + typeclass + typefamily to allow direct use of SqlQuery a in set operation and to allow recursive cte's to unify syntax with SqlSetOperation. Added lowercase names for set operations. If we can migrate off the constructor names we may be able to simplify the implementation.

* Fixed haddock documentation issue from v3.3.4.0 and added documentation
for new features introduced by v3.4.0.0

* fixed comments that were changed while debugging haddock build

* Cleanup formatting in From per PR. Cleanup ValidOnClause, added documentation and reduced the number of instances

* Update src/Database/Esqueleto/Experimental.hs

Co-authored-by: charukiewicz <charukiewicz@protonmail.com>
Co-authored-by: Matt Parsons <parsonsmatt@gmail.com>
2020-10-28 21:37:17 -06:00
Matt Parsons
583167adb0
Make the Experimental module more prominent (#205)
* update README

* add comments

* update cabal

* update changelog
2020-09-17 14:52:38 -06:00
Ben Levy
56e4b83e5c
New syntax for Joins (Subquery + Union/Intersect/...) (#172)
* It works?

* Add multiple return values back in

* Allow order by alias

* Support groupBy and count, Returning value from a fromQuery now will make it into an alias

* Eliminate Alias type, TODO: finish implementing all the functions on Value for the alias constructors

* Add entity support to subqueries

* Cleanup duplication; Cleanup warnings and finish implementing all the cases for aliased values and entities.

* Cleanup fromQuery and add comments

* Modify EValueReference to support aliased entity fields instead of having to use opaque ERaw in field access

* Implement SQL Set Operations

* Add test to show novel use of fromQuery

* Cleanup unsafe case statements

* Add type annotations to helper queries to satisfy the typechecker on older GHC

* New syntax for joins, using placeholder names with ' in them to avoid name conflict with existing join types.
New api properly enforces Maybe on outer joins and requires an on clause for all joins in their construction.

* Add some more test queries using the new syntax

* Add test to verify that delete works with the new syntax

* Add cross join and implicit cross join using comma examples to test code for new from syntax

* Comment out use of CrossJoin in common tests since postgres cant handle it with the current implementation of the CrossJoin kind

* Add typeclass machinery to support the use of the old Join data types used in the existing from clause

* Fix bug with CrossJoin and add on_ syntax sugar

* move new from syntax into Database.Esqueleto.Experimental

* Merge subqueries and unions with the new join syntax, they all seem to play nicely together

* Cleanup somehow copies of ToAlias ended up staying in Internal and a swp file made it in to the branch.

* Fix compilation errors

* Swith tuple to using a TypeOperator

* Make operator only 2 characters

* added up to 8-tuple instances for ToMaybe, ToAlias, and ToAliasReference

* Add compiler error tests for new syntax to support making better errors

* Use closed data families to allow for catching missing on statements in joins.

* Convert ToAliasReferenceT to be a closed type family matching the other classes in the Experimental module

* added Esqueleto.Experimental documentation: added introduction and several examples of old vs. new syntax

* added more usage examples to module introduction; added documentation to SqlSetOperation, From, on, from, and (:&)

* Update (^.) to only treat natural keys with more than one component as ECompositeKey. Fixes #176.

* Update article metadata test to ensure the correct response was being returned instead of just check if an exception was thrown

* Add article metadata to cleanDB before deleting all articles to fix foreign key constraint errors

* Bump version number and add changelog entry

* Fix issue with ToMaybeT for Values, Maybe was going in the wrong place compared to the rest of the library. Add test to prove that Left joining into a subquery that returns a maybe flattens the maybe properly to avoid needing to call joinV.

* Fix common test for postgres, needed to add dogCounts to the group by since postgres is strict on only agregates for non grouped columns; I really need to set up a local postgresql

* Revert ToFromT changes. Only accept functions that return a SqlExpr (Value Bool) in ToFromT

* escaped use of '@' in TypeApplications in documentation

* Add more specific type signature to `on`

per parsonsmatt review suggestion. Improves type inference significantly.

Co-Authored-By: Matt Parsons <parsonsmatt@gmail.com>

Co-authored-by: charukiewicz <c.charukiewicz@gmail.com>
Co-authored-by: Matt Parsons <parsonsmatt@gmail.com>
2020-03-29 10:40:49 -06:00
Matt Parsons
3fcc965de7
Group by documentation (#170)
* Group by documentation
2020-01-16 10:03:53 -07:00
charukiewicz
a7435bac06 Exposed new SQL string functions added in v3.3.0 and bumped to v3.3.1 2019-12-12 22:42:26 -06:00
Matt Parsons
e0489988c8
sub_select fix #2 (#153)
* Deprecation notice

* Better message, changelog

* thanks @philonous for the typo find!

* Add subSelectCount

* Add subSelectList

* Add subSelectForeign

* Flip the warning back on

* Add subSelect test

* Write tests demonstrating usage

* fix

* sigh
2019-10-28 17:26:09 -06:00
Matt Parsons
91fa258193
Fix the On Clause Ordering issue (#156)
* Add failing test

* Refactor newIdentFor to not have an error case

* annotation for warning

* refactoring

* Expression parser

* holy shit it works

* Add a shitload of tests

* cross join

* Find a failing case

* Account for that one case

* works

* Composability test

* okay now it tests something

* Documentation updates

* Add since, changelog

* fix
2019-10-28 14:06:01 -06:00
brady.ouren
7b3cb37131 move function and bump version
- moves associateJoin to Database.Esqueleto
- relaxes bounds on containers dep
-
2019-10-25 11:58:54 -07:00
parsonsmatt
6d82106b68 renderQueryToText 2019-08-28 09:40:01 -06:00
Esteban Ibarra
5d8f5b53e6 Add between (#127)
* Update between so it works with SQL values

* Add support for composite keys in between clause

* Remove unused values from ERaw in construct

* Update unsafeSqlBinOp to handle composite keys and between to use >=., <=. and &&.

* Support composite keys in unsafeSqlBinOp correctly

* Updated changelog

* Update version number of between to 3.1.0
2019-08-08 11:23:10 -06:00
parsonsmatt
7e96bb54a7 Remove from public interface 2019-02-01 16:47:19 -07:00
Chris Allen
afdc7f792b Merge branch 'master' of github.com:bitemyapp/esqueleto 2018-02-27 17:45:26 -06:00
Chris Allen
0acb568445 Updating for UnliftIO, Conduit 1.3, Persistent 2.8 2018-02-27 17:45:25 -06:00
Chris Allen
68f327376b
Merge pull request #60 from mheinzel/master
Fix SQL syntax in join example
2018-02-27 17:41:25 -06:00
Cole Brown
501cf6b266 Add withNonNull helper to project nullable values
Guards against null values with a where_ call.
2017-10-17 13:25:56 -04:00
Matthias Heinzel
1ca1c3c185 Fix SQL syntax in join example 2017-10-13 22:09:28 +02:00
Chris Allen
ff87a31951 Export From 2017-07-25 13:48:19 -05:00
Kirill Zaborsky
99da7c333d Correct persistent module name for example imports
Follow-up to https://github.com/prowdsponsor/esqueleto/pull/152
2017-01-07 16:04:25 +03:00
Eric Easley
5d56abd698 Adjust for upcoming split db changes 2016-04-01 18:13:52 -07:00
Eric Easley
dc72d1bcd8 Export ToBaseId 2016-02-09 12:04:01 -08:00
Eric Easley
970deabfc2 Add ToBaseId 2016-02-06 16:47:26 -08:00
Chris Allen
f7bdd78d2e tests pass for insertSelectCount and I only raged at haskell-mode a teensy bit 2016-01-14 13:42:35 -06:00
Levi Notik
a727e0e9e1 fix some grammar in comments 2015-12-02 13:12:03 -05:00
Felipe Lessa
d350b4d2c7 countDistinct, countDistinctRows. 2015-08-11 12:05:24 -03:00
Felipe Lessa
555faaeaac castString, SqlString for Maybe. 2015-08-05 16:15:11 -03:00
Felipe Lessa
78a7fcdaeb New SqlString class, ditch IsString. 2015-08-05 15:54:16 -03:00
Felipe Lessa
871708987d New justList function. 2015-08-05 15:41:10 -03:00
Felipe Lessa
f32c98c412 New functions castNum and castNumM. 2015-07-15 14:20:13 -03:00
Felipe Lessa
6c63f2c5ac Add array_agg function, new PostgreSQL module. 2015-07-15 12:28:26 -03:00
Felipe Lessa
9552180629 Add support to simple locking clauses. 2015-06-27 12:32:49 -03:00
Felipe Lessa
80beea1e67 New convenience function distinctOnOrderBy. 2015-06-19 23:47:16 -03:00
Felipe Lessa
b8814fb09a Make distinctOn work like orderBy via 'don'. 2015-06-19 22:47:41 -03:00
Felipe Lessa
a1a09e736f New distinct, distinctOn. Deprecate old specializations. 2015-06-19 15:45:15 -03:00
Maciej Bielecki
2397ddf12b Add ILIKE operator 2015-05-20 06:10:28 +02:00
Felipe Lessa
9436fe9649 Use new repo address everywhere. 2015-05-12 13:20:34 -03:00
Felipe Lessa
07bd23f810 Add links to most identifiers on esqueleto docs. 2015-05-12 12:56:44 -03:00
Felipe Lessa
b20fe09755 Fix valkey's documentation. 2015-05-12 12:39:38 -03:00
Felipe Lessa
e4ccc4ecdc Fix markup for backticks ` and double quotes " on Haddocks.
Actually, the old form of backticks works on my Haddock, but somehow
doesn't on Hackage's Haddock.  This second form is still valid although
ugly, and works on my Haddock as well.  From reading Haddock's
documentation and source code, I don't think there's a canonical way of
writing this markup.
2015-05-12 12:32:45 -03:00
Alexandr Kurilin
b46c52d7b2 Add support for lower() function 2015-04-03 16:29:17 -07:00
Josh Berman
8579010409 INSERT INTO SELECT typo 2014-11-17 17:19:45 +02:00
Paul Berens
d690e0b425 Implement CASE support
* This seems to work but I don't have in-depth tests yet
 * I seem to still have some oddity here and there which needs to be
 nailed down
 * This only implements the "full" CASE syntax, not the simplified, and
 it makes ELSE mandatory, (its optional with CASE)
2014-11-02 01:31:54 -07:00
Michael Snoyman
05fbbba86a Support for persistent 2.0.8 2014-09-28 07:05:41 +03:00
Michael Snoyman
4febf46c6a Merge branch 'persistent2' of github.com:fpco/esqueleto
Conflicts:
	esqueleto.cabal
	src/Database/Esqueleto.hs
2014-09-08 09:05:57 +03:00
Michael Snoyman
30964d950d More persistent2 updates 2014-08-27 11:27:36 +03:00
Mitchell Rosen
e735378f90 added coalesce/coalesceDefault functions 2014-07-11 16:03:04 -07:00
Felipe Lessa
e91c625ff7 Small doc improvement. 2014-07-07 23:55:38 -03:00
Erik de Castro Lopo
41698518c9 Rename keyE to valJ and fix implementation.
As Felipe points out in the PR comments, the implementation can be
simplified to "val . unValue" but the type signature on the function
still prevents anything non-sensical happening.

See: https://github.com/prowdsponsor/esqueleto/pull/69
2014-07-08 10:47:44 +10:00
Erik de Castro Lopo
0b830771ea Add function keyE.
Give a value, keyE lifts the Key for that value into the query expression.

    keyE :: Esqueleto query expr backend =>
            Value (Key entity) -> expr (Value (Key entity))
2014-07-07 19:52:21 +10:00
Michael Snoyman
2685cdb7f7 Merge branch 'master' of github.com:meteficha/esqueleto into HEAD
Conflicts:
	esqueleto.cabal
	src/Database/Esqueleto/Internal/Sql.hs
2014-05-26 16:34:34 +03:00