7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【個人メモ】tiedotというNoSQL DBをいじってみる

Last updated at Posted at 2014-10-13

tiedot?

tiedot

Goで書かれたNoSQL DB。
触ってみるメモを書いとく。

環境

  • Golangをインストール済みであること
  • git, mercurialがインストール済みであること
  • $GOPATH, $GOROOTが設定済みであること

インストール方法

> go get github.com/HouzuoGuo/tiedot

tiedotの立ち上げ

> tiedot -mode=httpd -dir=/tmp/MyDatabase -port=8080

tiedot Web UI

Web UIが用意されている。admin画面を開いてみる

> open http://localhost:8080/admin

Screen Shot 2014-10-07 at 22.26.39.png

Web UIから操作をする

コレクションとやらを作ってみよう。

Screen Shot 2014-10-07 at 22.41.53.png

"New Collection"ボタンをクリックして、
Modalの中にコレクション名を入れ、作成してみた。

Screen Shot 2014-10-07 at 22.42.03.png

ドキュメントを作成

  • "New Doc"を押してドキュメントを作る

Screen_Shot_2014-10-07_at_22_48_06.png

  • JSON形式でドキュメントを書いていく

Screen Shot 2014-10-07 at 22.56.00.png

  • 新しいドキュメントがhogehogeコレクションに追加された。

Screen Shot 2014-10-13 at 19.37.15.png

  • コレクションのindex一覧画面にも、追加したドキュメントが表示されている

Screen Shot 2014-10-13 at 19.38.35.png

検索するためにindexを設定

クエリを投げるためにはindexを設定しなければいけないので、
indexを設定する。

Screen_Shot_2014-10-13_at_21_26_14.png

  • index追加

"New Index"ボタンを押す。

Screen_Shot_2014-10-13_at_21_28_07.png

  • modalにてindexに指定するキー名を入力する

Screen Shot 2014-10-13 at 21.28.58.png

ドキュメントとして保存した時に利用したキー名である
age, name, gadgetsを入力。

Screen Shot 2014-10-13 at 21.33.23.png

ドキュメントに保存した値をGUIで取得

name=Keiji Matsuzaki となるドキュメントがないか検索を行うクエリをGUIにて発行する

  • ドキュメントの画面で"Query"ボタンを押す

Screen_Shot_2014-10-13_at_21_35_23.png

  • 検索するクエリを書く

検索対象となるドキュメントは1件しか保存していないが、
クエリを書いてみることにする

{ "eq": "Keiji Matsuzaki", "in": ["name"]}
  • クエリの実行

Screen Shot 2014-10-13 at 21.59.05.png

"Execute" ボタンを押して、検索クエリに合うドキュメントがあれば、
ドキュメントが表示される。

  • 無効なクエリを実行

検索に引っかからないクエリを発行した場合は、ドキュメントは出てこない。

Screen Shot 2014-10-13 at 22.02.22.png

CLIから操作

tiedotにはCLIからも操作が可能になるようにAPIが用意されている。
詳しくは、API reference and embedded usageを参考のこと。

コレクションの作成

> curl "http://localhost:8080/create?col=hogehoge"

コレクションが作られたか確認する

> curl "http://localhost:8080/all"
["hogehoge"]

ドキュメントをコレクションに対して作成する

> curl --data-ascii \
  doc='{"name": "Keiji Matsuzaki", "age": 32, "gadgets": ["iPhone 6 Plus", "Nexus 7", "Mac Book Pro Retina Late 2012"]} \ 
  'http://localhost:8080/insert?col=hogehoge'
1652584854220917731

帰ってきたIDを元にドキュメントを検索

一意なIDが生成されるので、検索が容易。

> curl "http://localhost:8080/get?col=hogheoge&id=1652584854220917731"
{"age":32,"gadgets":["iPhone 6 Plus","Nexus 7","Mac Book Pro Retina Late 2012"],"name":"Keiji Matsuzaki"}

検索クエリを投げる

indexを作成する

indexを作成しなければクエリを投げることができない。
age, name, gadgetsのindexを作成する

> curl "http://localhost:8080/index?col=hogehoge&path=age"
> curl "http://localhost:8080/index?col=hogehoge&path=name"
> curl "http://localhost:8080/index?col=hogehoge&path=gadgets"

クエリを投げる

  • "name" = "Keiji Matsuzaki" なドキュメントを検索する
> curl --data-ascii \
  doc='{"name": "Keiji Matsuzaki", "in": ["name"]}' \
  http://localhost:8080/query?col=hogehoge'

{"1652584854220917731":{"age":32,"gadgets":["iPhone 6 Plus","Nexus 7","Mac Book Pro Retina Late 2012"],"name":"Keiji Matsuzaki"}}

サーバのシャットダウンを行う

  • /shutdown APIにアクセスすれば良い
> curl "http://localhost:8080/shutdown"
curl: (52) Empty reply from server

触ってみて

CouchDBの代わりになるのだろうか、とふと思ったり...
開発時のJSONでレスポンスを返すAPI サーバのモックアップとして利用できるんじゃないかなあ。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?