Permalink
Browse files

compatibility fixes for Rakudo Star 2012.02, reformatted readme with …

…syntax highlihting
  • Loading branch information...
1 parent 7d90c6e commit 38e43d9aaa931a80e003fe800fc17391f9dbc745 @bbkr bbkr committed Mar 1, 2012
Showing with 49 additions and 38 deletions.
  1. +36 −13 README.md
  2. +0 −12 changelog.txt
  3. +1 −1 lib/MongoDB.pm
  4. +3 −3 lib/MongoDB/Collection.pm
  5. +1 −1 lib/MongoDB/Connection.pm
  6. +4 −4 lib/MongoDB/Cursor.pm
  7. +2 −2 lib/MongoDB/DataBase.pm
  8. +2 −2 t/find.t
View
@@ -12,15 +12,18 @@ Let's see what it can do...
### Initialize
+```perl
use MongoDB;
my $connection = MongoDB::Connection.new( );
my $database = $connection.database( 'test' );
my $collection = $database.collection( 'perl_users' );
my $cursor;
+```
### Insert documents into collection
+```perl
my %document1 = {
'name' => 'Paweł Pabian',
'nick' => 'bbkr',
@@ -40,71 +43,85 @@ Let's see what it can do...
};
$collection.insert( %document1, %document2 );
+```
-Flags
+Flags:
-* _:continue_on_errror_ - Do not stop processing a bulk insert if one document fails.
+* `:continue_on_errror` - Do not stop processing a bulk insert if one document fails.
### Find documents inside collection
Find everything.
+```perl
my $cursor = $collection.find( );
while $cursor.fetch( ) -> %document {
%document.perl.say;
}
+````
Or narrow down using condition.
+```perl
$cursor = $collection.find( { 'nick' => 'bbkr' } );
$cursor.fetch( ).perl.say;
+```
-Options
+Options:
-* _number_to_return_ - Int - TODO doc
+* `number_to_return` - Int - TODO doc
-Flags
+Flags:
-* _:no_cursor_timeout_ - Do not time out idle cursor after an inactivity period.
+* `:no_cursor_timeout` - Do not time out idle cursor after an inactivity period.
### Update documents in collection
Update any document.
+```perl
$collection.update( { }, { '$set' => { 'company' => 'Implix' } } );
+```
Update specific document.
+```perl
$collection.update( { 'nick' => 'andee' }, { '$push' => { 'versions' => 6 } } );
+```
-Flags
+Flags:
-* _:upsert_ - Insert the supplied object into the collection if no matching document is found.
-* _:multi_update_ - Update all matching documents in the collection (only first matching document is updated by default).
+* `:upsert` - Insert the supplied object into the collection if no matching document is found.
+* `:multi_update` - Update all matching documents in the collection (only first matching document is updated by default).
### Remove documents from collection
Remove specific documents.
+```perl
$collection.remove( { 'nick' => 'bbkr' } );
+```
Remove all documents.
+```perl
$collection.remove( );
+```
-Flags
+Flags:
-* _:single_remove_ - Remove only the first matching document in the collection (all matching documents are removed by default).
+* `:single_remove` - Remove only the first matching document in the collection (all matching documents are removed by default).
## FLAGS
Flags are boolean values, false by default.
They can be used anywhere and in any order in methods.
+```perl
remove( { 'nick' => 'bbkr' }, :single_remove );
remove( :single_remove, { 'nick' => 'bbkr' } ); # same
remove( single_remove => True, { 'nick' => 'bbkr' } ); # same
-
+```
## FEATURE ROADMAP
@@ -123,9 +140,15 @@ List of things you may expect in nearest future.
* Lack of Num or Rat support, this is directly related to not yet specified pack/unpack in Perl6.
* Speed, protocol correctness and clear code are priorities for now.
+## CHANGELOG
+
+* 0.4 - compatibility fixes for Rakudo Star 2012.02
+* 0.3 - basic flags added to methods (upsert, multi_update, single_remove,...), kill support for cursor
+* 0.2- adapted to Rakudo NOM 2011.09+.
+* 0.1 - basic Proof-of-concept working on Rakudo 2011.07.
## CONTACT
You can find me (and many awesome people who helped me to develop this module)
-on irc.freenode.net #perl6 channel as __bbkr__.
+on irc.freenode.net #perl6 channel as **bbkr**.
View
@@ -1,12 +0,0 @@
-0.3
-
-* Basic flags added to methods (upsert, multi_update, single_remove,...)
-* Kill support for cursor.
-
-0.2
-
-* Adapted to Rakudo NOM 2011.09+.
-
-0.1
-
-* Basic Proof-of-concept working on Rakudo 2011.07.
View
@@ -1,4 +1,4 @@
-module MongoDB:ver<0.3>;
+module MongoDB:ver<0.4>;
use MongoDB::Wire;
@@ -8,14 +8,14 @@ has Str $.name is rw;
submethod BUILD ( :$database, Str :$name ) {
- $.database = $database;
+ $!database = $database;
# TODO validate name
- $.name = $name;
+ $!name = $name;
}
method insert (
- *@documents where { +@documents and [&&]@documents>>.isa( Hash ) },
+ *@documents where { +@documents and [&&]( @documents>>.isa( Hash ) ) },
Bool :$continue_on_error = False
) {
@@ -20,7 +20,7 @@ method database ( Str $name ) {
method send ( Buf $b, Bool $has_response ) {
- $!sock.send( [~]$b.list>>.chr );
+ $!sock.send( [~]( $b.list>>.chr ) );
# some calls do not expect response
return unless $has_response;
View
@@ -12,20 +12,20 @@ has @.documents is rw;
submethod BUILD ( :$collection, :%OP_REPLY ) {
- $.collection = $collection;
+ $!collection = $collection;
# assign cursorID
- $.id = %OP_REPLY{ 'cursor_id' };
+ $!id = %OP_REPLY{ 'cursor_id' };
# assign documents
- @.documents = %OP_REPLY{ 'documents' }.list;
+ @!documents = %OP_REPLY{ 'documents' }.list;
}
method fetch ( ) {
# there are no more documents in last response batch
# but there is next batch to fetch from database
- if not @.documents and [+]$.id.list {
+ if not @.documents and [+]( $.id.list ) {
# request next batch of documents
my %OP_REPLY = self.wire.OP_GETMORE( self );
View
@@ -7,10 +7,10 @@ has Str $.name is rw;
submethod BUILD ( :$connection, Str :$name ) {
- $.connection = $connection;
+ $!connection = $connection;
# TODO validate name
- $.name = $name;
+ $!name = $name;
}
method collection ( Str $name ) {
View
@@ -40,7 +40,7 @@ lives_ok {
$cursor.kill();
}, 'kill cursor';
-is ([+]$cursor.id.list), 0, 'cursor is killed';
+is ( [+]( $cursor.id.list ) ), 0, 'cursor is killed';
lives_ok
{
@@ -56,7 +56,7 @@ lives_ok {
$cursor = $collection.find( number_to_return => 1 )
}, 'initialize cursor for one document';
-is ([+]$cursor.id.list), 0, 'cursor for one document is closed automatically';
+is ( [+]( $cursor.id.list ) ), 0, 'cursor for one document is closed automatically';
lives_ok
{

0 comments on commit 38e43d9

Please sign in to comment.