Copyright | (c) Eitan Chatav 2020 |
---|---|
Maintainer | eitan@morphism.tech |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module implements a data type ltree for representing labels of data stored in a hierarchical tree-like structure.
Synopsis
- createLTree :: Definition db db
- newtype LTree = UnsafeLTree {}
- newtype LQuery = UnsafeLQuery {}
- newtype LTxtQuery = UnsafeLTxtQuery {
- getLTxtQuery :: Text
- type PGltree = 'UnsafePGType "ltree"
- type PGlquery = 'UnsafePGType "lquery"
- type PGltxtquery = 'UnsafePGType "ltxtquery"
- ltree :: TypeExpression db (null PGltree)
- lquery :: TypeExpression db (null PGlquery)
- ltxtquery :: TypeExpression db (null PGltxtquery)
- subltree :: '[null PGltree, null 'PGint4, null 'PGint4] ---> null PGltree
- subpath :: '[null PGltree, null 'PGint4, null 'PGint4] ---> null PGltree
- subpathEnd :: '[null PGltree, null 'PGint4] ---> null PGltree
- nlevel :: null PGltree --> null 'PGint4
- indexLTree :: '[null PGltree, null PGltree] ---> null 'PGint4
- indexOffset :: '[null PGltree, null PGltree, null 'PGint4] ---> null 'PGint4
- text2ltree :: null 'PGtext --> null PGltree
- ltree2text :: null PGltree --> null 'PGtext
- lca :: null ('PGvararray ('NotNull PGltree)) --> null PGltree
- (%~) :: Operator (null0 PGltree) (null1 PGlquery) ('Null 'PGbool)
- (~%) :: Operator (null1 PGlquery) (null0 PGltree) ('Null 'PGbool)
- (%?) :: Operator (null0 PGltree) (null1 ('PGvararray ('NotNull PGlquery))) ('Null 'PGbool)
- (?%) :: Operator (null0 ('PGvararray ('NotNull PGlquery))) (null1 PGltree) ('Null 'PGbool)
- (%@) :: Operator (null0 PGltree) (null1 PGltxtquery) ('Null 'PGbool)
- (@%) :: Operator (null0 PGltxtquery) (null1 PGltree) ('Null 'PGbool)
- (@>%) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGltree) ('Null 'PGbool)
- (%<@) :: Operator (null0 PGltree) (null1 ('PGvararray ('NotNull PGltree))) ('Null 'PGbool)
- (<@%) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGltree) ('Null 'PGbool)
- (%@>) :: Operator (null0 PGltree) (null1 ('PGvararray ('NotNull PGltree))) ('Null 'PGbool)
- (&~) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGlquery) ('Null 'PGbool)
- (~&) :: Operator (null0 PGlquery) (null1 ('PGvararray ('NotNull PGltree))) ('Null 'PGbool)
- (&?) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 ('PGvararray ('NotNull PGlquery))) ('Null 'PGbool)
- (?&) :: Operator (null0 ('PGvararray ('NotNull PGlquery))) (null1 ('PGvararray ('NotNull PGltree))) ('Null 'PGbool)
- (&@) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGltxtquery) ('Null 'PGbool)
- (@&) :: Operator (null0 PGltxtquery) (null1 ('PGvararray ('NotNull PGltree))) ('Null 'PGbool)
- (?@>) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGltree) ('Null PGltree)
- (?<@) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGltree) ('Null PGltree)
- (?~) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGlquery) ('Null PGltree)
- (?@) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGltxtquery) ('Null PGltree)
Definition
createLTree :: Definition db db Source #
Loads ltree extension into the current database.
Types
A label is a sequence of alphanumeric characters and underscores (for example, in C locale the characters A-Za-z0-9_ are allowed). Labels must be less than 256 bytes long.
Examples: 42, Personal_Services
A label path is a sequence of zero or more labels separated by dots, for example L1.L2.L3, representing a path from the root of a hierarchical tree to a particular node. The length of a label path must be less than 65Kb, but keeping it under 2Kb is preferable. In practice this is not a major limitation; for example, the longest label path in the DMOZ catalogue (http://www.dmoz.org) is about 240 bytes.
Example: Top.Countries.Europe.Russia
ltree stores a label path.
Instances
Generic LTree Source # | |
Read LTree Source # | |
Show LTree Source # | |
Eq LTree Source # | |
Ord LTree Source # | |
Inline LTree Source # | |
(TypeError ('Text "LTree binary instances not yet implemented.") :: Constraint) => FromPG LTree Source # | |
Defined in Squeal.PostgreSQL.LTree | |
IsPG LTree Source # | |
Defined in Squeal.PostgreSQL.LTree | |
(TypeError ('Text "LTree binary instances not yet implemented.") :: Constraint) => ToPG db LTree Source # | |
Defined in Squeal.PostgreSQL.LTree | |
type Rep LTree Source # | |
Defined in Squeal.PostgreSQL.LTree | |
type PG LTree Source # | |
Defined in Squeal.PostgreSQL.LTree |
lquery represents a regular-expression-like pattern for matching ltree values. A simple word matches that label within a path. A star symbol (*) matches zero or more labels. For example:
foo Match the exact label path foo *.foo.* Match any label path containing the label foo *.foo Match any label path whose last label is foo
Star symbols can also be quantified to restrict how many labels they can match:
*{n} Match exactly n labels *{n,} Match at least n labels *{n,m} Match at least n but not more than m labels *{,m} Match at most m labels — same as *{0,m}
There are several modifiers that can be put at the end of a non-star label in lquery to make it match more than just the exact match:
@ Match case-insensitively, for example a@ matches A * Match any label with this prefix, for example foo* matches foobar % Match initial underscore-separated words
The behavior of % is a bit complicated. It tries to match words rather than the entire label. For example foo_bar% matches foo_bar_baz but not foo_barbaz. If combined with *, prefix matching applies to each word separately, for example foo_bar%* matches foo1_bar2_baz but not foo1_br2_baz.
Also, you can write several possibly-modified labels separated with | (OR) to match any of those labels, and you can put ! (NOT) at the start to match any label that doesn't match any of the alternatives.
Here's an annotated example of lquery:
Top.*{0,2}.sport*@.!football|tennis.Russ*|Spain 1. 2. 3. 4. 5.
This query will match any label path that:
- begins with the label Top
- and next has zero to two labels before
- a label beginning with the case-insensitive prefix sport
- then a label not matching football nor tennis
- and then ends with a label beginning with Russ or exactly matching Spain.
Instances
Generic LQuery Source # | |
Read LQuery Source # | |
Show LQuery Source # | |
Eq LQuery Source # | |
Ord LQuery Source # | |
Inline LQuery Source # | |
(TypeError ('Text "LQuery binary instances not yet implemented.") :: Constraint) => FromPG LQuery Source # | |
Defined in Squeal.PostgreSQL.LTree | |
IsPG LQuery Source # | |
Defined in Squeal.PostgreSQL.LTree | |
(TypeError ('Text "LQuery binary instances not yet implemented.") :: Constraint) => ToPG db LQuery Source # | |
Defined in Squeal.PostgreSQL.LTree | |
type Rep LQuery Source # | |
Defined in Squeal.PostgreSQL.LTree | |
type PG LQuery Source # | |
Defined in Squeal.PostgreSQL.LTree |
ltxtquery represents a full-text-search-like pattern for matching ltree values. An ltxtquery value contains words, possibly with the modifiers @, *, % at the end; the modifiers have the same meanings as in lquery. Words can be combined with & (AND), | (OR), ! (NOT), and parentheses. The key difference from lquery is that ltxtquery matches words without regard to their position in the label path.
Here's an example ltxtquery:
Europe & Russia*@ & !Transportation
This will match paths that contain the label Europe and any label beginning with Russia (case-insensitive), but not paths containing the label Transportation. The location of these words within the path is not important. Also, when % is used, the word can be matched to any underscore-separated word within a label, regardless of position.
Note: ltxtquery allows whitespace between symbols, but ltree and lquery do not.
Instances
Generic LTxtQuery Source # | |
Read LTxtQuery Source # | |
Show LTxtQuery Source # | |
Eq LTxtQuery Source # | |
Ord LTxtQuery Source # | |
Defined in Squeal.PostgreSQL.LTree | |
Inline LTxtQuery Source # | |
(TypeError ('Text "LTxtQuery binary instances not yet implemented.") :: Constraint) => FromPG LTxtQuery Source # | |
Defined in Squeal.PostgreSQL.LTree | |
IsPG LTxtQuery Source # | |
Defined in Squeal.PostgreSQL.LTree | |
(TypeError ('Text "LTxtQuery binary instances not yet implemented.") :: Constraint) => ToPG db LTxtQuery Source # | |
Defined in Squeal.PostgreSQL.LTree | |
type Rep LTxtQuery Source # | |
Defined in Squeal.PostgreSQL.LTree | |
type PG LTxtQuery Source # | |
Defined in Squeal.PostgreSQL.LTree |
type PGltree = 'UnsafePGType "ltree" Source #
Postgres ltree type
type PGlquery = 'UnsafePGType "lquery" Source #
Postgres lquery type
type PGltxtquery = 'UnsafePGType "ltxtquery" Source #
Postgres ltxtquery type
ltree :: TypeExpression db (null PGltree) Source #
Postgres ltree type expression
lquery :: TypeExpression db (null PGlquery) Source #
Postgres lquery type expression
ltxtquery :: TypeExpression db (null PGltxtquery) Source #
Postgres ltxtquery type expression
Functions
subltree :: '[null PGltree, null 'PGint4, null 'PGint4] ---> null PGltree Source #
Returns subpath of ltree from position start to position end-1 (counting from 0).
subpath :: '[null PGltree, null 'PGint4, null 'PGint4] ---> null PGltree Source #
Returns subpath of ltree starting at position offset, with length len. If offset is negative, subpath starts that far from the end of the path. If len is negative, leaves that many labels off the end of the path.
subpathEnd :: '[null PGltree, null 'PGint4] ---> null PGltree Source #
Returns subpath of ltree starting at position offset, extending to end of path. If offset is negative, subpath starts that far from the end of the path.
indexLTree :: '[null PGltree, null PGltree] ---> null 'PGint4 Source #
Returns position of first occurrence of b in a, or -1 if not found.
indexOffset :: '[null PGltree, null PGltree, null 'PGint4] ---> null 'PGint4 Source #
Returns position of first occurrence of b in a, or -1 if not found. The search starts at position offset; negative offset means start -offset labels from the end of the path.
lca :: null ('PGvararray ('NotNull PGltree)) --> null PGltree Source #
Computes longest common ancestor of paths in array.
Operators
(%~) :: Operator (null0 PGltree) (null1 PGlquery) ('Null 'PGbool) infix 4 Source #
Does ltree match lquery?
(~%) :: Operator (null1 PGlquery) (null0 PGltree) ('Null 'PGbool) infix 4 Source #
Does ltree match lquery?
(%?) :: Operator (null0 PGltree) (null1 ('PGvararray ('NotNull PGlquery))) ('Null 'PGbool) infix 4 Source #
Does ltree match any lquery in array?
(?%) :: Operator (null0 ('PGvararray ('NotNull PGlquery))) (null1 PGltree) ('Null 'PGbool) infix 4 Source #
Does ltree match any lquery in array?
(%@) :: Operator (null0 PGltree) (null1 PGltxtquery) ('Null 'PGbool) infix 4 Source #
Does ltree match ltxtquery?
(@%) :: Operator (null0 PGltxtquery) (null1 PGltree) ('Null 'PGbool) infix 4 Source #
Does ltree match ltxtquery?
(@>%) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGltree) ('Null 'PGbool) infix 4 Source #
Does array contain an ancestor of ltree?
(%<@) :: Operator (null0 PGltree) (null1 ('PGvararray ('NotNull PGltree))) ('Null 'PGbool) infix 4 Source #
Does array contain an ancestor of ltree?
(<@%) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGltree) ('Null 'PGbool) infix 4 Source #
Does array contain a descendant of ltree?
(%@>) :: Operator (null0 PGltree) (null1 ('PGvararray ('NotNull PGltree))) ('Null 'PGbool) infix 4 Source #
Does array contain a descendant of ltree?
(&~) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGlquery) ('Null 'PGbool) infix 4 Source #
Does array contain any path matching lquery?
(~&) :: Operator (null0 PGlquery) (null1 ('PGvararray ('NotNull PGltree))) ('Null 'PGbool) infix 4 Source #
Does array contain any path matching lquery?
(&?) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 ('PGvararray ('NotNull PGlquery))) ('Null 'PGbool) infix 4 Source #
Does ltree array contain any path matching any lquery?
(?&) :: Operator (null0 ('PGvararray ('NotNull PGlquery))) (null1 ('PGvararray ('NotNull PGltree))) ('Null 'PGbool) infix 4 Source #
Does ltree array contain any path matching any lquery?
(&@) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGltxtquery) ('Null 'PGbool) infix 4 Source #
Does array contain any path matching ltxtquery?
(@&) :: Operator (null0 PGltxtquery) (null1 ('PGvararray ('NotNull PGltree))) ('Null 'PGbool) infix 4 Source #
Does array contain any path matching ltxtquery?
(?@>) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGltree) ('Null PGltree) infix 4 Source #
Returns first array entry that is an ancestor of ltree, or NULL if none.
(?<@) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGltree) ('Null PGltree) infix 4 Source #
Returns first array entry that is a descendant of ltree, or NULL if none.
(?~) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGlquery) ('Null PGltree) infix 4 Source #
Returns first array entry that matches lquery, or NULL if none.
(?@) :: Operator (null0 ('PGvararray ('NotNull PGltree))) (null1 PGltxtquery) ('Null PGltree) infix 4 Source #
Returns first array entry that matches ltxtquery, or NULL if none.
Orphan instances
PGSubset PGltree Source # |
|
PGTyped db PGlquery Source # | |
PGTyped db PGltree Source # | |
PGTyped db PGltxtquery Source # | |
pgtype :: forall (null :: PGType -> NullType). TypeExpression db (null PGltxtquery) # | |
OidOf db PGlquery Source # | |
OidOf db PGltree Source # | |
OidOf db PGltxtquery Source # | |
OidOfArray db PGlquery Source # | |
oidOfArray :: ReaderT (K Connection db) IO Oid # | |
OidOfArray db PGltree Source # | |
oidOfArray :: ReaderT (K Connection db) IO Oid # | |
OidOfArray db PGltxtquery Source # | |
oidOfArray :: ReaderT (K Connection db) IO Oid # | |
IsString (Expression grp lat with db params from (null PGlquery)) Source # | |
fromString :: String -> Expression grp lat with db params from (null PGlquery) # | |
IsString (Expression grp lat with db params from (null PGltree)) Source # | |
fromString :: String -> Expression grp lat with db params from (null PGltree) # | |
IsString (Expression grp lat with db params from (null PGltxtquery)) Source # | |
fromString :: String -> Expression grp lat with db params from (null PGltxtquery) # | |
Monoid (Expression grp lat with db params from (null PGltree)) Source # | |
mempty :: Expression grp lat with db params from (null PGltree) # mappend :: Expression grp lat with db params from (null PGltree) -> Expression grp lat with db params from (null PGltree) -> Expression grp lat with db params from (null PGltree) # mconcat :: [Expression grp lat with db params from (null PGltree)] -> Expression grp lat with db params from (null PGltree) # | |
Semigroup (Expression grp lat with db params from (null PGltree)) Source # |
|
(<>) :: Expression grp lat with db params from (null PGltree) -> Expression grp lat with db params from (null PGltree) -> Expression grp lat with db params from (null PGltree) # sconcat :: NonEmpty (Expression grp lat with db params from (null PGltree)) -> Expression grp lat with db params from (null PGltree) # stimes :: Integral b => b -> Expression grp lat with db params from (null PGltree) -> Expression grp lat with db params from (null PGltree) # |