[Dbix-class] rfc - how best to do design sorting, collations, etc

Matt S Trout dbix-class at trout.me.uk
Sat Feb 23 20:07:40 GMT 2008


On Tue, Feb 19, 2008 at 08:38:05PM -0800, Darren Duncan wrote:
> Hello,
> 
> In my work on designing the Muldis D language, one of the biggest 
> unresolved design problems I'm having is working out features that 
> involve sorting a set of values for various reasons, including 
> implementing ordered output of database queries, or implementing 
> '<'|'>' operators, or min|max|between operators, or implementing 
> quota queries or windowed queries.
> 
> I'm looking for some input on how I might best proceed with getting 
> these working.
> 
> The design needs to have semantics explicitly designed enough that 
> the features provide the range of actual features or behaviours that 
> people want to use with a database, that are highly deterministic 
> while being highly portable, so its easy to predict what any request 
> would give you and have that be the same in any implementation, and 
> that is easy to translate both ways semantics intact between Muldis D 
> and various SQL dialects and various normal programming languages 
> like Perl et al, and that is easy to use.
> 
> In various SQL dialects, it is common practice that when you want to 
> sort a rowset deterministically, you use an ORDER BY clause that 
> lists which columns (stored or computed) of the rowset whose values 
> you are sorting the rows on, and their order of precedence when some 
> column values compare as equal and others inequal.  This has the 
> advantage of being very terse and generally polymorphic but it 
> requires that the type of the column's values has some built-in 
> sorting method to automatically use.
> 
> In Perl in the generic case, you sort a list by saying eg "sort { 
> <binary-order-compare-expr> } @rowset", and the expression would 
> explicitly invoke whatever behaviour-specific operators you want; 
> this gives you the most control, but it is more verbose and 
> potentially less polymorphic.

But you don't -have- to pass anything and by default perl uses 'cmp', which
can be overloaded by objects to provide an alternative default collation
order.

The SQL 'ORDER BY foo' is much the same thing in that it uses whatever
foo's collation order is.

So I don't really see that this is an either-or choice.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list