Commit Graph

773 Commits

Author SHA1 Message Date
Trevis Elser
c1a71736b0 Fix permissions for CI caching 2024-10-02 14:28:06 -04:00
Trevis Elser
90136377c5 Updates PostgreSQL versions tested with
PostgreSQL 17 has been released so we test against that. 12 is removed
from the tests, as it only has about a month of upstream support left
and to keep the test matrix somewhat manageable.
2024-10-02 13:31:59 -04:00
Trevis Elser
037728bd87 Removes legacy Orville
Removes code and docs for legacy orville version.
2024-10-01 20:16:10 -04:00
Trevis Elser
6c8684d7c0 Adds support for building a SelectExpr with @DISTINCT ON@ 2024-10-01 14:22:25 -04:00
Janus Troelsen
b90517eb0b Upgrade PostgreSQL in testing 2024-09-18 08:50:48 -06:00
Trevis Elser
c3da2baf32 Build with postgresql-libpq-0.11.0
The relevant change in 0.11.0 is supports PostgreSQL pipelining
feature. This skips support for that feature. For now this doesn't
attempt to support the pipelining.
2024-09-04 21:09:43 -04:00
Trevis Elser
99d754330e Merge remote-tracking branch 'tusharad/feature/onConflictDo' 2024-09-04 09:38:09 -04:00
Trevis Elser
46bfded387 Update ON CONFLICT support
This changes the support for building ON CONFLICT portions of an
INSERT in a few key ways:

- Supports using an 'IndexBodyExpr' in addition to 'ConstraintName'
and 'Qualified ColumnName' for determining what to check for a
conflict.

- Is based more around 'RawSql', which allows for callers to inject
things not explicitly supported at this time. For example, we do not
have a notion of COLLATION, and the PostgreSQL documentation even
mentions it as usually unneeded. However this now allows for it.

- The support is also broken out to a separate module. This is more
about module size than anything else. For example, it is not likely
that we would reuse the support elsewhere. This implementation detail
is easy enough to change and should be reconsidered before the next
release.
2024-09-03 14:42:15 -04:00
Nebula Lavelle
f618f975be Implements 'SqlComparable' instance for 'SqlMarshaller'
I added the instance and a number of helper functions for using it,
including `Plan`s like `findAllWhereByMarshaller`.

PostgreSQL does not support the input of anonymous row values, and the
instance methods need to produce row `SqlValue`s and `ValueExpression`s.
This meant that I had to add support for row values at the `SqlValue`
level. The `SqlRowValue` constructor will produce a row of placeholders:

```sql
($1, $2, $3)
```
2024-08-30 11:24:45 -04:00
tusharad
826bd83ba9 Added support for Insert ON CONFLICT DO UPDATE 2024-08-13 11:59:16 +05:30
Nebula Lavelle
cf41ce0799 Adds planTraversable, a generalization of planList 2024-08-09 19:48:37 -04:00
Nebula Lavelle
111b11da2a Updates GitHub workflow
- Use `docker compose` instead of `docker-compose`.
- Use fixed Ubuntu GitHub runner version instead of latest
2024-08-09 19:47:42 -04:00
Trevis Elser
38f42e0603 Ensure OVER has correct parens 2024-06-28 11:01:26 -04:00
John C. Lavelle
7e162900d6 Adds support for creating and migrating column comments
Setting a `fieldDescription` on a `FieldDefinition` will now result in a
SQL comment on that column.
2024-06-19 11:04:29 -04:00
Trevis Elser
5f9291aeb8 Merge branch 'telser/windowing-expr-and-functions' 2024-06-13 16:26:21 -04:00
John C. Lavelle
83685758f3 Merge branch 'jlavelle/from-item-expr-monoid' 2024-06-13 15:33:02 -04:00
Trevis Elser
ee9a4eb3aa Add windowing to 'SelectOptions'
Also, makes the window functions return a 'ValueExpression' so they
are more directly usable.
2024-06-13 15:30:20 -04:00
John C. Lavelle
45c957e0da Adds haddocks to PgDescription
Also fixed the @since annotations on `RelationDescription`.
2024-06-13 10:23:21 -04:00
John C. Lavelle
97da489793 Correctly handles Empty in RawSql Semigroup instance 2024-06-12 12:41:37 -04:00
John C. Lavelle
e5c6e5a210 Monoid instance for FromItemExpr
I added `Monoid` and `Semigroup` instances to `FromItemExpr` to support
writing queries with empty from lists with `mempty` or Cartesian
product from lists with `<>`.

