postgresql-ltree-0.0.0.0: Types and functions for representing PostgreSQL's ltree
Safe HaskellNone
LanguageHaskell2010

Database.PostgreSQL.LTree

Description

This module provides types and functions for PostgreSQL's ltree https://www.postgresql.org/docs/current/ltree.html

You will want to use a specific implementation, e.g. postgresql-simple-ltree.

Synopsis

Documentation

newtype LTree Source #

Wrapper for Postgres' ltree (label tree) type.

Constructors

LTree 

Fields

Instances

Instances details
Eq LTree Source # 
Instance details

Defined in Database.PostgreSQL.LTree

Methods

(==) :: LTree -> LTree -> Bool #

(/=) :: LTree -> LTree -> Bool #

Ord LTree Source # 
Instance details

Defined in Database.PostgreSQL.LTree

Methods

compare :: LTree -> LTree -> Ordering #

(<) :: LTree -> LTree -> Bool #

(<=) :: LTree -> LTree -> Bool #

(>) :: LTree -> LTree -> Bool #

(>=) :: LTree -> LTree -> Bool #

max :: LTree -> LTree -> LTree #

min :: LTree -> LTree -> LTree #

Show LTree Source # 
Instance details

Defined in Database.PostgreSQL.LTree

Methods

showsPrec :: Int -> LTree -> ShowS #

show :: LTree -> String #

showList :: [LTree] -> ShowS #

ToJSON LTree Source # 
Instance details

Defined in Database.PostgreSQL.LTree

FromJSON LTree Source # 
Instance details

Defined in Database.PostgreSQL.LTree

data Label Source #

Wrapper for a single label in an ltree. The constructor IS NOT exported to ensure we only construct valid labels. See mkLabel for constructing a Label.

Instances

Instances details
Eq Label Source # 
Instance details

Defined in Database.PostgreSQL.LTree

Methods

(==) :: Label -> Label -> Bool #

(/=) :: Label -> Label -> Bool #

Ord Label Source # 
Instance details

Defined in Database.PostgreSQL.LTree

Methods

compare :: Label -> Label -> Ordering #

(<) :: Label -> Label -> Bool #

(<=) :: Label -> Label -> Bool #

(>) :: Label -> Label -> Bool #

(>=) :: Label -> Label -> Bool #

max :: Label -> Label -> Label #

min :: Label -> Label -> Label #

Show Label Source # 
Instance details

Defined in Database.PostgreSQL.LTree

Methods

showsPrec :: Int -> Label -> ShowS #

show :: Label -> String #

showList :: [Label] -> ShowS #

ToJSON Label Source # 
Instance details

Defined in Database.PostgreSQL.LTree

FromJSON Label Source # 
Instance details

Defined in Database.PostgreSQL.LTree

map :: (Label -> Label) -> LTree -> LTree Source #

Produce a new LTree by applying the supplied function to each Label.

fromList :: [Label] -> LTree Source #

Convert a list to an LTree.

toList :: LTree -> [Label] Source #

Convert an LTree to a list.

rootLabel :: LTree -> Maybe Label Source #

Get the first Label from an LTree if one exists.

parentLabel :: LTree -> Maybe Label Source #

Get the second-to-last Label in an LTree.

parent :: LTree -> Maybe LTree Source #

Get the parent path of an LTree.

numLabels :: LTree -> Int Source #

Get the length of an LTree.

mkLabel :: Text -> Either String Label Source #

Safely construct a Label from Text. If the supplied Text contains characters unsupported by ltree. On failure, returns Left with an error message.

unsafeMkLabel :: Text -> Label Source #

Same as mkLabel except throws an error for an invalid Text input.

uuidToLabel :: UUID -> Label Source #

A UUID can always be converted into a Label without error by dropping the hyphens. The resulting Label will only contain numbers and lower-case alpha characters.

empty :: LTree Source #

An empty LTree.

null :: LTree -> Bool Source #

Test whether an LTree is empty.

singleton :: Label -> LTree Source #

Construct an LTree from a single Label.

snoc :: LTree -> Label -> LTree Source #

Append a single Label to the end of an LTree; should be O(1) since it's delegating to |>

render :: LTree -> Text Source #

Render an ltree as it would appear in the database.

unsafeUncheckedParse :: Text -> LTree Source #

Unsafely parse an LTree from Text assuming each Label is valid. Use this only if you sure the input is a valid LTree; e.g. it was fetched from a field the database of type ltree.

parse :: Text -> Either String LTree Source #

Parse an LTree from Text. If any Label present is invalid, returns Left.

isImmediateParentOf :: LTree -> LTree -> Bool Source #

Test whether the first LTree is an immediate parent of the second; e.g. a.b is an immediate parent of a.b.c

isImmediateChildOf :: LTree -> LTree -> Bool Source #

Test whether the first LTree is an immediate child of the second; e.g. a.b.c is an immediate child of a.b

parseUUIDFromLabel :: Label -> Either String UUID Source #

Attempt to parse a UUID from a Label.

allLabelsUnique :: LTree -> Bool Source #

Test whether all labels in the LTree are unique.