Skip to content

Instantly share code, notes, and snippets.

Created July 30, 2010 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/501078 to your computer and use it in GitHub Desktop.
Save anonymous/501078 to your computer and use it in GitHub Desktop.
class Select {
has $.from;
has @!columns;
# We want to be able to chain method calls
method select(@!columns) { self }
method Str {
"SELECT @!columns.map(*.name).join(', ') FROM $!from.name()";
}
}
class Table {
has @!columns;
has $.name;
method add_columns (*@columns) { @!columns = @columns }
multi method select($foo) {
my Select $select .= new;
return $select.from(self).select(@!columns);
}
multi method select(*@columns) { }
}
class Column {
has Str $.name;
}
use Test;
plan *;
my Table $person = Table.new(name => 'person');
$person.add_columns(
Column.new( name => 'name' ),
);
my Select $select = $person.select(*);
is(~$select, 'SELECT name FROM person', 'basic SELECT statement');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment