[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[ANN] Mongoose 0.2.0

Jamey Cribbs

7/21/2006 4:49:00 PM

You can download it from: http://rubyforge.org/projects...

*What's New*

Thanks, to Ezra Zygmuntowicz, this release features a much cleaner query
language, so I decided to get this out before anyone gets too used to
the old version. Ezra pointed out how I could eliminate having to pass
the table's class as a block parameter to the query, and also eliminate
having to qualify every column name in the query with the table's
class. So, a query that looked like this:

Plane.find do |plane|
plane.speed > 350
plane.any do
plane.country == 'USA'
plane.country == 'Great Britain'
end
end

Now, looks like this:

Plane.find do
speed > 350
any do
country == 'USA'
country == 'Great Britain'
end
end

Much cleaner. Thanks Ezra!

Also, Ezra contributed a Table.create method and Logan Capaldo
contributed a fix to eliminate a string eval. There is a new example
script from Daniel Sheppard showing how to integrate ActiveRecord
validations into Mongoose. Plus the usual code cleanup and bug fixes.

*What is Mongoose?*

Mongoose is a database management system written in Ruby. It has an
ActiveRecord-like interface, uses Skiplists for its indexing, and
Marshal for its data serialization. I named it Mongoose, because, like
Rudyard Kipling's Rikki-Tikki-Tavi, my aim is for it to be small, quick,
and friendly.

You can find rudimentary documentation in the README file and some
sample scripts in the example directory.

Jamey Cribbs
jcribbs@netpromi.com

17 Answers

Logan Capaldo

7/21/2006 5:01:00 PM

0


On Jul 21, 2006, at 12:49 PM, Jamey Cribbs wrote:

> You can download it from: http://rubyforge.org/projects...
>
> *What's New*
>
> Thanks, to Ezra Zygmuntowicz, this release features a much cleaner
> query language, so I decided to get this out before anyone gets too
> used to the old version. Ezra pointed out how I could eliminate
> having to pass the table's class as a block parameter to the query,
> and also eliminate having to qualify every column name in the query
> with the table's class. So, a query that looked like this:
>
> Plane.find do |plane|
> plane.speed > 350
> plane.any do
> plane.country == 'USA' plane.country == 'Great Britain'
> end
> end
>
> Now, looks like this:
>
> Plane.find do
> speed > 350
> any do
> country == 'USA'
> country == 'Great Britain'
> end
> end
>
> Much cleaner. Thanks Ezra!
>
> Also, Ezra contributed a Table.create method and Logan Capaldo
> contributed a fix to eliminate a string eval. There is a new
> example script from Daniel Sheppard showing how to integrate
> ActiveRecord validations into Mongoose. Plus the usual code
> cleanup and bug fixes.
>
> *What is Mongoose?*
>
> Mongoose is a database management system written in Ruby. It has
> an ActiveRecord-like interface, uses Skiplists for its indexing,
> and Marshal for its data serialization. I named it Mongoose,
> because, like Rudyard Kipling's Rikki-Tikki-Tavi, my aim is for it
> to be small, quick, and friendly.
>
> You can find rudimentary documentation in the README file and some
> sample scripts in the example directory.
>
> Jamey Cribbs
> jcribbs@netpromi.com
>

I'm just too slow with sending in my patches. ;)


simonh

7/21/2006 5:39:00 PM

0

Jamey, just out of curiosity, how long did it take you to write
mongoose 0.1.0? Also Do you think mongoose will be more maintainable
now its split into multiple files?

Jamey Cribbs

7/21/2006 6:39:00 PM

0

simonh wrote:
> Jamey, just out of curiosity, how long did it take you to write
> mongoose 0.1.0? Also Do you think mongoose will be more maintainable
> now its split into multiple files?
>
>
I probably started working on it the middle of last week and have been
working on it in most of my spare time (probably a 2-3 hours a day; my
wife would probably say more like 5-6 hours a day :-) ). However, over
the last few months, I had already been experimenting with Skiplists and
with using Marshal for storage. Also, I was able to borrow some great
code from Logan Capaldo's KirbyRecord.

Yes, I do think it will be more maintainable. KirbyBase is one BIG file
and, so far, I definitely like the feel of having Mongoose split up into
different files for different components.

