JSONFileStorage
hololinked.storage.JSONFileStorage
Bases: BaseConfigurationRepository
JSON file based storage engine composed within Thing.
Carries out property operations such as storing and retrieving values from a plain JSON file.
Source code in repo/hololinked/hololinked/storage/jsonfile.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
Attributes
Functions
__init__
Initialize JSONFileStorage for a Thing instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Thing
|
The |
required |
|
str
|
Path to the JSON file to use for storage. |
required |
|
BaseSerializer | None
|
Serializer for encoding and decoding JSON data. Defaults to an instance of |
None
|
Source code in repo/hololinked/hololinked/storage/jsonfile.py
from_thing
classmethod
Build the JSON file storage for a Thing, deriving the file name from its ID if none was given.
The file always lives under global_config.TEMP_DIR_DB, so a relative json_filename cannot escape it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Thing
|
the |
required |
|
Any
|
the keyword arguments given to the |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
the storage engine, with the file loaded if it already exists |
Source code in repo/hololinked/hololinked/storage/jsonfile.py
get_property
Fetch a single property value from the JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Property
|
string name or descriptor object |
required |
|
Ignored for this storage engine since JSON file storage is always deserialized. Included for interface compatibility. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
property value |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the property is not found in storage. |
Source code in repo/hololinked/hololinked/storage/jsonfile.py
get_properties
Get multiple properties at once from the JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str | Property, Any]
|
string names or the descriptor of the properties as a list |
required |
|
Ignored for this storage engine since JSON file storage is always deserialized. Included for interface compatibility. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
property names and values as items |
Source code in repo/hololinked/hololinked/storage/jsonfile.py
get_all_properties
Get all properties stored in the JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Ignored for this storage engine since JSON file storage is always deserialized. Included for interface compatibility. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
property names and values as items |
Source code in repo/hololinked/hololinked/storage/jsonfile.py
set_property
Change the value of an already existing property in the JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Property
|
string name or descriptor object |
required |
|
Any
|
value of the property |
required |
Source code in repo/hololinked/hololinked/storage/jsonfile.py
set_properties
Change the values of already existing properties at once in the JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str | Property, Any]
|
string names or the descriptor of the property and any value as dictionary pairs |
required |
Source code in repo/hololinked/hololinked/storage/jsonfile.py
create_missing_properties
create_missing_properties(properties: dict[str, Property], get_missing_property_names: bool = False) -> list[str] | None
Create any and all missing properties in the JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, Property]
|
descriptors of the properties |
required |
|
bool
|
whether to return the list of missing property names |
False
|
Returns:
| Type | Description |
|---|---|
List[str]
|
list of missing properties if get_missing_property_names is True |