Permalink
Browse files

[Squerl] more tests, more implementation

  • Loading branch information...
1 parent 319cc6a commit bc612a22f370f8622dbbf2d403a419f93818a5a7 @masak committed Sep 16, 2009
Showing with 27 additions and 6 deletions.
  1. +10 −5 lib/Squerl.pm
  2. +3 −1 t/squerl/{sqlite-write.t → 01-sqlite-write.t}
  3. +14 −0 t/squerl/02-dataset.t
View
@@ -1,20 +1,25 @@
use SQLite3;
class Squerl::Dataset {
- has $!db;
- has $!table;
+ has $.db;
+ has %.opts;
+
+ multi method new($db, *%opts) {
+ return self.bless(self.CREATE(), :$db, :%opts);
+ }
method insert(*@values) {
my $values = @values>>.perl.join(', ');
given $!db {
.open;
- .exec("INSERT INTO $!table VALUES($values)");
+ # RAKUDO: Real string interpolation
+ .exec("INSERT INTO {%!opts<table>} VALUES($values)");
.close;
}
}
method all() {
- $!db.select("*", $!table);
+ $!db.select("*", %!opts<table>);
}
}
@@ -67,7 +72,7 @@ class Squerl::Database {
}
method from($table) {
- return Squerl::Dataset.new(:db(self), :$table);
+ return Squerl::Dataset.new(self, :$table);
}
}
@@ -3,7 +3,7 @@ use Test;
use Squerl;
-unlink (my $file = 't/squirrel/posts.db');
+unlink (my $file = 't/squerl/posts.db');
my $DB = Squerl.sqlite($file);
$DB.create_table: <posts
@@ -23,4 +23,6 @@ my $number-of-posts = +$posts.all;
is $number-of-posts, 1, 'could insert and then retrieve a row';
+done_testing;
+
unlink $file;
View
@@ -0,0 +1,14 @@
+use v6;
+use Test;
+
+use Squerl;
+
+my $dataset = Squerl::Dataset.new('db');
+
+{
+ my $db = 'db';
+ my %opts = :from<test>;
+ my $d = Squerl::Dataset.new($db, |%opts);
+ is $d.db, $db, 'attribtue .db was properly set';
+ is_deeply $d.opts, %opts, 'attribute .opts was properly set';
+}

0 comments on commit bc612a2

Please sign in to comment.