I added an `Empty` constructor and an `appendWithCommaSpace` helper to
`RawSql` to facilitate the `Semigroup` instance, since we need to
generate different SQL if any of the `FromItemExpr`s being appended are
empty.
2024-06-12 09:52:24 -04:00
John C. Lavelle
8b388bda56 Adds support for adding and migrating table comments
Added:
- Expr-level support for comments
- Functions for getting and setting comments on a `TableDefinition`
- `AutoMigration` support for adding, removing, and modifying table comments
2024-06-10 12:13:32 -04:00
Trevis Elser
11134c5f3e Adding windowing function support
Adds Expr-level support for create a resuable window clause.
This takes the form of @WINDOW window_name AS (window_definition)@.

Creating a window_definition is separate precisely because it is
reused from the above window clause and in selection as the portion
that comes after the @OVER@ keyword.

Building on the ability to express a window definition, is a window
function call. These functions have some additional requirements:
  - They are only valid in select or order by contexts
  - The use of the OVER keyword and a window definition is required.

Specific helpers for the following windowing functions are included:
  - rank
  - rowNumber
  - dense_rank
  - percent_rank
2024-06-07 04:53:20 -04:00
Trevis Elser
9f28093f6b Fix CASE expr generation and add test for it.
Simple test case covers the overall CASE generation as well as the WHEN portion.
2024-06-05 10:47:05 -04:00
Trevis Elser
fd263858db Add conditional expression support
Adds support for "conditional expressions" as seen at
https://www.postgresql.org/docs/13/functions-conditional.html

These are not typical SQL functions, in that they must not be quoted
the same way. As such these cannot use the pre-existing support for
functions.

The module name of 'ConditionalExpr' is a bit odd in that there is no
type of the same name. However grouping these items does seem natural
as the PostgreSQL documentation groups them.
2024-06-04 16:28:36 -04:00
Trevis Elser
c076c572d8 Merge branch 'aallen/thread-safe-connections' 2024-06-04 16:22:33 -04:00
Trevis Elser
c231aa1206 Merge branch 'telser/row-locking' 2024-06-04 15:55:10 -04:00
Trevis Elser
0c789e961e Adds JoinExpr to model SQL JOIN
The pieces needed to represent @JOIN@ are now available at the 'expr' level.

- 'JoinType' represents the INNER/LEFT/RIGHT/LATERAL portion.

- 'JoinConstraint' represents the portion that would determine how to
limit the result set. Currently only a helper for 'ON expr' is added.
This is left general enough to support the 'USING(columnNames)' syntax
as well in a future exercise.

- 'JoinExpr' represent the above pieces put together so that they can
be easily folded together into a 'FromItemExpr'.

Perhaps the most controversial change included is renaming
'TableReferenceList' to 'FromItemExpr'. This change more closely
matches the name in the PostgreSQL documentation. Which hopefully aids
clarity as at least some users did not realize that the "Table" in
that name was _not_ necessarily a user defined table like a
'TableDefinition', but could be something like a @JOIN@ or a subquery.
2024-05-29 09:23:02 -04:00
David Vollbracht
3efb7a67f7 Adds MigrationLockOptions
These new options allow the user to control how many times Orville
will try to acquire the migration lock as well as the delay between
each attempt.

Note that this changes the default delay from the previous 10 milliseconds
to a randomized delay between 100 and 125 milliseconds. The default
max attempts remains set to 25.
2024-05-28 10:20:19 -05:00
Trevis Elser
d8aef905c2 Adding basic subquery expression support
This adds the ability to use a 'QueryExpr' as a subquery particularly
for one form of the expressions found at
https://www.postgresql.org/docs/12/functions-subquery.html.

