# Mongoose 0.1.0

**URL:** <https://www.ruby-forum.com/t/mongoose-0-1-0/99004>\
**Category:** Ruby\
**Created:** [July 19, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/mongoose-0-1-0/99004 "2006-07-19T17:43:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jamey\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5e9695/32.png) [@Jamey\_C](https://www.ruby-forum.com/u/Jamey_C)\
**Post date:** [July 19, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/mongoose-0-1-0/99004/1 "2006-07-19T17:43:59Z")

</div>

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 download it from: [http://rubyforge.org/projects/mongoose/](http://rubyforge.org/projects/mongoose/)

## _Credits_

Thanks to Logan C. for letting me steal a lot of the code from  
KirbyRecord.

Thanks to Ezra Z. and Fabien F., whose ez\_where Rails  
plugin, provided much of the  
inspiration for the query language.

Thanks to everyone who gave me feedback on KirbyBase. I have tried to  
put all the lessons learned from developing that library to good use  
here.

## _Features_

- Pure Ruby, with no external dependencies.

- ActiveRecord-like interface.

- Fast queries on indexed fields (Up to 10x faster than KirbyBase).  
Indexes are Skiplists, which are just plain fun to play around with.

- Not an in-memory database. Data is only read in from disk when needed  
and changes are immediately written out to disk.

- In-memory indexes are initialized from dedicated index files, rather  
than rebuilt from scratch upon database initialization (like KirbyBase  
does). This can greatly reduce startup times.

- Supports any data type that Marshal supports.

- Table relations supported via has\_one, has\_many.

## _Why?_

Well, I started to look into performance improvements for KirbyBase.  
One thing I noticed was that Ruby takes a comparatively long time  
converting strings to native data types like Integer, Time, etc. Since  
KirbyBase stores its records as strings, returning a large result set  
could take a long time. I found that if I Marshaled records before I  
wrote them to disk, a subsequent read of those records was significantly  
faster.

About the same time, I read a paper about skiplists. A skiplist is a  
data structure that is relatively simple (compared to say a b-tree) to  
understand and implement in code. I was able to take the pseudo-code in  
the paper and implement a Ruby version in a couple of hours. Skiplists  
are pretty fast and since they are pretty easy to understand, I think  
there is good potential to tweak them. So, I wanted to try using  
skiplists for indexing rather than KirbyBase’s array-based indexes.

I started to retrofit both the Marshal serialization and Skiplists in  
KirbyBase, but quickly found that it was going to be more work than just  
starting over from scratch with a new design. Besides, I didn’t want to  
radically change KirbyBase and piss off the current user base (both of  
you know who you are).

So, I started from scratch. This also gave me the opportunity to make  
two other major changes. First of all, I wanted to keep the query  
language as close to KirbyBase’s as possible (i.e. Ruby blocks), but I  
wanted more control over the query expression. I took the opportunity  
to borrow a lot of idea’s from Ezra’s ez\_where plugin. I think this  
will give me the capability down the road to tweak the query engine,  
based on the query itself.

The second thing I changed was that I have finally seen the light about  
ActiveRecord, so I stole pretty much all of Logan’s KirbyRecord code to  
give Mongoose an ActiveRecord-like api.

The end result of all of this (I hope) is a database management system  
that is small, easy to use, and fast.

_What about KirbyBase?_

---

<div class="post-metadata">

**Author:** ![Jamey\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5e9695/32.png) [@Jamey\_C](https://www.ruby-forum.com/u/Jamey_C)\
**Post date:** [July 19, 2006, 6:50pm UTC](https://www.ruby-forum.com/t/mongoose-0-1-0/99004/2 "2006-07-19T18:50:15Z")

</div>

On Jul 19, 2006, at 10:41 AM, Jamey C. wrote:

> 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.

This really interesting stuff Jamey. Thanks for sharing!

James Edward G. II

---

<div class="post-metadata">

**Author:** ![Jamey\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5e9695/32.png) [@Jamey\_C](https://www.ruby-forum.com/u/Jamey_C)\
**Post date:** [July 19, 2006, 6:09pm UTC](https://www.ruby-forum.com/t/mongoose-0-1-0/99004/3 "2006-07-19T18:09:01Z")

</div>

On Jul 19, 2006, at 8:41 AM, Jamey C. wrote:

> Thanks to Logan C. for letting me steal a lot of the code from

Jamey-

```
This looks awesome! I totally have a few good uses for this. I will

```

be playing with this and giving you feedback and maybe a few patches  
as i get familiar with it.

Thanks Jamey!

-Ezra

---

<div class="post-metadata">

**Author:** ![Jamey\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5e9695/32.png) [@Jamey\_C](https://www.ruby-forum.com/u/Jamey_C)\
**Post date:** [July 20, 2006, 3:15am UTC](https://www.ruby-forum.com/t/mongoose-0-1-0/99004/4 "2006-07-20T03:15:26Z")

</div>

Ezra Z. wrote:

> Jamey-
> 
> ```
> This looks awesome! I totally have a few good uses for this. I 
> 
> ```
> 
> will be playing with this and giving you feedback and maybe a few  
> patches as i get familiar with it.

Thank _you_ for ez\_where! I have to admit that, even though I looked at  
your code, I still couldn’t totally wrap my head around how you had made  
some of the ez\_where magic happen. So, if you do get a chance to look  
at my query code and give me any pointers on what I could do better,  
that would be great.

Jamey

---

<div class="post-metadata">

**Author:** ![Jamey\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5e9695/32.png) [@Jamey\_C](https://www.ruby-forum.com/u/Jamey_C)\
**Post date:** [July 19, 2006, 8:02pm UTC](https://www.ruby-forum.com/t/mongoose-0-1-0/99004/5 "2006-07-19T20:02:47Z")

</div>

On 7/19/06, Jamey C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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.

Great job!
