delta_trace_db.db.delta_trace_db_collection¶
Classes
(en) This class relates to the contents of each class in the DB. |
- class delta_trace_db.db.delta_trace_db_collection.Collection¶
Bases:
CloneableFile(en) This class relates to the contents of each class in the DB. It implements operations on the DB.
(ja) DB内のクラス単位の内容に関するクラスです。 DBに対する操作などが実装されています。
- add_all(q: Query) QueryResult¶
(en) Adds the data specified by the query. If the key specified by serialKey does not exist in the object being added, the operation will fail.
(ja) クエリで指定されたデータを追加します。 serialKeyで指定したキーが追加するオブジェクトに存在しない場合、操作は失敗します。
- Parameters:
q (Query) – The query.
- add_listener(cb: Callable[[], None], name: str | None = None)¶
(en) This is a callback setting function that can be used when linking the UI and DB. The callback set here will be called when the contents of this collection are changed. In other words, if you register it, you will be able to update the screen, etc. when the contents of the DB change. Normally you would register it in initState and then use removeListener to remove it when disposing. If you use this on the server side, it may be a good idea to set up a function that writes the backup to storage. Please note that notifications will not be restored even if the DB is deserialized. You will need to set them every time.
Note: Listeners are not serialized. You must re-register them each time after deserialization.
(ja) UIとDBを連携する際に利用できる、コールバックの設定関数です。 ここで設定したコールバックは、このコレクションの内容が変更されると呼び出されます。 つまり、登録しておくとDBの内容変更時に画面更新等ができるようになります。 通常はinitStateで登録し、dispose時にremoveListenerを使って解除してください。 これをサーバー側で使用する場合は、バックアップをストレージに書き込む関数などを設定 するのも良いかもしれません。 なお、通知に関してはDBをデシリアライズしても復元されません。毎回設定する必要があります。
注: リスナーはシリアライズされません。デシリアライズ後は毎回再登録する必要があります。
- Parameters:
cb (Callable[[], None]) – The function to execute when the DB is changed.
name (Optional[str]) – If you set a non-null value, a listener will be registered with that name. Setting a name is useful if you want to be more precise about registration and release.
- change_transaction_mode(is_transaction_mode: bool)¶
(en) Called when switching to or from transaction mode. This is intended to be called only from DeltaTraceDB. Do not normally use this.
(ja) トランザクションモードへの変更時、及び解除時に呼び出します。 これはDeltaTraceDBからのみ呼び出されることを想定しています。 通常は使用しないでください。
- Parameters:
is_transaction_mode (bool) – If true, change to transaction mode.
- class_name = 'Collection'¶
- clear(q: Query) QueryResult¶
(en) Clear the contents of the collection.
(ja) コレクションの内容を破棄します。
- Parameters:
q (Query) – The query.
- clear_add(q: Query) QueryResult¶
(en) Clear the contents stored in the collection and then adds data. This can be used, for example, to update a front-end database with search results from a back-end. If the key specified by serialKey does not exist in the object being added, the operation will fail.
(ja) コレクションの内容を破棄してからデータを追加します。 これは例えば、バックエンドからの検索内容でフロントエンドのDBを更新したい場合などに 使用できます。 serialKeyで指定したキーが追加するオブジェクトに存在しない場合、操作は失敗します。
- Parameters:
q (Query) – The query.
- clone() Collection¶
(en) Returns a deep copy of this object.
(ja) このオブジェクトのディープコピーを返します。
- conform_to_template(q: Query) QueryResult¶
(en) Changes the structure of the database according to the specified template. Keys and values that are not in the specified template are deleted. Keys that exist only in the specified template are added and initialized with the values from the template.
(ja) データベースの構造を、指定のテンプレートに沿って変更します。 指定したテンプレートに無いキーと値は削除されます。 指定したテンプレートにのみ存在するキーは追加され、テンプレートの値で初期化されます。
- Parameters:
q (Query) – The query.
- count(q: Query) QueryResult¶
(en) Returns the total number of items stored in the collection.
(ja) コレクションに保存されているデータの総数を返します。
- Parameters:
q (Query) – The query.
- delete(q: Query) QueryResult¶
(en) Deletes all objects that match a query.
(ja) クエリーにマッチするオブジェクトを全て削除します。
- Parameters:
q (Query) – The query.
- delete_one(q: Query) QueryResult¶
(en) Removes only the first object that matches the query.
(ja) クエリーにマッチするオブジェクトのうち、最初の1つだけを削除します。
- Parameters:
q (Query) – The query.
- classmethod from_dict(src: Dict[str, Any]) Collection¶
(en) Restore this object from the dictionary. Note that src is used as is, not copied.
(ja) このオブジェクトを辞書から復元します。 srcはコピーされずにそのまま利用されることに注意してください。
- Parameters:
src (Dict[str, Any]) – A dictionary made with toDict of this class.
- get_all(q: Query) QueryResult¶
(en) Gets all the contents of the collection. This is useful if you just want to sort the contents. By specifying paging-related parameters, you can easily create paging through all items.
(ja) コレクションの内容を全件取得します。 内容をソートだけしたいような場合に便利です。 ページング関係のパラメータを指定することで、 全アイテムからのページングを簡単に作ることもできます。
- Parameters:
q (Query) – The query.
- property length: int¶
(en) Returns the number of data in the collection.
(ja) コレクションのデータ数を返します。
- notify_listeners()¶
(en) Executes a registered callback.
(ja) 登録済みのコールバックを実行します。
- property raw: List[Dict[str, Any]]¶
(en) Returns the stored contents as a reference list. Be careful as it is dangerous to edit it directly.
(ja) 保持している内容をリストの参照として返します。 直接編集すると危険なため注意してください。
- remove_listener(cb: Callable[[], None], name: str | None = None)¶
(en) This function is used to cancel the set callback. Call it in the UI using dispose etc.
(ja) 設定したコールバックを解除するための関数です。 UIではdisposeなどで呼び出します。
- Parameters:
cb (Callable[[], None]) – The function for which you want to cancel the notification.
name (Optional[str]) – If you registered with a name when you added Listener, you must unregister with the same name.
- rename_field(q: Query) QueryResult¶
(en) Renames the specified key in the database. The operation will fail if the target key does not exist or if you try to change it to an existing key.
(ja) データベースの、指定したキーの名前を変更します。 対象のキーが存在しなかったり、既に存在するキーに変更しようとすると操作は失敗します。
- Parameters:
q (Query) – The query.
- search(q: Query) QueryResult¶
(en) Finds and returns objects that match a query.
(ja) クエリーにマッチするオブジェクトを検索し、返します。
- Parameters:
q (Query) – The query.
- search_one(q: Query) QueryResult¶
(en) Finds and returns objects that match a query. It is faster than a “search query” when searching for a single item because the search stops once a hit is found.
(ja) クエリーにマッチするオブジェクトを検索し、返します。 1件のヒットがあった時点で探索を打ち切るため、 単一のアイテムを検索する場合はsearchよりも高速に動作します。
- Parameters:
q (Query) – The query.
- to_dict() Dict[str, Any]¶
(en) Convert the object to a dictionary. The returned dictionary can only contain primitive types, null, lists or maps with only primitive elements. If you want to include other classes, the target class should inherit from this class and chain calls to_dict.
(ja) このオブジェクトを辞書に変換します。 戻り値の辞書にはプリミティブ型かプリミティブ型要素のみのリスト またはマップ等、そしてNoneのみを含められます。 それ以外のクラスを含めたい場合、対象のクラスもこのクラスを継承し、 to_dictを連鎖的に呼び出すようにしてください。
- update(q: Query, is_single_target: bool) QueryResult¶
(en) Updates the contents of all objects that match the query. Only provided parameters will be overwritten; unprovided parameters will remain unchanged. The parameters directly below will be updated. For example, if the original data is {“a”: 0, “b”: {“c”: 1}}, and you update it by data of {“b”: {“d”: 2}}, the result will be {“a”: 0, “b”: {“d”: 2}}.
(ja) クエリーにマッチする全てのオブジェクトの内容を更新します。 与えたパラメータのみが上書き対象になり、与えなかったパラメータは変化しません。 直下のパラメータが更新対象になるため、 例えば元のデータが {“a” : 0 , “b” : {“c” : 1} }の場合に、 {“b” : {“d” : 2} }で更新すると、 結果は {“a” : 0, “b” : {“d” : 2} } になります。
- Parameters:
q (Query) – The query.
is_single_target (bool) – If true, the target is single object.
- version = '16'¶