Module

Droplet.Language

Package
purescript-droplet
Repository
easafe/purescript-droplet

Query language

#spyQuery Source

spyQuery :: forall q projection. ToQuery q projection => q -> { parameters :: Array Foreign, plan :: Maybe Plan, query :: String }

Debug generated query

Re-exports from Droplet.Language.Internal.Condition

#Op Source

data Op b c

Wrapper for comparisons

Instances

#Not Source

data Not

Instances

#In Source

data In

Instances

#Exists Source

data Exists

Instances

#or Source

or :: forall a b c d. Op a b -> Op c d -> Op (Op a b) (Op c d)

#notEquals Source

notEquals :: forall compared field. field -> compared -> Op field compared

#not Source

not :: forall compared field. Op field compared -> Op Not (Op field compared)

#lesserThan Source

lesserThan :: forall compared field. field -> compared -> Op field compared

#isNotNull Source

isNotNull :: forall field. field -> Op IsNotNull field

#in_ Source

in_ :: forall compared field. field -> compared -> Op In (Op field compared)

#greaterThan Source

greaterThan :: forall compared field. field -> compared -> Op field compared

#equals Source

equals :: forall field other. field -> other -> Op field other

#and Source

and :: forall a b c d. Op a b -> Op c d -> Op (Op a b) (Op c d)

#(.||.) Source

Operator alias for Droplet.Language.Internal.Condition.or (left-associative / precedence 2)

#(.>.) Source

Operator alias for Droplet.Language.Internal.Condition.greaterThan (non-associative / precedence 4)

#(.=.) Source

Operator alias for Droplet.Language.Internal.Condition.equals (non-associative / precedence 4)

#(.<>.) Source

Operator alias for Droplet.Language.Internal.Condition.notEquals (non-associative / precedence 4)

#(.<.) Source

Operator alias for Droplet.Language.Internal.Condition.lesserThan (non-associative / precedence 4)

#(.&&.) Source

Operator alias for Droplet.Language.Internal.Condition.and (left-associative / precedence 3)

Re-exports from Droplet.Language.Internal.Definition

#Unique Source

data Unique

#Table Source

data Table :: Symbol -> Row Type -> Typedata Table (name :: Symbol) (fields :: Row Type)

Constructors

#Star Source

data Star

Constructors

#PrimaryKey Source

#Path Source

data Path :: Symbol -> Symbol -> Typedata Path (alias :: Symbol) (field :: Symbol)

Qualified columns (e.g, table.column)

#Identity Source

data Identity

GENERATED ALWAYS AS IDENTITY constraint

#ForeignKey Source

data ForeignKey :: Symbol -> Type -> Typedata ForeignKey (field :: Symbol) (table :: Type)

#E Source

data E

Marks the query end

#Default Source

data Default

Constructors

Instances

#Constraint Source

data Constraint :: forall n. n -> Type -> Typedata Constraint name t

#Composite Source

data Composite :: Symbol -> Typedata Composite (name :: Symbol)

#Column Source

data Column (t :: Type) (constraint :: Type)

Constructors

Instances

#ToParameters Source

class ToParameters :: Row Type -> RowList Type -> Constraintclass ToParameters record (list :: RowList Type) 

Instances

#ToType Source

class ToType (t :: Type)  where

String representation of field types

Members

Instances

#ToValue Source

class ToValue v  where

Converts a PureScript value into Postgres

Members

Instances

#(...) Source

Operator alias for Droplet.Language.Internal.Definition.path (non-associative / precedence 7)

Re-exports from Droplet.Language.Internal.Function

#FunctionSignature' Source

type FunctionSignature' output = forall fields. PgFunction Void Unit fields output

#FunctionSignature Source

type FunctionSignature input output = forall args fields. MatchArgumentList input args fields => args -> PgFunction input args fields output

#Aggregate Source

data Aggregate :: Type -> Type -> Row Type -> Type -> Typedata Aggregate input rest (fields :: Row Type) (output :: Type)

Built-in aggregate functions

#string_agg Source

string_agg :: forall f rest fields. ToStringAgg f rest fields => f -> rest -> Aggregate f rest fields (Maybe String)

#function' Source

function' :: forall output. String -> FunctionSignature' output

Represents a function that takes no arguments

#function Source

function :: forall input output. String -> FunctionSignature input output

Represents a function that takes arguments

#count Source

count :: forall f fields. ToCount f fields => f -> Aggregate f E fields BigInt

#coalesce Source

coalesce :: forall input output fields. ToCoalesce input fields output => input -> PgFunction input input fields (Maybe output)

Re-exports from Droplet.Language.Internal.Syntax

#Where Source

data Where c rest

Instances

#Values Source

data Values fieldValues rest

Instances

#Update Source

newtype Update :: Symbol -> Row Type -> Type -> Typenewtype Update (name :: Symbol) (fields :: Row Type) rest

Instances

#Union Source

data Union q r

Instances

#T Source

newtype T (t :: Type) rest

Helper data type for extending TABLE syntax

#Set Source

data Set pairs rest

Instances

#Select Source

data Select :: Type -> Row Type -> Type -> Typedata Select s (projection :: Row Type) rest

SELECT representation. projection refers to the final output of this statement

Instances

#Returning Source

newtype Returning f

#Prepare Source

data Prepare q

#Plan Source

newtype Plan

Name of this prepared statement

#Outer Source

data Outer :: Sidedata Outer

Instances

#OrderBy Source

data OrderBy f rest

Instances

#On Source

data On c rest

Instances

#Offset Source

data Offset rest

Instances

#Limit Source

data Limit :: Int -> Type -> Typedata Limit (n :: Int) rest

Instances

#Join Source

data Join :: Side -> Row Type -> Type -> Type -> RowList Symbol -> Type -> Typedata Join (k :: Side) (fields :: Row Type) q r (aliases :: SymbolList) rest

Instances

#Into Source

data Into :: Symbol -> Row Type -> Type -> Type -> Typedata Into (name :: Symbol) (fields :: Row Type) fieldNames rest

Instances

#Insert Source

newtype Insert rest

Instances

#Inner Source

data Inner :: Sidedata Inner

Instances

#From Source

data From :: Type -> Row Type -> Type -> Typedata From f (fields :: Row Type) rest

Instances

#Drop Source

newtype Drop rest

Instances

#Distinct Source

newtype Distinct s

Instances

#Delete Source

newtype Delete rest

Instances

#DefaultValues Source

data DefaultValues

Instances

#Create Source

newtype Create rest

Instances

#As Source

newtype As :: Symbol -> Type -> Typenewtype As (alias :: Symbol) rest

Instances

#Alter Source

newtype Alter rest

Instances

#wher Source

wher :: forall c q sql. ToWhere c q => Resume q (Where c E) sql => c -> q -> sql

WHERE statement

#values Source

values :: forall tableName fields fieldNames fieldValues. InsertValues fields fieldNames fieldValues => fieldValues -> Insert (Into tableName fields fieldNames E) -> Insert (Into tableName fields fieldNames (Values fieldValues E))

#update Source

update :: forall name fields. Table name fields -> Update name fields E

#unionAll Source

unionAll :: forall q r. ToUnion q r => q -> r -> Union q r

#union Source

union :: forall q r. ToUnion q r => q -> r -> Union q r

#table Source

table :: forall name q fields sql. ToTable q (Table name fields) => Resume q (Table name fields) sql => Table name fields -> q -> sql

Table up for modification

#set Source

set :: forall name fields pairs. ToUpdatePairs fields pairs => pairs -> Update name fields E -> Update name fields (Set pairs E)

#select Source

select :: forall s projection. ToSelect s => s -> Select s projection E

SELECT can project literals, columns and subqueries with the following considerations:

  • Multiple columns are represented by tuples. Data.Tuple.Nested./\ is convenient for this
  • Literal values (e.g., numbers) must be aliased (with AS)
  • Columns names in projections must be unique, or referenced by different table aliases (e.g., u.name, t.name)
  • Subqueries must return a single column

#returning Source

returning :: forall f q sql. ToReturning f q => Resume q (Returning f) sql => f -> q -> sql

