[ANN] Ackbar - ActiveRecord Adapter for KirbyBase

A

Assaph Mehr

=3D About Ackbar

Ackbar is an adapter for ActiveRecord (the Rails ORM layer) to the KirbyBas=
e
pure-ruby plain-text DBMS. Because KirbyBase does not support SQL, joins or
transactions, this is not a 100% fit. There are some changes to the ActiveR=
ecord
interface (see below), but it may still be useful in some cases.

=3D URIs

Ackbar: http://ackbar.rubyforge.org
KirbyBase: http://www.netpromi.com/kirbybase_ruby.html
Rails: http://www.rubyonrails.com
Pimki: http://pimki.rubyforge.org

=3D Goals

Ackbar's project goals, in order of importance, are:
1. Support Pimki with a pure-ruby, cross-platform hassle-less install DBMS
2. An exercise for me to learn ActiveRecord inside out
3. Support other "shrink-wrapped" Rails projects with similar needs

As can be seen, the main reason I need Ackbar is so I distribute Pimki acro=
ss
multiple platforms without requiring non-Ruby 3rd party libraries.
KirbyBase will
work wherever Ruby works, and so will Pimki. That alleviates the need
to repackage
other bits, end users will not have to install extra software, I have
full control
on the storage, the storage is in plain text. Just what I need to "shrink w=
rap"
a Rails project for end-user distribution.

=3D What's Covered

Ackbar currently passes through a small bootstrap test suite, and through a=
bout
80% of the ActiveRecord test suite. I will never pass 100% of the tests bec=
ause
KirbyBase does not support all required functionality.

Ackbar includes a SQL fragment translator, so that simple cross-database co=
de
should be maintainable. For example the following will work as expected,
Book.find :all, :conditions =3D> "name =3D 'Pickaxe'"
Book.find :all, :conditions =3D> ["name =3D ?", 'Pickaxe']
Additionally, you can also provide blocks:
Book.find :all, :conditions =3D> lambda{|rec| rec.name =3D=3D 'Pickaxe'}
or even:
Book.find:)all) {|rec| rec.name =3D=3D 'Pickaxe'}

Most of these changes are around the #find method, bit some apply to #updat=
e and
associations. Basic SQL translation should work the same, but you can alway=
s
provide custom code to be used. See the CHANGELOG and the tests for example=
s.


=3D What's Not Covered

* Transactions
* Joins, and therefore Eager Associations
* Mixins
* Other plugins

On the todo list is support for mixins. It might even be possible to
rig something
to simulate joins and eager associations, but that is for a later
stage. Transactions
will obviously only be supported once they are supported by KirbyBase.

Additionally, there are numerous little changes to the standard behaviour. =
See
the CHANGELOG and the tests for more details. These may cause little
heart attacks
if you expect a standard SQL database.

It is also worth noting that other plugins that write SQL will not
work. You will
need to get a copy of them to your /vendors dir and modify the relevant par=
ts.

=3D Installation

Simply:
gem install ackbar
or download the zip file from http://rubyforge.org/projects/ackbar and
just stick
kirbybase_adapter.rb in the Rails lib dir.

You will then need to add
require 'kirbybase_adapter'
in the config/environment.rb file of your project.

If you plan on multi-database development / deployment, you must
require the adapter
only if necessary:
require 'kirbybase_adapter' if
ActiveRecord::Base.configurations[RAILS_ENV]['adapter'] =3D=3D 'kirbybase'

This is because Ackbar overrides certain methods in ActiveRecord::Base
and others.
These methods translate the standard SQL generation to method calls on
KirbyBase,
and obviously should not be overridden for regular DBs.


Please do not hesitate to contact me for questions, comments, whacks
on the head with a clue stick :)

Cheers,
Assaph
 
H

Harold Hausman

Wow, best news in a while!

I can't wait to dig into this. A lot of Ruby love this Valentine Day.

Thank you,
-Harold

=3D About Ackbar

Ackbar is an adapter for ActiveRecord (the Rails ORM layer) to the KirbyB= ase
pure-ruby plain-text DBMS. Because KirbyBase does not support SQL, joins = or
transactions, this is not a 100% fit. There are some changes to the Activ= eRecord
interface (see below), but it may still be useful in some cases.

=3D URIs

Ackbar: http://ackbar.rubyforge.org
KirbyBase: http://www.netpromi.com/kirbybase_ruby.html
Rails: http://www.rubyonrails.com
Pimki: http://pimki.rubyforge.org

=3D Goals

Ackbar's project goals, in order of importance, are:
1. Support Pimki with a pure-ruby, cross-platform hassle-less install DBM= S
2. An exercise for me to learn ActiveRecord inside out
3. Support other "shrink-wrapped" Rails projects with similar needs

As can be seen, the main reason I need Ackbar is so I distribute Pimki ac= ross
multiple platforms without requiring non-Ruby 3rd party libraries.
KirbyBase will
work wherever Ruby works, and so will Pimki. That alleviates the need
to repackage
other bits, end users will not have to install extra software, I have
full control
on the storage, the storage is in plain text. Just what I need to "shrink= wrap"
a Rails project for end-user distribution.

=3D What's Covered

