NextDB.netを触ってみた

Ajaxianでちょろっと紹介されていたNextDB.netが、いろんな意味で、おもしろい。

NextDB.net is a revolutionary hosted database that lets AJAX applications leverage the full power of data-driven programming.

In the past, creating a scalable data-driven website required knowledge of SQL and backend programming-- not anymore. Creating a powerful relational database is now as simple as logging into your NextDB account and using intuitive graphical tools to create tables, relationships and queries.

NextDB's powerful AJAX API's bring the full power of relational programming into the browser. If you're a web designer with limited JavaScript experience, you will be amazed at how easy it is to data-enable your HTML pages. If you're an experienced database developer, you will appreciate a "real" database programming environment that is perfectly suited to the most demanding Web 2.0 applications.

nextdb.net - Registered at Namecheap.com

NextDB.net はJavaScriptからアクセスできるWeb上のデータベース。呼び出しは基本的にJavaScriptからAPI経由で行う。間にプロキシサーバを挟むことはない。JSONPのコールバックを使ってブラウザからダイレクトに通信する。読み込みのみならず書き込みもそれで行っている。これにはびっくり。つまり、永続データを扱うAjaxアプリケーションを全くサーバ無しでつくれるよ、みたいなことが目標のようだ。データベースのスキーマは開発者がWebブラウザから定義できる。SimpleDBのようにスキーマレス、という訳ではなく、感覚としては通常のリレーショナルデータベースに近い。

通信は至ってシンプル。以下はサンプルアプリケーション(http://www.nextdb.net/demo-blog/)にログインしたとき(abc@example.com/abc123)のリクエストと、それに対するレスポンスのダンプ。

http://www.nextdb.net:8080/nextdb/service/brenthamby/demo1/EXECUTE_QUERY?callback=net.nextdb.Request.queryCallback&name=LOGIN&pageSize=10&startAfterPK=0&$%7Bemail%7D=abc@example.com&$%7Bpwd%7D=abc123&id=1
net.nextdb.Request.queryCallback(
{id:1,rs:[{USER:{PK:"-19h6g39fvleg3",first_name:"abc",last_name:"def",email:"abc@example.com",password:"abc123"}}]}
)

クエリ。USER_BLOGテーブルのレコードを全部取ってくる。ユーザ/パスワードをリクエストごとに毎回渡すみたい。

http://www.nextdb.net:8080/nextdb/service/brenthamby/demo1/EXECUTE_QUERY?callback=net.nextdb.Request.queryCallback&name=GET_USER_BLOGS&pageSize=1000&startAfterPK=0&$%7Bemail%7D=abc@example.com&$%7Bpassword%7D=abc123&id=2
net.nextdb.Request.queryCallback(
{id:2,rs:[{USER:{PK:"1hvzizm88858a",first_name:"abc",last_name:"def",email:"abc@example.com",password:"abc123"},USER_BLOG:{PK:"-cdqseinqf6jl",name:"my first blog",created:"2008-04-25 09:06:41.03 GMT",public:0}},
{USER:{PK:"1b96tclujyqn1",first_name:"abc",last_name:"def",email:"abc@example.com",password:"abc123"},USER_BLOG:{PK:"nxkrigs70dem",name:"my second blog",created:"2008-04-25 09:06:58.391 GMT",public:0}}]}
)


データのインサートを試してみる。BLOG_ENTRYテーブルに一行追加。FKパラメータに既に取得したUSER_BLOGレコードのPKが指定されている。

http://www.nextdb.net:8080/nextdb/service/brenthamby/demo1/INSERT?_callback=net.nextdb.Request.insertCallback&_table=BLOG_ENTRY&title=Hello%2C%20World&body=This%20is%20a%20test&created=now&public=0&_relationshipName=BLOG_ENTRIES&_FK=pad2m408dd9u&_id=3
net.nextdb.Request.insertCallback(
 {
 "generatedPK":"-1eqo3kfi6cngv",
 "id":"3",
 "message":"1 row inserted into BLOG_ENTRY and linked to USER_BLOG",
 "permalink":null
 }
)

成功。あれ、でもこれにはユーザ名もパスワードもないのだけれど。CSRFは大丈夫?
ってことで、まったく関係ないサイトからおなじINSERTリクエストをJSONPで投げてみる。

net.nextdb.Request.insertCallback(
 {
 "generatedPK":"17vp8o9i68bav",
 "id":"3",
 "message":"1 row inserted into BLOG_ENTRY and linked to USER_BLOG",
 "permalink":null
 }
)

成功してしまった。確かにデータベースには同じエントリが2つできている。リクエストIDのような役目に見えるidパラメータ値がかぶっていてもまったく関係ない模様。

どうもここの説明によると一応Referrerを見ているらしいが、ほんとにやってるのかどうかが結局不明。クライアントが意図的にReferrer切ったらどうするのかも不明。まあ、まだAlphaですしね。アカウント来たらもうちょっと触ってみてもいい。

How does NextDB use HTTP Referrer headers?

For each database, you can independently set the HTTP referrers that are allowed to access the database. Database access will be denied for any HTTP request that originates from a web page that is not on the list of allowed HTTP referrers.

http://www.nextdb.net/faq.html