Skip to content

Instantly share code, notes, and snippets.

View rjattrill's full-sized avatar

Ross Attrill rjattrill

View GitHub Profile

Abstract

DBIx::DataModel (DBIDM) is a light and powerful framework that simplifies interactions with relational databases. DBIDM makes simple database interactions easy and complex interactions possible - all using Perl.

In February I described three key advantages of DBIDM and in this article I will describe three more being:

  • a small but discerning list of CPAN dependencies
  • more efficient than raw SQL for joins
  • a design philosophy that 'less is more' - bringing out the strengths of Perl and DBI
@rjattrill
rjattrill / UnitTestTemplate.t
Last active December 15, 2015 12:29
Unit Test Template
use Test::More;
use v5.10;
use Carp;
use Try::Tiny;
use Data::Dumper;
use FindBin qw($Bin);
use FindBin::libs;
our $username = 'unit_test';
@rjattrill
rjattrill / SortArrayCollection.as
Last active December 14, 2015 22:38
Sort an ArrayCollection
// Sort by taskItemId
var dataSortField:SortField = new SortField();
dataSortField.name = "taskItemId";
dataSortField.numeric = true;
dataSortField.reverse();
var numericDataSort:Sort = new Sort();
numericDataSort.fields = [dataSortField];
this.taskItemAc.sort = numericDataSort;
this.taskItemAc.refresh();
@rjattrill
rjattrill / SmallButton.mxml
Last active December 13, 2015 17:48
Really small spark button
<s:Button id="smallBtn" right="5" top="5" width="10" height="10"
click="smallBtn_clickHandler(event)"
cornerRadius="0"/>
my $lr = $dao->schema->join(qw/Parent grandparent/)->select(-where => {active => 1});
foreach my $p (@$lr) {
$p->expand('child', -where => {active => 1});
}
@rjattrill
rjattrill / DBIDM_ExpandWithCriteria.pl
Created February 13, 2013 04:48
Expand with criteria in DBIDM
my $lr = $dao->schema->join(qw/ProcessExecution process domain/)->select(%where);
foreach my $pe (@$lr) {
$pe->expand('process');
my $label = "Domain: " . $pe->{domain} . "\t\tProcess: " . $pe->{process} . "\t\tOperation Date: " . $pe->{operation_date};
$pe->{label} = $label;
if ($tree gt 1) {
$pe->expand('task_actions', -where => {deactivated => undef});
if ($tree gt 2) {
foreach my $ta (@{$pe->{task_actions}}) {
@rjattrill
rjattrill / AliasedJoinsInDBIDM.pl
Created February 8, 2013 06:10
Alias joins in select using DBIx::DataModel
$schema ->join(qw/Department|dpt activities|act employee|emp/)
->select( -columns => qw/dpt.name act.d_begin emp.lastname/,
-where => {"dpt.dpt_name" => {-like => "A%"}});
@rjattrill
rjattrill / FormatNumberInTextField.mxml
Created February 8, 2013 01:37
Format number for display in a Spark TextInput, Label or similar.
<s:TextInput id="defaultValueTextInput" text="{isNaN(taskParam.valueNum) ? '' : taskParam.valueNum.toString()} "/>
@rjattrill
rjattrill / Perl.sublime-build
Last active December 12, 2015 07:09
Configuring Sublime Text build for Perl and Ruby. Also configured to use exec-in-window package.
{
"cmd": ["perl", "-w", "$file"],
"file_regex": ".* at (.*) line ([0-9]*)",
// Build target is exec-in-window package
"target": "exec_in_window",
"working_dir": "${project_path}",
"selector": "source.perl"
}
@rjattrill
rjattrill / DataGridFormatNumbers.mxml
Last active December 10, 2015 23:18
Format numbers in Spark DataGrid
<fx:Script><![CDATA[
import spark.formatters.NumberFormatter;
var numberFormatter:NumberFormatter = new NumberFormatter();
private function numberFormat(item:Object, column:GridColumn):String {
return numberFormatter.format(item [column.dataField]);
}
]]>
</fx:Script>
<s:GridColumn dataField="valueNum" headerText="Value" labelFunction="numberFormat">