Created
July 30, 2010 18:32
-
-
Save anonymous/501078 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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