You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks to William Yao and Cullin Poresky for their contributions!
Prepared Statements
Squeal 0.9 adds a new Prepared type for prepared statements.
dataPreparedmxy=Prepared{runPrepared::x->my--^ execute a prepared statement
, deallocate::m()--^ manually clean up a prepared statement}
This allows to factor and generalize the functions executePrepared
and executePrepared_. Squeal 0.9 adds new methods prepare and prepare_ to the MonadPQ typeclass.
They may then be run using runPrepared and manually cleaned up
using deallocate. The Prepared type has a cornucopia of instances
allowing you to combine prepared statements in lots of ways. Instances Prepared supports include Category, Arrow, Profunctor and more.
A function preparedFor abstracts the pattern of preparing a statement,
then doing something with it and finally deallocating. That something
can be thought of as an "optic", a generalization of lenses.
preparedFor
::MonadPQdbpq=> (Preparedpqa (Resultb) ->Preparedpqst)
--^ transform the input and output using an "optic"->Statementdbab--^ query or manipulation->s->pqt
For instance, using the optic traverse' recovers the function executePrepared and using the optic wander traverse_ recovers the
function executePrepared_, which are used for running prepared statements
over Traversable or Foldable containers of parameters respectively.
With the generalized notion of a Prepared object, you can prepare statments
and optionally combine them at the beginning of a database session and
have a Prepared object to use with runPrepared throughout the session.
This is a lower level primitive and closer to the model that PostgreSQL
actually provides than what Squeal previously allowed.
Row and Enum Types
Squeal 0.9 adds a number of new features for row and enum types.
First, new type families DbRelations and DbEnums have been added,
which filter a SchemasType down to all row or enum types.
A relation means a table, view or composite type;
other kinds of relations are not currently supported. Previously,
Squeal's support for row types only covered composite types but
Squeal 0.9 adds more support for tables and views. New TypeExpressions typerow and typeenum have been added. A new type family FindQualified,
which looks through database schemas to find a row or enum type has been added.
Squeal will now look through all tables, views and composite types when
trying to find a user-defined relation to match your row type where previously
it had only looked for composites.
Next, new functions have been added to allow users to define manual encodings
for row and enum types. Previously, Squeal only had functions to allow users to
define manual decodings for row and enum types. For enum types,
you can now use enumParam like so:
Since it is polykinded, the tys parameter can have either
the kind [NullType] or the kind RowType.
Other Changes
Squeal 0.9 adds support for GHC 9, which required fully saturating
a number of functions that involved RankNTypes, a change
required by the "simplified subsumption" proposal.
A bug for Has custom type errors, which made it expensive
in the case of a lookup failure because of use of the strict If
type family, has been fixed, thanks to Cullin.
Missing images and some small fixes were added for the Squeal
"Core Concepts Handbook", thanks to William.
CI has been fixed to properly test across different versions of GHC.
The function notNull which has a non-intuitive name has been
deprecated and a replacement function just_ has been added. The
terms null_ and just_ now intentionally connote Nothing and Just from Haskell's Maybe type.
The operators (.<@) and (@>.) as well as the functions arrAny
and arrAll have been generalized to allow Null arguments. Previously,
they had been improperly restricted to have NotNull arguments.
PQ has been given MonadFix, Alternative and MonadPlus instances.
This discussion was created from the release 0.9.0.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Version 0.9.0.0
Thanks to William Yao and Cullin Poresky for their contributions!
Prepared Statements
Squeal 0.9 adds a new
Prepared
type for prepared statements.This allows to factor and generalize the functions
executePrepared
and
executePrepared_
. Squeal 0.9 adds new methodsprepare
andprepare_
to theMonadPQ
typeclass.They may then be run using
runPrepared
and manually cleaned upusing
deallocate
. ThePrepared
type has a cornucopia of instancesallowing you to combine prepared statements in lots of ways. Instances
Prepared
supports includeCategory
,Arrow
,Profunctor
and more.A function
preparedFor
abstracts the pattern of preparing a statement,then doing something with it and finally deallocating. That something
can be thought of as an "optic", a generalization of lenses.
For instance, using the optic
traverse'
recovers the functionexecutePrepared
and using the opticwander traverse_
recovers thefunction
executePrepared_
, which are used for running prepared statementsover
Traversable
orFoldable
containers of parameters respectively.With the generalized notion of a
Prepared
object, you can prepare statmentsand optionally combine them at the beginning of a database session and
have a
Prepared
object to use withrunPrepared
throughout the session.This is a lower level primitive and closer to the model that PostgreSQL
actually provides than what Squeal previously allowed.
Row and Enum Types
Squeal 0.9 adds a number of new features for row and enum types.
First, new type families
DbRelations
andDbEnums
have been added,which filter a
SchemasType
down to all row or enum types.A relation means a table, view or composite type;
other kinds of relations are not currently supported. Previously,
Squeal's support for row types only covered composite types but
Squeal 0.9 adds more support for tables and views. New
TypeExpression
styperow
andtypeenum
have been added. A new type familyFindQualified
,which looks through database schemas to find a row or enum type has been added.
Squeal will now look through all tables, views and composite types when
trying to find a user-defined relation to match your row type where previously
it had only looked for composites.
Next, new functions have been added to allow users to define manual encodings
for row and enum types. Previously, Squeal only had functions to allow users to
define manual decodings for row and enum types. For enum types,
you can now use
enumParam
like so:For row types you can now use
rowParam
together with new combinators.#
to cons and#.
to end the row like so:There is also a function
genericRowParams
, which canbe used with combinators like so:
All of this is made possible by generalizing the
EncodeParams
type to polykinded:
Since it is polykinded, the
tys
parameter can have eitherthe kind
[NullType]
or the kindRowType
.Other Changes
Squeal 0.9 adds support for GHC 9, which required fully saturating
a number of functions that involved
RankNTypes
, a changerequired by the "simplified subsumption" proposal.
A bug for
Has
custom type errors, which made it expensivein the case of a lookup failure because of use of the strict
If
type family, has been fixed, thanks to Cullin.
Missing images and some small fixes were added for the Squeal
"Core Concepts Handbook", thanks to William.
CI has been fixed to properly test across different versions of GHC.
The function
notNull
which has a non-intuitive name has beendeprecated and a replacement function
just_
has been added. Theterms
null_
andjust_
now intentionally connoteNothing
andJust
from Haskell'sMaybe
type.The operators
(.<@)
and(@>.)
as well as the functionsarrAny
and
arrAll
have been generalized to allowNull
arguments. Previously,they had been improperly restricted to have
NotNull
arguments.PQ
has been givenMonadFix
,Alternative
andMonadPlus
instances.This discussion was created from the release 0.9.0.
Beta Was this translation helpful? Give feedback.
All reactions