In particular the following are added:
- 'EXISTS (subquery)', which results in a 'BooleanExpr'

- 'IN' subquery expression support of the form 'expression IN
(subquery)'.

- 'NOT IN' subquery expression support of the form 'expression NOT IN
(subquery)'.

- 'ANY' subquery expression support of the form 'expression operator
ANY (subquery)'. 'SOME' is an alias for 'ANY' supported by PostgreSQL,
but I left it out for simplicity.

- 'ALL' subquery expression support of the form 'expression operator
ALL (subquery)'.

Notably for 'IN', 'NOT IN', 'ANY', and 'ALL' there is a form that
works with a "row_constructor". That is not implemented here.

Also, there is a choice with the 'IN' and 'NOT IN' support. This
resuses the existing generation of those keywords but exposes separate
functions for building the 'BooleanExpr'. We could instead expose the
pieces and have users build the 'BooleanExpr' or we could implement
them as specializations of the 'anySubquery' and 'allSubquery'. That
specialization would look something like: 'inSubquery = anySubquery
equalsOp' and 'notInSubquery = allSubquery notEqualsOp'. Note those
would not generate the same literal SQL bytes. The path chosen here
feels like the best trade-off for users of the api at the cost of some
extra function definitions.
2024-05-24 13:11:22 -04:00
John C. Lavelle
dcbcc75c89 Merge branch 'jlavelle/order-by-value-expression' 2024-05-24 09:54:53 -04:00
Trevis Elser
e1e34e7578 Ensure cabal is installed to fix pipeline 2024-05-24 09:47:15 -04:00
David Vollbracht
b8a8c9dc1d Updates to latest haskell-tools image for development 2024-05-22 10:45:59 -05:00
John C. Lavelle
04e3ba5c71 Adds orderByValueExpression 2024-05-20 12:39:36 -04:00
Trevis Elser
dfa2699911 Merge branch 'telser/version-bounds-ghc-updates' 2024-05-04 12:49:50 -04:00
Trevis Elser
277561d9a4 Adds a higher level 'AliasName'
This allows for an alias concept to be used in more of the higher
level api, notably in the synthetic field.

The previous 'Alias' is renamed 'AliasExpr' to provide more
distinction between the two.
2024-04-27 18:40:55 -04:00
Aaron Allen
f2be3aa837 Run fourmolu 2024-04-26 15:21:33 -05:00
Aaron Allen
0c0a0017a9 Make Connections Thread Safe
Issuing multiple commands concurrently on the same connection results in
one of those commands hanging indefinitely, possibly due to a dead-lock
somewhere in libpq.

This introduces an MVar that is used to serialize access to the
connection for utilization purposes. The existing semantics around closing
connections should be preserved by the use of a second MVar.
2024-04-25 15:37:22 -05:00
Trevis Elser
fe3d3762a8 Bump dependency bounds and update which GHC are tested with
- Bump upper bounds on containers and time as reported by cabal outdated
- Minor version bumps in the 9.4 and 9.6 series
- Updates nightly to the latest, adding 9.8.2 to versions tested with
- Updates the cabal file with GHC versions tested against
- Removes a redundant constraint caught by newer versions of GHC.
2024-04-06 05:51:10 -04:00
Trevis Elser
cc252ccdcd Adds a RowLockingClause to SelectOptions
Support for the various forms of locking in a select statements is
added, as docummented by PostgrSQL at:
https://www.postgresql.org/docs/12/sql-select.html#SQL-FOR-UPDATE-SHARE

This is another case of a select option being left preferred, much like limit.
2024-04-06 04:44:55 -04:00
Trevis Elser
dcdc11ee84 Adds initial aliasing support.
The highlights:

- Moving to use 'Qualified ColumnName' in many/most places. This
allows for the aliasing to be used naturally in those places.

