jsonjsdb 0.7.2__tar.gz → 0.7.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {jsonjsdb-0.7.2 → jsonjsdb-0.7.4}/PKG-INFO +7 -1
- {jsonjsdb-0.7.2 → jsonjsdb-0.7.4}/README.md +6 -0
- {jsonjsdb-0.7.2 → jsonjsdb-0.7.4}/pyproject.toml +1 -1
- {jsonjsdb-0.7.2 → jsonjsdb-0.7.4}/src/jsonjsdb/database.py +12 -5
- {jsonjsdb-0.7.2 → jsonjsdb-0.7.4}/src/jsonjsdb/evolution.py +1 -3
- {jsonjsdb-0.7.2 → jsonjsdb-0.7.4}/src/jsonjsdb/writer.py +22 -9
- {jsonjsdb-0.7.2 → jsonjsdb-0.7.4}/.gitignore +0 -0
- {jsonjsdb-0.7.2 → jsonjsdb-0.7.4}/LICENSE +0 -0
- {jsonjsdb-0.7.2 → jsonjsdb-0.7.4}/src/jsonjsdb/__init__.py +0 -0
- {jsonjsdb-0.7.2 → jsonjsdb-0.7.4}/src/jsonjsdb/loader.py +0 -0
- {jsonjsdb-0.7.2 → jsonjsdb-0.7.4}/src/jsonjsdb/py.typed +0 -0
- {jsonjsdb-0.7.2 → jsonjsdb-0.7.4}/src/jsonjsdb/table.py +0 -0
- {jsonjsdb-0.7.2 → jsonjsdb-0.7.4}/src/jsonjsdb/types.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: jsonjsdb
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.4
|
|
4
4
|
Summary: Python library for JSONJS database loading
|
|
5
5
|
Project-URL: Homepage, https://github.com/datannur/jsonjsdb
|
|
6
6
|
Project-URL: Repository, https://github.com/datannur/jsonjsdb
|
|
@@ -172,8 +172,14 @@ db.save()
|
|
|
172
172
|
# Disable tracking
|
|
173
173
|
db.save(track_evolution=False)
|
|
174
174
|
|
|
175
|
+
# Skip .json.js files (faster, smaller output)
|
|
176
|
+
db.save(write_js=False)
|
|
177
|
+
|
|
175
178
|
# Use Excel as source (for easy editing of logs)
|
|
176
179
|
db.save(evolution_xlsx=Path("path/to/evolution.xlsx"))
|
|
180
|
+
|
|
181
|
+
# Override timestamp for deterministic outputs (useful for testing)
|
|
182
|
+
db.save(timestamp=1741186800)
|
|
177
183
|
```
|
|
178
184
|
|
|
179
185
|
When `evolution_xlsx` is provided:
|
|
@@ -147,8 +147,14 @@ db.save()
|
|
|
147
147
|
# Disable tracking
|
|
148
148
|
db.save(track_evolution=False)
|
|
149
149
|
|
|
150
|
+
# Skip .json.js files (faster, smaller output)
|
|
151
|
+
db.save(write_js=False)
|
|
152
|
+
|
|
150
153
|
# Use Excel as source (for easy editing of logs)
|
|
151
154
|
db.save(evolution_xlsx=Path("path/to/evolution.xlsx"))
|
|
155
|
+
|
|
156
|
+
# Override timestamp for deterministic outputs (useful for testing)
|
|
157
|
+
db.save(timestamp=1741186800)
|
|
152
158
|
```
|
|
153
159
|
|
|
154
160
|
When `evolution_xlsx` is provided:
|
|
@@ -106,6 +106,8 @@ class Jsonjsdb:
|
|
|
106
106
|
*,
|
|
107
107
|
track_evolution: bool = True,
|
|
108
108
|
evolution_xlsx: Path | str | None = None,
|
|
109
|
+
timestamp: int | None = None,
|
|
110
|
+
write_js: bool = True,
|
|
109
111
|
) -> None:
|
|
110
112
|
"""Save all tables to disk with optional evolution tracking.
|
|
111
113
|
|
|
@@ -116,6 +118,8 @@ class Jsonjsdb:
|
|
|
116
118
|
path: Target directory path (optional if already loaded from path)
|
|
117
119
|
track_evolution: Enable change tracking (default: True)
|
|
118
120
|
evolution_xlsx: Optional path for evolution.xlsx output
|
|
121
|
+
timestamp: Optional timestamp override for deterministic outputs
|
|
122
|
+
write_js: If True, write both .json and .json.js (default: True)
|
|
119
123
|
"""
|
|
120
124
|
save_path = Path(path) if path else self._path
|
|
121
125
|
|
|
@@ -131,7 +135,7 @@ class Jsonjsdb:
|
|
|
131
135
|
self._path is not None and save_path.resolve() == self._path.resolve()
|
|
132
136
|
)
|
|
133
137
|
|
|
134
|
-
|
|
138
|
+
ts = timestamp if timestamp is not None else get_timestamp()
|
|
135
139
|
new_entries: list[EvolutionEntry] = []
|
|
136
140
|
|
|
137
141
|
table_names = []
|
|
@@ -143,11 +147,12 @@ class Jsonjsdb:
|
|
|
143
147
|
# Track evolution if enabled
|
|
144
148
|
if track_evolution:
|
|
145
149
|
old_df = self._get_old_table(save_path, name, same_path)
|
|
146
|
-
entries = compare_datasets(old_df, persistable_df,
|
|
150
|
+
entries = compare_datasets(old_df, persistable_df, ts, name)
|
|
147
151
|
new_entries.extend(entries)
|
|
148
152
|
|
|
149
153
|
write_table_json(persistable_df, save_path / f"{name}.json")
|
|
150
|
-
|
|
154
|
+
if write_js:
|
|
155
|
+
write_table_jsonjs(persistable_df, name, save_path / f"{name}.json.js")
|
|
151
156
|
table_names.append(name)
|
|
152
157
|
|
|
153
158
|
# Update snapshot for next comparison
|
|
@@ -159,10 +164,12 @@ class Jsonjsdb:
|
|
|
159
164
|
existing_entries = load_evolution(save_path, xlsx_path)
|
|
160
165
|
all_entries = existing_entries + new_entries
|
|
161
166
|
save_evolution(all_entries, save_path, xlsx_path)
|
|
162
|
-
if "evolution" not in table_names:
|
|
167
|
+
if "evolution" not in table_names: # pragma: no branch
|
|
163
168
|
table_names.append("evolution")
|
|
164
169
|
|
|
165
|
-
write_table_index(
|
|
170
|
+
write_table_index(
|
|
171
|
+
table_names, save_path / "__table__.json", ts, write_js=write_js
|
|
172
|
+
)
|
|
166
173
|
|
|
167
174
|
self._path = save_path
|
|
168
175
|
|
|
@@ -144,9 +144,7 @@ def compare_datasets(
|
|
|
144
144
|
map_new = _df_to_dict_by_id(new_df)
|
|
145
145
|
|
|
146
146
|
# Determine all variables to compare
|
|
147
|
-
if
|
|
148
|
-
variables = new_df.columns
|
|
149
|
-
elif new_df.is_empty():
|
|
147
|
+
if new_df.is_empty():
|
|
150
148
|
variables = old_df.columns
|
|
151
149
|
else:
|
|
152
150
|
variables = list(set(old_df.columns) | set(new_df.columns))
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import json
|
|
4
4
|
import time
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import Any
|
|
6
|
+
from typing import Any, Optional
|
|
7
7
|
|
|
8
8
|
import polars as pl
|
|
9
9
|
|
|
@@ -33,14 +33,27 @@ def write_table_jsonjs(df: pl.DataFrame, table_name: str, path: Path) -> None:
|
|
|
33
33
|
f.write(content)
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
def write_table_index(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
def write_table_index(
|
|
37
|
+
tables: list[str],
|
|
38
|
+
path: Path,
|
|
39
|
+
timestamp: Optional[int] = None,
|
|
40
|
+
*,
|
|
41
|
+
write_js: bool = True,
|
|
42
|
+
) -> None:
|
|
43
|
+
"""Write __table__.json and optionally __table__.json.js with table metadata.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
tables: List of table names to include
|
|
47
|
+
path: Path to write __table__.json
|
|
48
|
+
timestamp: Optional timestamp override (uses current time if None)
|
|
49
|
+
write_js: If True, also write __table__.json.js (default: True)
|
|
50
|
+
"""
|
|
51
|
+
now = timestamp if timestamp is not None else int(time.time())
|
|
52
|
+
df = pl.DataFrame([{"name": name, "last_modif": now} for name in sorted(tables)])
|
|
53
|
+
|
|
54
|
+
write_table_json(df, path)
|
|
55
|
+
if write_js:
|
|
56
|
+
write_table_jsonjs(df, "__table__", path.with_suffix(".json.js"))
|
|
44
57
|
|
|
45
58
|
|
|
46
59
|
def _prepare_df_for_write(df: pl.DataFrame) -> pl.DataFrame:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|