LoginSignup
1
1

More than 5 years have passed since last update.

Casbahのラッパー作ってみた

Posted at

Casbahのラッパー作ってみた

ScalaでMongoDBとやり取りするには。

MongoDBの公式サイト

いろいろある。

Rogueがいい感じだったので、それを使おうかと思ったのだが
Liftに依存してたので、やめた。

で、オレオレドライバ作った。
ドライバというよりは、公式ドライバ「Casbah」のラッパー、といった方が正しいが。

implicit val db = MongoClient(...)("dbの名前")

// insert
Book.insert( Book(author="FooBar", title="HogeFuga", price=1200) )

// find
val books: Seq[Book] = Book.where(_.author == "foo" && _.price >= 2000).find

// update
Book.where(_.title == "hoge").set(price := 1000).update

// remove
Book.where(_.price <= 1000).remove

Casbahを直接使うよりは、便利に書けると思う。
とくにANDとかORとか使う場合は。


githubで公開してます。

tochka

これ作るために、いろいろ調べていて思ったのだが、
MongoDB使うならScalaよりGroovyの方が便利だと思う。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1