- Add an alias type and function to create a 'Qualified ColumnName'
with it. This signals that 'Alias' is in fact different than
'ColumnName' or 'TableName', and reusing them for aliasing is not
always appropriate.

- Adding a 'MarshallAlias' constructor to the 'SqlMarshaller' so that
an alias can be attached to all of the natural fields in a marshaller
in a single function call from users. Synthetic fields could be
refactored with this facility, but that was left out here to keep the
already big changeset smaller.

- Adds 'AliasedFieldDefinition' for holding a field that should be
referenced with an alias in SQL.

- Adds a 'SqlComparable' typeclass to allow for comparison in a
polymorphic way. Instances are provided for 'FieldDefinition',
'SyntheticField' and the new 'AliasedFieldDefinition'. Comparison
functions are exposed working with the class. The field definition
functions and operators for comparison are now type restricted
versions of the classy functions. In this way the "simple" case of
FieldDefinitions has the most specific functions, but
'AliasedFieldDefinition' and 'SyntheticField' can both be compared
against.

- A small number of helpers are added to make generation of bits of
SQL, such as a 'TableReferenceList' that includes the 'AS alias' piece.
2024-04-05 21:27:49 -04:00
Trevis Elser
b59a7dce4f Adds basic support for PostgreSQL extensions and particularly pg_trgm
At the highest level this does four things:
- Adds support for extensions, including automigration
- Adds a 'IfNotExistsExpr' for use in some extension support.
- Adds support for a subset of functionality provided by the pg_trgm
extension.
- Allows ordering to be done on a synthetic field.

Extension support is added at the expression level, as well as to the
'PgCatalog' tracking infrastructure to support 'AutoMigration'
for loading/unloading extensions.

Support for cascading the load of extensions supported and used
during automigration so that users can be sure to list the extension
they want and any dependencies will be loaded as well.

To be used in conjection with the extension support is some
functionality from pg_trgm. The ability to add both GIN and GIST
indexes are included, as well as overriding the GIST index parameter,
'siglen'. Further, the similarity, word_similarity, and
strict_word_similarity functions are exposed to compare value
expressions. Higher level synthetic fields that compare a column with
a value are also included. This hopefully covers a broad range of
usage such as LIKE queries, column similarity, and the flexibility to
use the function value in other ways.

Support for ordering by a synthetic field is added precisely be able
sort by similarity.

pg_trgm has a few things **not** included here:

  - The notion of a similarity threshold for each of the three
similarity functions. Including the ability to show and set the
values.

  - Operators comparing a pair of values that each, implicitly use a
corresponding threshold resulting in a boolean.

  - Operators that compute "distance", defined as 1 - similarity, for
each of the three similarities.
2024-03-24 14:18:11 -04:00
David Vollbracht
0164710a8a Merge branch 'add-trigger-support' 2024-03-18 09:27:37 -05:00
David Vollbracht
cbbd090141 Removes extra spaces from createTrigger and createFunction 2024-03-18 08:25:00 -05:00
Paul Burns
855f92147e
Updates github workflow file 2024-02-29 11:24:13 -05:00
Paul Burns
8bda0a7ed9
Fix typo in AutoMigration caused by previous commit 2024-02-29 11:23:26 -05:00
Paul Burns
8b3c17464c
Re-orders arguments to mkCreateFunctionExpr
Re-orders arguments to `mkCreateFunctionExpr` to be consistent with
`mkCreateTriggerExpr`
2024-02-29 11:05:24 -05:00
David Vollbracht
8e012e348b A couple (more) trigger doc touchups 2024-02-29 08:25:57 -06:00
David Vollbracht
b0f56fd028 Minor touchups in trigger related docs 2024-02-29 08:17:23 -06:00
David Vollbracht
e1d53d2c75 Fixes docs that said "sequence" instead of "function" 2024-02-28 14:00:56 -06:00
David Vollbracht
a46eaf1ff1 Bumps @since on DatabaseDescription lookupProcedure 2024-02-28 13:33:01 -06:00