-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This adds a new type `QualifiedName` for named PostgreSQL objects (tables, views, functions and sequences) that can optionally be qualified by a schema. Previously only `TableSchema` could be qualified in this way. `QualifiedName` has an `IsString` instance so the common case (where the schema is `Nothing`) doesn't have to care about schemas (if `OverloadedStrings` is enabled). This also refactors `TableSchema` to use `QualifiedName` for its `name` field and drops its `schema` field. Thanks to @elldritch for the bug report and the inspiration.
- Loading branch information
1 parent
8cec776
commit c778ac1
Showing
16 changed files
with
130 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!-- | ||
A new scriv changelog fragment. | ||
Uncomment the section that is right (remove the HTML comment wrapper). | ||
--> | ||
|
||
<!-- | ||
### Removed | ||
- A bullet item for the Removed category. | ||
--> | ||
### Added | ||
|
||
- Added the `QualifiedName` type for named PostgreSQL objects (tables, views, functions, sequences, etc.) that can optionally be qualified by a schema, including an `IsString` instance. | ||
|
||
### Changed | ||
|
||
- The `schema` field from `TableSchema` has been removed and the name field changed from `String` to `QualifiedName`. | ||
- `nextval` and `function` now take a `QualifiedName` instead of a `String`. | ||
|
||
<!-- | ||
### Deprecated | ||
- A bullet item for the Deprecated category. | ||
--> | ||
### Fixed | ||
|
||
- Fixes [#228](https://github.com/circuithub/rel8/issues/228) where it was impossible to call `nextval` with a qualified sequence name. | ||
|
||
<!-- | ||
### Security | ||
- A bullet item for the Security category. | ||
--> | ||
This comment has been minimized.
Sorry, something went wrong. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{-# language DataKinds #-} | ||
{-# language OverloadedStrings #-} | ||
|
||
module Rel8.Expr.Text | ||
( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{-# language OverloadedStrings #-} | ||
|
||
module Rel8.Expr.Time | ||
( -- * Working with @Day@ | ||
today | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{-# language DerivingStrategies #-} | ||
{-# language DuplicateRecordFields #-} | ||
{-# language RecordWildCards #-} | ||
{-# language StandaloneKindSignatures #-} | ||
{-# language StrictData #-} | ||
|
||
module Rel8.Schema.QualifiedName | ||
( QualifiedName (..) | ||
, ppQualifiedName | ||
) | ||
where | ||
|
||
-- base | ||
import Data.Kind (Type) | ||
import Data.String (IsString, fromString) | ||
import Prelude | ||
|
||
-- opaleye | ||
import qualified Opaleye.Internal.HaskellDB.Sql as Opaleye | ||
import qualified Opaleye.Internal.HaskellDB.Sql.Print as Opaleye | ||
|
||
-- pretty | ||
import Text.PrettyPrint (Doc) | ||
|
||
|
||
-- | A name of an object (such as a table, view, function or sequence) | ||
-- qualified by an optional schema. In the absence of an explicit schema, | ||
-- the connection's @search_path@ will be used implicitly. | ||
type QualifiedName :: Type | ||
data QualifiedName = QualifiedName | ||
{ name :: String | ||
-- ^ The name of the object. | ||
, schema :: Maybe String | ||
-- ^ The schema that this object belongs to. If 'Nothing', whatever is on | ||
-- the connection's @search_path@ will be used. | ||
} | ||
deriving stock (Eq, Ord, Show) | ||
|
||
|
||
-- | Constructs 'QualifiedName's with 'schema' set to 'Nothing'. | ||
instance IsString QualifiedName where | ||
fromString name = QualifiedName {schema = Nothing, ..} | ||
|
||
|
||
ppQualifiedName :: QualifiedName -> Doc | ||
ppQualifiedName QualifiedName {..} = Opaleye.ppTable Opaleye.SqlTable | ||
{ sqlTableSchemaName = schema | ||
, sqlTableName = name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ha, I never actually read this and just deleted everything and kept one section - I didn't realise you could have multiple!