Skip to content

Commit d44a467

Browse files
committed
Merge branch 'refactor-errors/1' into up-hasql
2 parents cf6ba3b + 6844503 commit d44a467

File tree

4 files changed

+44
-29
lines changed

4 files changed

+44
-29
lines changed

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,15 @@ Check the [development docs](https://github.com/PostgREST/postgrest/blob/main/ni
5353
### Running Tests
5454

5555
For instructions on running tests, see the [development docs](https://github.com/PostgREST/postgrest/blob/main/nix/README.md#testing).
56+
57+
### Structuring commits in pull requests
58+
59+
To simplify reviews, make it easy to split pull requests if deemed necessary, and to maintain clean and meaningful history of changes, you will be asked to update your PR if it does not follow the below rules:
60+
61+
* It must be possible to merge the PR branch into target using `git merge --ff-only`, ie. the source branch must be rebased on top of target.
62+
* No merge commits in the source branch.
63+
* All commits in the source branch must be self contained, meaning: it should be possible to treat each commit as a separate PR.
64+
* Commits in the source branch must contain only related changes (related means the changes target a single problem/goal). For example, any refactorings should be isolated from the actual change implementation into separate commits.
65+
* Tests, documentation, and changelog updates should be contained in the same commits as the actual code changes they relate to. An exception to this rule is when test or documentation changes are made in separate PR.
66+
* Commit messages must be prefixed with one of the prefixes defined in [the list used by commit verification scripts](https://github.com/PostgREST/postgrest/blob/main/nix/tools/gitTools.nix#L11).
67+
* Commit messages should contain a longer description of the purpose of the changes contained in the commit and, for non-trivial changes, a description of the changes themselves.

src/PostgREST/Query/SqlFragment.hs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ Module : PostgREST.Query.SqlFragment
66
Description : Helper functions for PostgREST.QueryBuilder.
77
-}
88
module PostgREST.Query.SqlFragment
9-
( noLocationF
10-
, handlerF
9+
( accessibleFuncs
10+
, accessibleTables
11+
, addConfigPgrstInserted
1112
, countF
12-
, groupF
13+
, currentSettingF
14+
, escapeIdent
15+
, escapeIdentList
16+
, explainF
17+
, fromJsonBodyF
1318
, fromQi
19+
, groupF
20+
, handlerF
21+
, intercalateSnippet
1422
, limitOffsetF
1523
, locationF
24+
, noLocationF
1625
, orderF
1726
, pgFmtColumn
1827
, pgFmtFilter
@@ -21,28 +30,19 @@ module PostgREST.Query.SqlFragment
2130
, pgFmtLogicTree
2231
, pgFmtOrderTerm
2332
, pgFmtSelectItem
24-
, pgFmtSpreadSelectItem
2533
, pgFmtSpreadJoinSelectItem
26-
, fromJsonBodyF
34+
, pgFmtSpreadSelectItem
2735
, responseHeadersF
2836
, responseStatusF
29-
, addConfigPgrstInserted
30-
, currentSettingF
3137
, returningF
38+
, schemaDescription
39+
, setConfigWithConstantName
40+
, setConfigWithConstantNameJSON
41+
, setConfigWithDynamicName
3242
, singleParameter
3343
, sourceCTE
3444
, sourceCTEName
3545
, unknownEncoder
36-
, intercalateSnippet
37-
, explainF
38-
, setConfigWithConstantName
39-
, setConfigWithDynamicName
40-
, setConfigWithConstantNameJSON
41-
, escapeIdent
42-
, escapeIdentList
43-
, schemaDescription
44-
, accessibleTables
45-
, accessibleFuncs
4646
) where
4747

4848
import qualified Data.Aeson as JSON
@@ -90,7 +90,8 @@ import PostgREST.RangeQuery (NonnegRange, allRange,
9090
rangeLimit, rangeOffset)
9191
import PostgREST.SchemaCache.Identifiers (FieldName,
9292
QualifiedIdentifier (..),
93-
RelIdentifier (..))
93+
RelIdentifier (..),
94+
escapeIdent, trimNullChars)
9495
import PostgREST.SchemaCache.Routine (MediaHandler (..),
9596
Routine (..),
9697
funcReturnsScalar,
@@ -163,9 +164,6 @@ pgBuildArrayLiteral vals =
163164
pgFmtIdent :: Text -> SQL.Snippet
164165
pgFmtIdent x = SQL.sql $ escapeIdent x
165166

166-
escapeIdent :: Text -> Text
167-
escapeIdent x = "\"" <> T.replace "\"" "\"\"" (trimNullChars x) <> "\""
168-
169167
-- Only use it if the input comes from the database itself, like on `jsonb_build_object('column_from_a_table', val)..`
170168
pgFmtLit :: Text -> Text
171169
pgFmtLit x =
@@ -176,9 +174,6 @@ pgFmtLit x =
176174
then "E" <> slashed
177175
else slashed
178176

179-
trimNullChars :: Text -> Text
180-
trimNullChars = T.takeWhile (/= '\x0')
181-
182177
-- |
183178
-- Format a list of identifiers and separate them by commas.
184179
--

src/PostgREST/SchemaCache.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ import NeatInterpolation (trimming)
4242
import PostgREST.Config (AppConfig (..))
4343
import PostgREST.Config.Database (TimezoneNames,
4444
toIsolationLevel)
45-
import PostgREST.Query.SqlFragment (escapeIdent)
4645
import PostgREST.SchemaCache.Identifiers (FieldName,
4746
QualifiedIdentifier (..),
4847
RelIdentifier (..),
49-
Schema, isAnyElement)
48+
Schema, escapeIdent,
49+
isAnyElement)
5050
import PostgREST.SchemaCache.Relationship (Cardinality (..),
5151
Junction (..),
5252
Relationship (..),

src/PostgREST/SchemaCache/Identifiers.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
{-# LANGUAGE DeriveGeneric #-}
33

44
module PostgREST.SchemaCache.Identifiers
5-
( QualifiedIdentifier(..)
5+
( FieldName
6+
, QualifiedIdentifier(..)
67
, RelIdentifier(..)
7-
, isAnyElement
88
, Schema
99
, TableName
10-
, FieldName
1110
, dumpQi
11+
, escapeIdent
12+
, isAnyElement
1213
, toQi
14+
, trimNullChars
1315
) where
1416

1517
import qualified Data.Aeson as JSON
@@ -46,6 +48,12 @@ toQi txt = case T.drop 1 <$> T.breakOn "." txt of
4648
(i, "") -> QualifiedIdentifier mempty i
4749
(s, i) -> QualifiedIdentifier s i
4850

51+
escapeIdent :: Text -> Text
52+
escapeIdent x = "\"" <> T.replace "\"" "\"\"" (trimNullChars x) <> "\""
53+
54+
trimNullChars :: Text -> Text
55+
trimNullChars = T.takeWhile (/= '\x0')
56+
4957
type Schema = Text
5058
type TableName = Text
5159
type FieldName = Text

0 commit comments

Comments
 (0)