Jamey

Confidentiality Notice: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. If you are not the intended recipient(s), you are hereby notified that any dissemination, unauthorized review, use, disclosure or distribution of this email and any materials contained in any attachments is prohibited. If you receive this message in error, or are not the intended recipient(s), please immediately notify the sender by email and destroy all copies of the original message, including attachments.

Logan Capaldo

7/21/2006 6:53:00 PM

0


On Jul 21, 2006, at 2:39 PM, Jamey Cribbs wrote:

> simonh wrote:
>> Jamey, just out of curiosity, how long did it take you to write
>> mongoose 0.1.0? Also Do you think mongoose will be more maintainable
>> now its split into multiple files?
>>
>>
> I probably started working on it the middle of last week and have
> been working on it in most of my spare time (probably a 2-3 hours a
> day; my wife would probably say more like 5-6 hours a day :-) ).
> However, over the last few months, I had already been experimenting
> with Skiplists and with using Marshal for storage. Also, I was
> able to borrow some great code from Logan Capaldo's KirbyRecord.
>
> Yes, I do think it will be more maintainable. KirbyBase is one BIG
> file and, so far, I definitely like the feel of having Mongoose
> split up into different files for different components.
>
> Jamey
>
> Confidentiality Notice: This email message, including any
> attachments, is for the sole use of the intended recipient(s) and
> may contain confidential and/or privileged information. If you are
> not the intended recipient(s), you are hereby notified that any
> dissemination, unauthorized review, use, disclosure or distribution
> of this email and any materials contained in any attachments is
> prohibited. If you receive this message in error, or are not the
> intended recipient(s), please immediately notify the sender by
> email and destroy all copies of the original message, including
> attachments.
>

Jamey, while we are on the topic of Mongoose, since the query
language isn't straight up "loop thru all the records of the table,
pass the row into this proc and see if it returns true", any chance
of query optimization and or arbitrary joins? If not, would you
object if I tried my hand at adding joins and query optimization?
(This is not a promise, it's more like if I have time it will slowly
start to show up).

I have a couple of ideas, One involving how to do Hash-based equi-
joins and cheat a little bit, if what i believe about Marshal is true
and reliable.


John W. Long

7/21/2006 6:56:00 PM

0

Jamey Cribbs wrote:
> Plane.find do |plane|
> plane.speed > 350
> plane.any do
> plane.country == 'USA' plane.country == 'Great Britain'
> end
> end
>
> Now, looks like this:
>
> Plane.find do
> speed > 350
> any do
> country == 'USA'
> country == 'Great Britain'
> end
> end

James, could you elaborate on how this is done? I would assume that the
first method is better because you don't lose the the surrounding scope.
What's going on in that do block?

--
John Long
http://wiseheart...

Jamey Cribbs

7/21/2006 7:29:00 PM

0

