jsonjsdb 0.7.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jsonjsdb
3
- Version: 0.7.3
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,6 +172,9 @@ 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"))
177
180
 
@@ -147,6 +147,9 @@ 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"))
152
155
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "jsonjsdb"
7
- version = "0.7.3"
7
+ version = "0.7.4"
8
8
  description = "Python library for JSONJS database loading"
9
9
  authors = [{ name = "datannur" }]
10
10
  readme = "README.md"
@@ -107,6 +107,7 @@ class Jsonjsdb:
107
107
  track_evolution: bool = True,
108
108
  evolution_xlsx: Path | str | None = None,
109
109
  timestamp: int | None = None,
110
+ write_js: bool = True,
110
111
  ) -> None:
111
112
  """Save all tables to disk with optional evolution tracking.
112
113
 
@@ -118,6 +119,7 @@ class Jsonjsdb:
118
119
  track_evolution: Enable change tracking (default: True)
119
120
  evolution_xlsx: Optional path for evolution.xlsx output
120
121
  timestamp: Optional timestamp override for deterministic outputs
122
+ write_js: If True, write both .json and .json.js (default: True)
121
123
  """
122
124
  save_path = Path(path) if path else self._path
123
125
 
@@ -149,7 +151,8 @@ class Jsonjsdb:
149
151
  new_entries.extend(entries)
150
152
 
151
153
  write_table_json(persistable_df, save_path / f"{name}.json")
152
- write_table_jsonjs(persistable_df, name, save_path / f"{name}.json.js")
154
+ if write_js:
155
+ write_table_jsonjs(persistable_df, name, save_path / f"{name}.json.js")
153
156
  table_names.append(name)
154
157
 
155
158
  # Update snapshot for next comparison
@@ -161,10 +164,12 @@ class Jsonjsdb:
161
164
  existing_entries = load_evolution(save_path, xlsx_path)
162
165
  all_entries = existing_entries + new_entries
163
166
  save_evolution(all_entries, save_path, xlsx_path)
164
- if "evolution" not in table_names:
167
+ if "evolution" not in table_names: # pragma: no branch
165
168
  table_names.append("evolution")
166
169
 
167
- write_table_index(table_names, save_path / "__table__.json", ts)
170
+ write_table_index(
171
+ table_names, save_path / "__table__.json", ts, write_js=write_js
172
+ )
168
173
 
169
174
  self._path = save_path
170
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 old_df.is_empty():
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))
@@ -34,21 +34,26 @@ def write_table_jsonjs(df: pl.DataFrame, table_name: str, path: Path) -> None:
34
34
 
35
35
 
36
36
  def write_table_index(
37
- tables: list[str], path: Path, timestamp: Optional[int] = None
37
+ tables: list[str],
38
+ path: Path,
39
+ timestamp: Optional[int] = None,
40
+ *,
41
+ write_js: bool = True,
38
42
  ) -> None:
39
- """Write __table__.json with table metadata.
43
+ """Write __table__.json and optionally __table__.json.js with table metadata.
40
44
 
41
45
  Args:
42
46
  tables: List of table names to include
43
47
  path: Path to write __table__.json
44
48
  timestamp: Optional timestamp override (uses current time if None)
49
+ write_js: If True, also write __table__.json.js (default: True)
45
50
  """
46
51
  now = timestamp if timestamp is not None else int(time.time())
47
- entries = [{"name": name, "last_modif": now} for name in sorted(tables)]
52
+ df = pl.DataFrame([{"name": name, "last_modif": now} for name in sorted(tables)])
48
53
 
49
- with open(path, "w") as f:
50
- json.dump(entries, f, indent=2, ensure_ascii=False)
51
- f.write("\n")
54
+ write_table_json(df, path)
55
+ if write_js:
56
+ write_table_jsonjs(df, "__table__", path.with_suffix(".json.js"))
52
57
 
53
58
 
54
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