Ackbar currently passes through a small bootstrap test suite, and through= about
80% of the ActiveRecord test suite. I will never pass 100% of the tests b= ecause
KirbyBase does not support all required functionality.

Ackbar includes a SQL fragment translator, so that simple cross-database = code
should be maintainable. For example the following will work as expected,
Book.find :all, :conditions =3D> "name =3D 'Pickaxe'"
Book.find :all, :conditions =3D> ["name =3D ?", 'Pickaxe']
Additionally, you can also provide blocks:
Book.find :all, :conditions =3D> lambda{|rec| rec.name =3D=3D 'Pickaxe'= }
or even:
Book.find:)all) {|rec| rec.name =3D=3D 'Pickaxe'}

Most of these changes are around the #find method, bit some apply to #upd= ate and
associations. Basic SQL translation should work the same, but you can alw= ays
provide custom code to be used. See the CHANGELOG and the tests for examp= les.


=3D What's Not Covered

* Transactions
* Joins, and therefore Eager Associations
* Mixins
* Other plugins

On the todo list is support for mixins. It might even be possible to
rig something
to simulate joins and eager associations, but that is for a later
stage. Transactions
will obviously only be supported once they are supported by KirbyBase.

Additionally, there are numerous little changes to the standard behaviour= See
the CHANGELOG and the tests for more details. These may cause little
heart attacks
if you expect a standard SQL database.

It is also worth noting that other plugins that write SQL will not
work. You will
need to get a copy of them to your /vendors dir and modify the relevant p= arts.

=3D Installation

Simply:
gem install ackbar
or download the zip file from http://rubyforge.org/projects/ackbar and
just stick
kirbybase_adapter.rb in the Rails lib dir.

You will then need to add
require 'kirbybase_adapter'
in the config/environment.rb file of your project.

If you plan on multi-database development / deployment, you must
require the adapter
only if necessary:
require 'kirbybase_adapter' if
ActiveRecord::Base.configurations[RAILS_ENV]['adapter'] =3D=3D 'kirbybase= '

This is because Ackbar overrides certain methods in ActiveRecord::Base
and others.
These methods translate the standard SQL generation to method calls on
KirbyBase,
and obviously should not be overridden for regular DBs.


Please do not hesitate to contact me for questions, comments, whacks
on the head with a clue stick :)

Cheers,
Assaph
 
E

Ezra Zygmuntowicz

Assaph-

I am trying to play with ackbar right now. What is the syntax for
database.yml in order to use the kirbybase adapter? Can you give me a
sample please?

Thanks-
-Ezra
 
A

Assaph Mehr

I am trying to play with ackbar right now. What is the syntax for
database.yml in order to use the kirbybase adapter? Can you give me a
sample please?

That's a simple one to answer:

development:
adapter: kirbybase
database: db/dev_db

Te database should point to a directory, in which KirbyBase will store
the .tbl files. There are a few other options that can be passed to
KB, but essentially this is what I used for testing.

Cheers,
Assaph
 
E

Ezra Zygmuntowicz

That's a simple one to answer:

development:
adapter: kirbybase
database: db/dev_db

Te database should point to a directory, in which KirbyBase will store
the .tbl files. There are a few other options that can be passed to
KB, but essentially this is what I used for testing.

Cheers,
Assaph

Thats what I thought and i already have that but I still get this
stack trace when i try to do anything with the db:

ezra:~/_book/kirby ez$ script/generate migration initial_schema
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/
connection_adapters/abstract/connection_specification.rb:79:in
`establish_connection': database configuration specifies nonexistent
kirbybase adapter (ActiveRecord::AdapterNotFound)
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/connection_adapters/abstract/
connection_specification.rb:71:in `establish_connection'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/connection_adapters/abstract/
connection_specification.rb:66:in `establish_connection'
from /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/
initializer.rb:169:in `initialize_database'
from /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/
initializer.rb:83:in `process'
from /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/
initializer.rb:42:in `send'
from /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/
initializer.rb:42:in `run'
from ./script/../config/../config/environment.rb:10
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
18:in `require__'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
18:in `require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/
active_support/dependencies.rb:214:in `require'
from /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/
generate.rb:1
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
18:in `require__'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
18:in `require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/
active_support/dependencies.rb:214:in `require'
from script/generate:3

Clues? Do i need to bootstrap the db somehow before I just make an
intial schema or what?

Thanks
-Ezra
 
A

Assaph Mehr

ezra:~/_book/kirby ez$ script/generate migration initial_schema
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/
connection_adapters/abstract/connection_specification.rb:79:in
`establish_connection': database configuration specifies nonexistent
kirbybase adapter (ActiveRecord::AdapterNotFound)

Have you require'd kirbybase_adapter? You need to add the require in
the config/environment.rb.
 
E

Ezra Zygmuntowicz

Have you require'd kirbybase_adapter? You need to add the require in
the config/environment.rb.

Yeah I tried that. I have the gem installed and I even tried putting
the kirbybase_adapter.rb in lib and it still didn't work same trace.
Anyway, I'll keep playing with it, I'm sure I'll figure it out.

Cheers-
-Ezra Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
http://yakimaherald.com
(e-mail address removed)
blog: http://brainspl.at
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top