NAME

SQL::Abstract::Plugin::CaseExpr - Case Expression support for SQLA2!

SYNOPSIS

# pass this to anything that SQLA will render
# arrayref b/c order matters
{ -case => [
  # if/then is a bit more familiar than WHEN/THEN
  {
    if   => { sales => { '>' => 9000 } },
    # scalars default to bind params
    then => 'Scouter Breaking'
  },
  {
    if   => { sales => { '>' => 0 } },
    then => 'At least something'
  },
  # if the final node does not contain if, it's the ELSE clause
  'How did this happen?'
]}
# CASE WHEN sales > 9000 THEN ? WHEN sales > 0 THEN ? ELSE ? END
# [ 'Scouter Breaking', 'At least something', 'How did this happen?' ]

DESCRIPTION

This is a work in progress to support CASE expressions in SQLA2

EXPERIMENTAL

Using with DBIx::Class

In order to use this with DBIx::Class, you simply need to apply the DBIC-SQLA2 plugin, and then your SQLMaker will support this syntax!

New Syntax

-case node

The entry point for the new handling is the -case node. This takes an arrayref of hashrefs which represent the branches of the conditional tree, and optionally a final entry as the default clause.

The hashrefs must have the following two keys:

if

The condition to be checked against. It is processed like a WHERE clause.

then

The value to be returned if this condition is true. Scalars here default to -value, which means they are taken as bind parameters