jasagiri @ ウィキ

Ambition再び

最終更新:

jasagiri

- view
管理者のみ編集可

いろいろなことが Ambition のために改善されています。最初のリリースから2週間での最新の成果を伝えようと思いました。

現在のバージョンは 0.2.2 で、出来る限りフォローし続けてください。 供給(?)には限りがあります。.

$ sudo gem install ambition -y

Databasein’

Ambition はあなたが選んだデータベースを尊重してSQLを生成しています。 (MySQL や PostgreSQL では)。

Check it:

# Postgres
User.select { |m| m.name =~ /chris/ }
SELECT * FROM users WHERE users."name" ~ 'chris'
# MySQL
User.select { |m| m.name =~ /chris/ }
SELECT * FROM users WHERE users.`name` REGEXP 'chris'

クール。 Postgres が大文字と小文字を区別する正規表現をサポートするので、私たちも対応します。:

User.select { |m| m.name =~ /chris/i }
SELECT * FROM users WHERE users."name" ~* 'chris'

あなたが好むかに関わらず、エスケープ処理は DB 固有です。そして Postgres では OFFSET が動作します。

私たちの(短い)リストにあなたが選択したデータベースを見つかりますか?遠慮なくパッチを送ってください、ありがたく受け取ります。

Toyin’

your toe in に浸るのを望むなら、will_paginate に影響された test/console を追加します。(?)

データベースは自分で作らなければなりませんが、一度セットアップすれば、この irbish スクリプトでスキーマ作成と fixtures の読み込みされ、楽しく実行できるでしょう。

$ mysqladmin create ambition_development
$ cd GEMS/ambition-0.2.2
$ ruby test/console
>> Developer.select { |u| u.salary > 80_000 }.size

=> 9

>> Developer.select { |u| u.salary > 80_000 }.entries

=> [#<Developer:0x271f370 ...> ...]

関連について多少荒い箇所があるかもしれませんが、全体としてはうまく動作しています。

異なったデータベースを使うために、 ADAPTER 環境変数を設定してください。例えば、

$ ADAPTER=sqlite3 ruby test/console

Speedin’

Some people have been asking about performance. You know how it goes. “Oh, that’s cool, but it’s slow.” “It doesn’t scale.” “Who owns the trademark?”

In the interest of appeasing the unappeasable, I spent some time with ruby-prof. Below are the fruits of my labor, comparing the first and latest versions of Ambition.

Each case runs 10,000 times. The benchmark I used is here. I had to fix some bugs in 0.1.0 to get it to work, but that shouldn’t affect anything.

# Ambition 0.1.0
                           user     system       total        real
simple select          7.030000   0.020000   7.050000 (  7.052899)
dual select            8.050000   0.010000   8.060000 (  8.094917)
join select            7.890000   0.030000   7.920000 (  8.003906)
dual select w/ sort   13.390000   0.040000  13.430000 ( 13.529581)
dual select w/ stuff  13.600000   0.050000  13.650000 ( 14.107565)
it's complicated      16.030000   0.070000  16.100000 ( 16.213238)
# Ambition 0.2.2
                         user     system      total        real
simple select         0.910000   0.010000   0.920000 (  0.921048)
dual select           1.380000   0.010000   1.390000 (  1.398235)
join select           1.950000   0.020000   1.970000 (  1.981603)
dual select w/ sort   1.960000   0.000000   1.960000 (  1.964018)
dual select w/ stuff  2.080000   0.010000   2.090000 (  2.111435)
it's complicated      2.820000   0.000000   2.820000 (  2.831330)
So, that’s pretty cool. We’re definitely not slowing anything down—Ambition happily leaves that task up to your app. Zing!

Stubbin’

これはまだ実験的な特徴ですが、 but that’s what we’re all about. Observe:

User.ambition_source = fixtures(:chris, :pj, :_why)
User.detect { |u| u.name == 'Chris' }

もし ambition_source がセットされ、 Ambition がデータベースの代わりにすべて実行するようになるでしょう。上の例では、 SQL を訓見立てて実行するよりもむしろ、fixures 配列を選択して実行しています。 単体テストの関数 / がクールかもしれません。

Gitin’

Development is now riding Git rather than Subversion. Follow along:

$ git clone git://errtheblog.com/git/ambition

If you haven’t already tried Git, this could be a golden opportunity for us both. Other projects like Rubinius, god, and CouchObject are already using this up and coming tool for development, so give it a shot.

Us using Git or Subversion should not affect your ability to use Ambition in a Rails app. You can either require the gem or run gem unpack ambition in your vendor/plugins directory to get it working.

Contributin’

Thanks to Matthew King, David Chelimsky, Pratik Naik, Loïc, Louis Rose, John Topley, and François Beausoleil for bug reports, feature requests, and their contributions.

If you didn’t catch the updates on the last post, we added empty?, downcase, upcase, any?, all?, and slice thanks to their hard work.

As always, you can add bugs, make requests, and participate in general over at the Lighthouse bug tracker.

We now have a mailing list, too: http://groups.google.com/group/ambition-rb

Prospectin’

私たちの目標は Rack から LINQ へ移りました。 これは、他の ORMs (Ambition が SQL, LDAP, XPath, 仕事といったた問い合わせ言語になる)サポートするだけではありません。 1.0 がリリースされる頃にはバックエンドについては気にしなくなります。 その頃には大胆にも名前を変えるかもしれません。時間が解決します。

記事メニュー
目安箱バナー