Logan Capaldo wrote:
>
> Jamey, while we are on the topic of Mongoose, since the query language
> isn't straight up "loop thru all the records of the table, pass the
> row into this proc and see if it returns true", any chance of query
> optimization and or arbitrary joins? If not, would you object if I
> tried my hand at adding joins and query optimization? (This is not a
> promise, it's more like if I have time it will slowly start to show up).
>
That would be great. That's one of the things I am really excited about
Mongoose is that, now that I can look at the query *before* it is
executed (unlike KirbyBase), it can be optimized. I've already got a
few ideas about query optimization, but I would definitely welcome both
ideas and code.
> I have a couple of ideas, One involving how to do Hash-based
> equi-joins and cheat a little bit, if what i believe about Marshal is
> true and reliable.
>
>
>
Sounds good!

Jamey

Confidentiality Notice: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. If you are not the intended recipient(s), you are hereby notified that any dissemination, unauthorized review, use, disclosure or distribution of this email and any materials contained in any attachments is prohibited. If you receive this message in error, or are not the intended recipient(s), please immediately notify the sender by email and destroy all copies of the original message, including attachments.

Jamey Cribbs

7/21/2006 7:35:00 PM

0

Joey wrote:
> country in ['USA','Great Britian']
> would be nice!
I will add it to the feature requests list.

By the way, you can currently do:

country.one_of 'USA', 'Great Britain'

which is pretty close.

Jamey

Confidentiality Notice: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. If you are not the intended recipient(s), you are hereby notified that any dissemination, unauthorized review, use, disclosure or distribution of this email and any materials contained in any attachments is prohibited. If you receive this message in error, or are not the intended recipient(s), please immediately notify the sender by email and destroy all copies of the original message, including attachments.

Jamey Cribbs

7/21/2006 7:44:00 PM

0

John W. Long wrote:
> Jamey Cribbs wrote:
>> Plane.find do |plane|
>> plane.speed > 350
>> plane.any do
>> plane.country == 'USA' plane.country == 'Great Britain'
>> end
>> end
>>
>> Now, looks like this:
>>
>> Plane.find do
>> speed > 350
>> any do
>> country == 'USA'
>> country == 'Great Britain'
>> end
>> end
>
> James, could you elaborate on how this is done? I would assume that
> the first method is better because you don't lose the the surrounding
> scope. What's going on in that do block?
Actually, I like the second way better, because you don't have to
clutter up your query with lots of references to your table class.

The way it works is that in the Plane.find method, I grab the block and
pass it to #instance_eval. This executes the block in the Plane classes
environment, so it knows that when it sees the attribute "speed" or
"country" in the block, it knows to call Plane.speed and Plane.country.
Planes.speed happens to be a reference to a SkiplistColumn instance and
it knows how to handle the "> 350" passed to it.

I have to credit Ezra for pointing me to this.

The reference to "any" just calls Plane.any which is a method in the
Plane class that knows how to take the block inside of it and format it
as a sub-query of the main query.

Jamey

Confidentiality Notice: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. If you are not the intended recipient(s), you are hereby notified that any dissemination, unauthorized review, use, disclosure or distribution of this email and any materials contained in any attachments is prohibited. If you receive this message in error, or are not the intended recipient(s), please immediately notify the sender by email and destroy all copies of the original message, including attachments.

John W. Long

7/22/2006 3:11:00 AM

0

Jamey Cribbs wrote:
> The way it works is that in the Plane.find method, I grab the block and
> pass it to #instance_eval. This executes the block in the Plane classes
> environment, so it knows that when it sees the attribute "speed" or
> "country" in the block, it knows to call Plane.speed and Plane.country.
> Planes.speed happens to be a reference to a SkiplistColumn instance and
> it knows how to handle the "> 350" passed to it.

The problem with this approach is that you loose access to instance
variables. For instance:

>> class Object
>> def with(&block)
>> instance_eval(&block)
>> end
>> end
=> nil
>> @test = 1
=> 1
>> Object.new.with { puts @test }
=> nil

In the above example @test when used within the context of the with
block is thought to be an instance variable of the object, which is why
it returns nil instead of 1. I consider this behavior undesirable.

--
John Long
http://wiseheart...

Jamey Cribbs

7/22/2006 2:44:00 PM

0

John W. Long wrote:
> Jamey Cribbs wrote:
>> The way it works is that in the Plane.find method, I grab the block
>> and pass it to #instance_eval. This executes the block in the Plane
>> classes environment, so it knows that when it sees the attribute
>> "speed" or "country" in the block, it knows to call Plane.speed and
>> Plane.country. Planes.speed happens to be a reference to a
>> SkiplistColumn instance and it knows how to handle the "> 350" passed
>> to it.
>
> The problem with this approach is that you loose access to instance
> variables. For instance:
>
> >> class Object
> >> def with(&block)
> >> instance_eval(&block)
> >> end
> >> end
> => nil
> >> @test = 1
> => 1
> >> Object.new.with { puts @test }
> => nil
>
> In the above example @test when used within the context of the with
> block is thought to be an instance variable of the object, which is
> why it returns nil instead of 1. I consider this behavior undesirable.
Hmm, I see your point. I've been playing around with this all morning,
but I can't see a way out of this except to go back to passing the Table
class to the query block and also qualifying the table column names in
the block.

Even though it does clutter up the query block more, I think John is
right that it is definitely more important to have access to the
instance variables in the calling object.

Thanks for pointing this out to me, John.

Jamey