HAYASHI Kentaro
null+****@clear*****
Thu Sep 26 18:47:50 JST 2013
HAYASHI Kentaro 2013-09-26 18:47:50 +0900 (Thu, 26 Sep 2013) New Revision: 403839c842b31051fea04102648e13604926cada https://github.com/groonga/groonga/commit/403839c842b31051fea04102648e13604926cada Message: doc: add note and execution example about cascade delete Added files: doc/source/example/reference/commands/delete_cascade.log doc/source/example/reference/commands/delete_status.log Modified files: doc/source/reference/commands/delete.txt Added: doc/source/example/reference/commands/delete_cascade.log (+112 -0) 100644 =================================================================== --- /dev/null +++ doc/source/example/reference/commands/delete_cascade.log 2013-09-26 18:47:50 +0900 (1a0643a) @@ -0,0 +1,112 @@ +Execution example:: + + table_create Country TABLE_HASH_KEY ShortText + # [[0, 1337566253.89858, 0.000355720520019531], true] + table_create Users TABLE_HASH_KEY UInt32 + # [[0, 1337566253.89858, 0.000355720520019531], true] + column_create Users name COLUMN_SCALAR ShortText + # [[0, 1337566253.89858, 0.000355720520019531], true] + column_create Users country COLUMN_SCALAR Country + # [[0, 1337566253.89858, 0.000355720520019531], true] + load --table Users + [ + {"_key": 1, "name": "John", country: "United States"} + {"_key": 2, "name": "Mike", country: "United States"} + {"_key": 3, "name": "Takashi", country: "Japan"} + {"_key": 4, "name": "Hanako", country: "Japan"} + ] + # [[0, 1337566253.89858, 0.000355720520019531], 4] + load --table Country + [ + {"_key": "United States"} + {"_key": "Japan"} + ] + # [[0, 1337566253.89858, 0.000355720520019531], 2] + delete Country "United States" + # [[0, 1337566253.89858, 0.000355720520019531], true] + select Country + # [ + # [ + # 0, + # 1337566253.89858, + # 0.000355720520019531 + # ], + # [ + # [ + # [ + # 1 + # ], + # [ + # [ + # "_id", + # "UInt32" + # ], + # [ + # "_key", + # "ShortText" + # ] + # ], + # [ + # 2, + # "Japan" + # ] + # ] + # ] + # ] + select Users + # [ + # [ + # 0, + # 1337566253.89858, + # 0.000355720520019531 + # ], + # [ + # [ + # [ + # 4 + # ], + # [ + # [ + # "_id", + # "UInt32" + # ], + # [ + # "_key", + # "UInt32" + # ], + # [ + # "country", + # "Country" + # ], + # [ + # "name", + # "ShortText" + # ] + # ], + # [ + # 1, + # 1, + # "", + # "John" + # ], + # [ + # 2, + # 2, + # "", + # "Mike" + # ], + # [ + # 3, + # 3, + # "Japan", + # "Takashi" + # ], + # [ + # 4, + # 4, + # "Japan", + # "Hanako" + # ] + # ] + # ] + # ] Added: doc/source/example/reference/commands/delete_status.log (+38 -0) 100644 =================================================================== --- /dev/null +++ doc/source/example/reference/commands/delete_status.log 2013-09-26 18:47:50 +0900 (663e422) @@ -0,0 +1,38 @@ +Execution example:: + + delete Entry 2 + # [[0, 1337566253.89858, 0.000355720520019531], true] + select Entry + # [ + # [ + # 0, + # 1337566253.89858, + # 0.000355720520019531 + # ], + # [ + # [ + # [ + # 1 + # ], + # [ + # [ + # "_id", + # "UInt32" + # ], + # [ + # "_key", + # "UInt32" + # ], + # [ + # "status", + # "ShortText" + # ] + # ], + # [ + # 1, + # 1, + # "OK" + # ] + # ] + # ] + # ] Modified: doc/source/reference/commands/delete.txt (+71 -18) =================================================================== --- doc/source/reference/commands/delete.txt 2013-09-26 18:37:05 +0900 (6696717) +++ doc/source/reference/commands/delete.txt 2013-09-26 18:47:50 +0900 (cf718e9) @@ -2,17 +2,25 @@ .. highlightlang:: none +.. groonga-command +.. database: commands_delete + ``delete`` ========== Summary ------- -delete - 一件のレコードの削除 +``delete`` command deletes specified record of table. + +.. _cascade-delete: -groonga組込コマンドの一つであるdeleteについて説明します。組込コマンドは、groonga実行ファイルの引数、標準入力、またはソケット経由でgroongaサーバにリクエストを送信することによって実行します。 +Cascade delete +^^^^^^^^^^^^^^ -deleteは、使用しているデータベースのテーブルに1件のレコードを削除します。 +There is a case that multiple table is associated. For example, the key of one table are referenced by other table's records. In such a case, if you delete the key of one table, other table's records are also removed. + +Note that the type of other table's column is COLUMN_VECTOR, only the value of referencing key is removed from the vector value. Syntax ------ @@ -23,47 +31,92 @@ Syntax Usage ----- -テーブルEntryからレコードを削除します。:: - - delete Entry abandon +Here are a schema definition and sample data to show usage. + +.. groonga-command +.. table_create Entry TABLE_HASH_KEY UInt32 +.. column_create Entry status --type ShortText +.. load --table Entry +.. [ +.. {"_key": 1, "status": "OK"} +.. {"_key": 2, "status": "NG"} +.. ] + +Delete the record from Entry table which has "2" as the key. + +.. groonga-command +.. include:: ../../example/reference/commands/delete_status.log +.. delete Entry 2 +.. select Entry + +Here is the example about cascaded delete. + +The country column of Users table associates with Country table. + +"Cascaded delete" removes the records which matches specified key and refers that key. + +.. groonga-command +.. include:: ../../example/reference/commands/delete_cascade.log +.. table_create Country TABLE_HASH_KEY ShortText +.. table_create Users TABLE_HASH_KEY UInt32 +.. column_create Users name COLUMN_SCALAR ShortText +.. column_create Users country COLUMN_SCALAR Country +.. load --table Users +.. [ +.. {"_key": 1, "name": "John", country: "United States"} +.. {"_key": 2, "name": "Mike", country: "United States"} +.. {"_key": 3, "name": "Takashi", country: "Japan"} +.. {"_key": 4, "name": "Hanako", country: "Japan"} +.. ] +.. load --table Country +.. [ +.. {"_key": "United States"} +.. {"_key": "Japan"} +.. ] +.. delete Country "United States" +.. select Country +.. select Users - [true] Parameters ---------- ``table`` - レコードを削除しようとするテーブルの名前を指定します。 + It specifies the name of table to delete the records. ``key`` - 削除するレコードの主キー値を指定します。主キーなしのテーブルの場合はこのパラメータを指定しても無視されます(idパラメータを代わりに指定します)。 + It specifies the key of record to delete. If you use the table with TABLE_NO_KEY, the key is just ignored. + (Use ``id`` parameter in such a case) ``id`` - レコードIDによってレコードを指定します。idパラメータを指定する場合は、keyパラメータを指定してはいけません。 + It specifies the id of record to delete. If you specify ``id`` parameter, you must not specify ``key`` parameter. ``filter`` - script形式のgrn_expr文字列によってレコードを指定します。filterパラメータを指定する場合は、id及びkeyパラメータを指定してはいけません。 + It specifies the expression of grn_expr to identify the record. If you specify ``filter`` parameter, + you must not specify ``key`` and ``id`` parameter. Return value ------------ -json形式 -^^^^^^^^ - :: - [成功かどうかのフラグ] + [HEADER, SUCCEEDED_OR_NOT] + +``HEADER`` + + The format of HEADER is [0, UNIX_TIME_WHEN_COMMAND_IS_STARTED, ELAPSED_TIME]. + See :doc:`/reference/command/output_format` about HEADER. -``成功かどうかのフラグ`` +``SUCCEEDED_OR_NOT`` - エラーが生じなかった場合にはtrue、エラーが生じた場合にはfalseを返す。 + If command succeeded, it returns true, otherwise it returns false on error. -関連項目 +See also -------- :doc:`load` -------------- next part -------------- HTML����������������������������...Download