#prepare Source

prepare :: forall q. ToPrepare q => Plan -> q -> Prepare q

https://www.postgresql.org/docs/current/sql-prepare.html

PREPARE statements can be employed to reuse execution plans, and thus optimize performance

Note: droplet always creates server-side parameters for literal values in queries. In the case of PREPARE, however, literals will be be parsed as statement parameters

#orderBy Source

orderBy :: forall f q sql. ToOrderBy f q => Resume q (OrderBy f E) sql => f -> q -> sql

ORDER BY statement

#on Source

on :: forall k l r c fields aliases. OnCondition c fields aliases => c -> Join k fields l r aliases E -> Join k fields l r aliases (On c E)

JOIN ... ON statement

#offset Source

offset :: forall q sql. ToOffset q => Resume q (Offset E) sql => Int -> q -> sql

OFFSET statement

Note: OFFSET must always follow after LIMIT or ORDER BY

#limit Source

limit :: forall n q sql. ToLimit q => Resume q (Limit n E) sql => Proxy n -> q -> sql

LIMIT statement

Note: LIMIT must always follow after ORDER BY

#leftJoin Source

leftJoin :: forall r l las ras list out aliases unique rf lf right left all fields source. ToJoin l left las => ToJoin r right ras => UniqueSources left right => RowListAppend las ras aliases => RowListNub aliases unique => UniqueAliases aliases unique => Union left right all => Nub all source => Union left lf source => Union right rf source => RowToList lf list => ToOuterColumns list out => Union rf out fields => l -> r -> Join Outer fields l r aliases E

LEFT OUTER JOIN statement

JOIN sources are the same as FROM

#join Source

join :: forall r l aliases unique las ras right rf lf left all source fields. ToJoin l left las => ToJoin r right ras => UniqueSources left right => RowListAppend las ras aliases => RowListNub aliases unique => UniqueAliases aliases unique => Union right left all => Nub all source => Union left lf source => Union right rf source => Union lf rf fields => l -> r -> Join Inner fields l r aliases E

INNER JOIN statement

JOIN sources are the same as FROM

#into Source

into :: forall tableName fields fieldNames fieldList required inserted. RowToList fields fieldList => RequiredColumns fieldList required => InsertList fields fieldNames inserted => MissingRequiredColumns required inserted => Table tableName fields -> fieldNames -> Insert E -> Insert (Into tableName fields fieldNames E)

#groupBy Source

groupBy :: forall f s q sql grouped columns. ToGroupBy q s columns => GroupedColumns f columns grouped => ValidGroupByProjection s grouped => Resume q (GroupBy f E) sql => f -> q -> sql

GROUP BY statement

#from Source

from :: forall f q fields sql. ToFrom f q fields => Resume q (From f fields E) sql => f -> q -> sql

FROM accepts the following sources

  • Tables
  • Inner and outer joins
  • Aliased tables
  • Aliased SELECT statements

Due to how SQL binding works, joins and subqueries require brackets to be parsed correctly. For example:

  • SELECT column FROM (SELECT column FROM table) AS alias should be select column # from (select column # from table # as alias))
  • SELECT column FROM table alias JOIN other_table other_alias should be select column # from ((table # as alias)join(other_table # as other_alias)))

To aid composition, SELECT projections are only validated on FROM

#exists Source

exists :: forall s projection f fields rest. Select s projection (From f fields rest) -> Op Exists (Select s projection (From f fields rest))

#drop Source

drop :: Drop E

DROP ...

#distinct Source

distinct :: forall s. ToSelect s => s -> Distinct s

#desc Source

desc :: forall name. name -> Sort name

DESC

#create Source

create :: Create E

CREATE ...

#asc Source

asc :: forall name. name -> Sort name

ASC

#as Source

as :: forall q alias sql. ToAs q alias => Resume q (As alias E) sql => Proxy alias -> q -> sql

AS statement

#add Source

add :: forall q name object columns extended. ToAdd q => Cons object q columns extended => TableChecks (Table name extended) => Proxy object -> q -> Alter (Table name columns) -> Alter (T (Table name columns) (Add object q))