tigrbl_engine_xlsx 0.1.1.dev1__py3-none-any.whl
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.
- tigrbl_engine_xlsx/__init__.py +19 -0
- tigrbl_engine_xlsx/engine.py +102 -0
- tigrbl_engine_xlsx/session.py +501 -0
- tigrbl_engine_xlsx-0.1.1.dev1.dist-info/METADATA +277 -0
- tigrbl_engine_xlsx-0.1.1.dev1.dist-info/RECORD +8 -0
- tigrbl_engine_xlsx-0.1.1.dev1.dist-info/WHEEL +4 -0
- tigrbl_engine_xlsx-0.1.1.dev1.dist-info/entry_points.txt +2 -0
- tigrbl_engine_xlsx-0.1.1.dev1.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from .engine import WorkbookCatalog, XlsxEngine, xlsx_capabilities, xlsx_engine
|
|
2
|
+
from .session import XlsxSession
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def register() -> None:
|
|
6
|
+
"""Entry-point hook invoked by tigrbl to register this engine."""
|
|
7
|
+
from tigrbl.engine.registry import register_engine
|
|
8
|
+
|
|
9
|
+
register_engine("xlsx", build=xlsx_engine, capabilities=xlsx_capabilities)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"WorkbookCatalog",
|
|
14
|
+
"XlsxEngine",
|
|
15
|
+
"XlsxSession",
|
|
16
|
+
"xlsx_engine",
|
|
17
|
+
"xlsx_capabilities",
|
|
18
|
+
"register",
|
|
19
|
+
]
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import threading
|
|
6
|
+
from typing import Any, Callable
|
|
7
|
+
|
|
8
|
+
from openpyxl import load_workbook
|
|
9
|
+
from openpyxl.workbook import Workbook
|
|
10
|
+
|
|
11
|
+
from .session import XlsxSession
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass
|
|
15
|
+
class WorkbookCatalog:
|
|
16
|
+
workbook: Workbook
|
|
17
|
+
path: str
|
|
18
|
+
tables: dict[str, list[dict[str, Any]]] = field(default_factory=dict)
|
|
19
|
+
pks: dict[str, str] = field(default_factory=dict)
|
|
20
|
+
table_ver: dict[str, int] = field(default_factory=dict)
|
|
21
|
+
lock: threading.RLock = field(default_factory=threading.RLock)
|
|
22
|
+
|
|
23
|
+
def get_live(self, name: str) -> list[dict[str, Any]]:
|
|
24
|
+
if name not in self.tables:
|
|
25
|
+
self.tables[name] = []
|
|
26
|
+
self.table_ver[name] = 0
|
|
27
|
+
self.pks.setdefault(name, "id")
|
|
28
|
+
self.table_ver.setdefault(name, 0)
|
|
29
|
+
return self.tables[name]
|
|
30
|
+
|
|
31
|
+
def bump(self, name: str) -> None:
|
|
32
|
+
self.table_ver[name] = self.table_ver.get(name, 0) + 1
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _sheet_to_rows(workbook: Workbook, sheet_name: str) -> list[dict[str, Any]]:
|
|
36
|
+
sheet = workbook[sheet_name]
|
|
37
|
+
values = list(sheet.iter_rows(values_only=True))
|
|
38
|
+
if not values:
|
|
39
|
+
return []
|
|
40
|
+
headers = [str(col) if col is not None else "" for col in values[0]]
|
|
41
|
+
rows: list[dict[str, Any]] = []
|
|
42
|
+
for row_values in values[1:]:
|
|
43
|
+
row = {
|
|
44
|
+
header: value
|
|
45
|
+
for header, value in zip(headers, row_values, strict=False)
|
|
46
|
+
if header
|
|
47
|
+
}
|
|
48
|
+
if any(value is not None for value in row.values()):
|
|
49
|
+
rows.append(row)
|
|
50
|
+
return rows
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@dataclass
|
|
54
|
+
class XlsxEngine:
|
|
55
|
+
"""Workbook-backed engine: workbook as DB, sheet names as tables."""
|
|
56
|
+
|
|
57
|
+
path: str
|
|
58
|
+
pk: str
|
|
59
|
+
workbook: Workbook
|
|
60
|
+
catalog: WorkbookCatalog
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def xlsx_engine(
|
|
64
|
+
*, mapping: dict[str, Any] | None = None, **_: Any
|
|
65
|
+
) -> tuple[XlsxEngine, Callable[[], XlsxSession]]:
|
|
66
|
+
config = dict(mapping or {})
|
|
67
|
+
path_value = config.get("path") or config.get("file")
|
|
68
|
+
if not isinstance(path_value, str) or not path_value:
|
|
69
|
+
raise TypeError("mapping['path'] (or 'file') must be a non-empty string")
|
|
70
|
+
path = str(Path(path_value))
|
|
71
|
+
|
|
72
|
+
pk = config.get("pk", "id")
|
|
73
|
+
if not isinstance(pk, str) or not pk:
|
|
74
|
+
raise TypeError("mapping['pk'] must be a non-empty string")
|
|
75
|
+
|
|
76
|
+
workbook = load_workbook(path)
|
|
77
|
+
if not workbook.sheetnames:
|
|
78
|
+
raise ValueError("workbook must contain at least one sheet")
|
|
79
|
+
|
|
80
|
+
catalog = WorkbookCatalog(
|
|
81
|
+
workbook=workbook,
|
|
82
|
+
path=path,
|
|
83
|
+
tables={name: _sheet_to_rows(workbook, name) for name in workbook.sheetnames},
|
|
84
|
+
pks={name: pk for name in workbook.sheetnames},
|
|
85
|
+
)
|
|
86
|
+
engine = XlsxEngine(path=path, pk=pk, workbook=workbook, catalog=catalog)
|
|
87
|
+
|
|
88
|
+
def session_factory() -> XlsxSession:
|
|
89
|
+
return XlsxSession(catalog)
|
|
90
|
+
|
|
91
|
+
return engine, session_factory
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def xlsx_capabilities() -> dict[str, object]:
|
|
95
|
+
return {
|
|
96
|
+
"files": ["xlsx"],
|
|
97
|
+
"workbook_database": True,
|
|
98
|
+
"multi_table": True,
|
|
99
|
+
"workbook_api": ["load_workbook", "wb[...]", "wb.save(...)"],
|
|
100
|
+
"transactions": True,
|
|
101
|
+
"dialect": "xlsx",
|
|
102
|
+
}
|
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import tempfile
|
|
5
|
+
|
|
6
|
+
from typing import (
|
|
7
|
+
TYPE_CHECKING,
|
|
8
|
+
Any,
|
|
9
|
+
Callable,
|
|
10
|
+
Dict,
|
|
11
|
+
List,
|
|
12
|
+
Mapping,
|
|
13
|
+
Optional,
|
|
14
|
+
Sequence,
|
|
15
|
+
Tuple,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
from openpyxl.worksheet.worksheet import Worksheet
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
from tigrbl.session.base import TigrblSessionBase
|
|
22
|
+
except Exception:
|
|
23
|
+
from abc import ABC, abstractmethod
|
|
24
|
+
|
|
25
|
+
class TigrblSessionBase(ABC): # pragma: no cover - fallback
|
|
26
|
+
def __init__(self, spec=None):
|
|
27
|
+
self._spec = spec
|
|
28
|
+
|
|
29
|
+
@abstractmethod
|
|
30
|
+
def _add_impl(self, obj): ...
|
|
31
|
+
|
|
32
|
+
@abstractmethod
|
|
33
|
+
async def _delete_impl(self, obj): ...
|
|
34
|
+
|
|
35
|
+
@abstractmethod
|
|
36
|
+
async def _flush_impl(self): ...
|
|
37
|
+
|
|
38
|
+
@abstractmethod
|
|
39
|
+
async def _refresh_impl(self, obj): ...
|
|
40
|
+
|
|
41
|
+
@abstractmethod
|
|
42
|
+
async def _get_impl(self, model, ident): ...
|
|
43
|
+
|
|
44
|
+
@abstractmethod
|
|
45
|
+
async def _execute_impl(self, stmt): ...
|
|
46
|
+
|
|
47
|
+
@abstractmethod
|
|
48
|
+
async def _tx_begin_impl(self): ...
|
|
49
|
+
|
|
50
|
+
@abstractmethod
|
|
51
|
+
async def _tx_commit_impl(self): ...
|
|
52
|
+
|
|
53
|
+
@abstractmethod
|
|
54
|
+
async def _tx_rollback_impl(self): ...
|
|
55
|
+
|
|
56
|
+
@abstractmethod
|
|
57
|
+
async def _close_impl(self): ...
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
try:
|
|
61
|
+
from tigrbl.session.spec import SessionSpec
|
|
62
|
+
except Exception:
|
|
63
|
+
|
|
64
|
+
class SessionSpec: # pragma: no cover - fallback
|
|
65
|
+
def __init__(self, isolation=None, read_only=None):
|
|
66
|
+
self.isolation = isolation
|
|
67
|
+
self.read_only = read_only
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
try:
|
|
71
|
+
from tigrbl.core.crud.helpers.model import _single_pk_name, _model_columns
|
|
72
|
+
except Exception:
|
|
73
|
+
|
|
74
|
+
def _single_pk_name(model): # pragma: no cover - fallback
|
|
75
|
+
return "id"
|
|
76
|
+
|
|
77
|
+
def _model_columns(model): # pragma: no cover - fallback
|
|
78
|
+
return getattr(model, "__annotations__", {}) or {"id": int}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
try:
|
|
82
|
+
from tigrbl.core.crud.helpers import NoResultFound
|
|
83
|
+
except Exception:
|
|
84
|
+
|
|
85
|
+
class NoResultFound(Exception):
|
|
86
|
+
pass
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
if TYPE_CHECKING:
|
|
90
|
+
from .engine import WorkbookCatalog
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class _ScalarResult:
|
|
94
|
+
def __init__(self, items: Sequence[Any]) -> None:
|
|
95
|
+
self._items = list(items)
|
|
96
|
+
|
|
97
|
+
def scalars(self) -> "_ScalarResult":
|
|
98
|
+
return self
|
|
99
|
+
|
|
100
|
+
def all(self) -> List[Any]:
|
|
101
|
+
return list(self._items)
|
|
102
|
+
|
|
103
|
+
def scalar_one(self) -> Any:
|
|
104
|
+
if len(self._items) != 1:
|
|
105
|
+
raise NoResultFound("expected exactly one row")
|
|
106
|
+
return self._items[0]
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class _ExecuteResult(_ScalarResult):
|
|
110
|
+
rowcount: int = 0
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class XlsxSession(TigrblSessionBase):
|
|
114
|
+
"""Native transaction session over workbook sheets as tables."""
|
|
115
|
+
|
|
116
|
+
def __init__(
|
|
117
|
+
self, catalog: "WorkbookCatalog", spec: Optional[SessionSpec] = None
|
|
118
|
+
) -> None:
|
|
119
|
+
super().__init__(spec)
|
|
120
|
+
self._cat = catalog
|
|
121
|
+
self._snap: Dict[str, list[dict[str, Any]]] = {}
|
|
122
|
+
self._snap_ver: Dict[str, int] = {}
|
|
123
|
+
self._puts: Dict[Tuple[type, Any], Dict[str, Any]] = {}
|
|
124
|
+
self._dels: set[Tuple[type, Any]] = set()
|
|
125
|
+
|
|
126
|
+
def workbook(self):
|
|
127
|
+
return self._cat.workbook
|
|
128
|
+
|
|
129
|
+
def sheet(self, name: str) -> Worksheet:
|
|
130
|
+
return self._cat.workbook[name]
|
|
131
|
+
|
|
132
|
+
def table(self, name: str) -> list[dict[str, Any]]:
|
|
133
|
+
return [dict(row) for row in self._cat.get_live(name)]
|
|
134
|
+
|
|
135
|
+
async def run_sync(self, fn: Callable[[Any], Any]) -> Any:
|
|
136
|
+
out = fn(self)
|
|
137
|
+
return await out if hasattr(out, "__await__") else out
|
|
138
|
+
|
|
139
|
+
async def _tx_begin_impl(self) -> None:
|
|
140
|
+
self._snap.clear()
|
|
141
|
+
self._snap_ver.clear()
|
|
142
|
+
self._puts.clear()
|
|
143
|
+
self._dels.clear()
|
|
144
|
+
|
|
145
|
+
async def _tx_commit_impl(self) -> None:
|
|
146
|
+
iso = (self._spec.isolation if self._spec else None) or "read_committed"
|
|
147
|
+
if iso in ("repeatable_read", "snapshot", "serializable"):
|
|
148
|
+
for table, version in self._snap_ver.items():
|
|
149
|
+
if self._cat.table_ver.get(table, 0) != version:
|
|
150
|
+
raise RuntimeError(f"transaction conflict on table '{table}'")
|
|
151
|
+
|
|
152
|
+
with self._cat.lock:
|
|
153
|
+
dels_by_table: Dict[str, List[Any]] = {}
|
|
154
|
+
for model, ident in self._dels:
|
|
155
|
+
dels_by_table.setdefault(self._table(model), []).append(ident)
|
|
156
|
+
for table, idents in dels_by_table.items():
|
|
157
|
+
pk = self._pk_of(table)
|
|
158
|
+
live = self._cat.get_live(table)
|
|
159
|
+
self._cat.tables[table] = [
|
|
160
|
+
row for row in live if row.get(pk) not in idents
|
|
161
|
+
]
|
|
162
|
+
self._cat.bump(table)
|
|
163
|
+
|
|
164
|
+
puts_by_table: Dict[str, List[Dict[str, Any]]] = {}
|
|
165
|
+
for (model, _), row in self._puts.items():
|
|
166
|
+
puts_by_table.setdefault(self._table(model), []).append(dict(row))
|
|
167
|
+
for table, rows in puts_by_table.items():
|
|
168
|
+
pk = self._pk_of(table)
|
|
169
|
+
live = self._cat.get_live(table)
|
|
170
|
+
live_by_pk = {row.get(pk): dict(row) for row in live}
|
|
171
|
+
for row in rows:
|
|
172
|
+
if pk not in row:
|
|
173
|
+
raise RuntimeError(f"missing pk '{pk}' for table '{table}'")
|
|
174
|
+
live_by_pk[row[pk]] = row
|
|
175
|
+
self._cat.tables[table] = list(live_by_pk.values())
|
|
176
|
+
self._cat.bump(table)
|
|
177
|
+
|
|
178
|
+
self._persist_workbook()
|
|
179
|
+
|
|
180
|
+
self._puts.clear()
|
|
181
|
+
self._dels.clear()
|
|
182
|
+
|
|
183
|
+
async def _tx_rollback_impl(self) -> None:
|
|
184
|
+
self._snap.clear()
|
|
185
|
+
self._snap_ver.clear()
|
|
186
|
+
self._puts.clear()
|
|
187
|
+
self._dels.clear()
|
|
188
|
+
|
|
189
|
+
def _add_impl(self, obj: Any) -> Any:
|
|
190
|
+
model = obj.__class__
|
|
191
|
+
pk = _single_pk_name(model)
|
|
192
|
+
ident = getattr(obj, pk)
|
|
193
|
+
if ident is None:
|
|
194
|
+
raise ValueError(f"primary key {pk!r} must be set")
|
|
195
|
+
row = {column: getattr(obj, column, None) for column in _model_columns(model)}
|
|
196
|
+
self._puts[(model, ident)] = row
|
|
197
|
+
self._dels.discard((model, ident))
|
|
198
|
+
return None
|
|
199
|
+
|
|
200
|
+
async def _delete_impl(self, obj: Any) -> None:
|
|
201
|
+
model = obj.__class__
|
|
202
|
+
pk = _single_pk_name(model)
|
|
203
|
+
ident = getattr(obj, pk)
|
|
204
|
+
self._puts.pop((model, ident), None)
|
|
205
|
+
self._dels.add((model, ident))
|
|
206
|
+
|
|
207
|
+
async def _flush_impl(self) -> None:
|
|
208
|
+
return
|
|
209
|
+
|
|
210
|
+
async def _refresh_impl(self, obj: Any) -> None:
|
|
211
|
+
pk = _single_pk_name(obj.__class__)
|
|
212
|
+
ident = getattr(obj, pk)
|
|
213
|
+
fresh = await self._get_impl(obj.__class__, ident)
|
|
214
|
+
if fresh is None:
|
|
215
|
+
return
|
|
216
|
+
for column in _model_columns(obj.__class__):
|
|
217
|
+
setattr(obj, column, getattr(fresh, column, None))
|
|
218
|
+
|
|
219
|
+
async def _get_impl(self, model: type, ident: Any) -> Any | None:
|
|
220
|
+
row = self._puts.get((model, ident))
|
|
221
|
+
if row is not None:
|
|
222
|
+
return self._inflate(model, row)
|
|
223
|
+
if (model, ident) in self._dels:
|
|
224
|
+
return None
|
|
225
|
+
table_rows = self._rows_for(model)
|
|
226
|
+
pk = _single_pk_name(model)
|
|
227
|
+
for table_row in table_rows:
|
|
228
|
+
if table_row.get(pk) == ident:
|
|
229
|
+
return self._inflate(model, table_row)
|
|
230
|
+
return None
|
|
231
|
+
|
|
232
|
+
async def _execute_impl(self, stmt: Any) -> Any:
|
|
233
|
+
kind = type(stmt).__name__.lower()
|
|
234
|
+
if "select" in kind:
|
|
235
|
+
model, where, order, limit, offset = self._decompose_select(stmt)
|
|
236
|
+
items = self._scan_model(model)
|
|
237
|
+
items = [obj for obj in items if self._matches_obj(obj, where)]
|
|
238
|
+
return _ExecuteResult(self._order_slice(items, order, limit, offset))
|
|
239
|
+
if "delete" in kind:
|
|
240
|
+
model, where = self._decompose_delete(stmt)
|
|
241
|
+
items = self._scan_model(model)
|
|
242
|
+
items = [obj for obj in items if self._matches_obj(obj, where)]
|
|
243
|
+
for obj in items:
|
|
244
|
+
pk = _single_pk_name(model)
|
|
245
|
+
ident = getattr(obj, pk)
|
|
246
|
+
self._puts.pop((model, ident), None)
|
|
247
|
+
self._dels.add((model, ident))
|
|
248
|
+
result = _ExecuteResult([])
|
|
249
|
+
result.rowcount = len(items)
|
|
250
|
+
return result
|
|
251
|
+
raise NotImplementedError(f"Unsupported statement: {type(stmt)}")
|
|
252
|
+
|
|
253
|
+
async def _close_impl(self) -> None:
|
|
254
|
+
return
|
|
255
|
+
|
|
256
|
+
def _table(self, model: type) -> str:
|
|
257
|
+
return getattr(model, "__tablename__", None) or model.__name__
|
|
258
|
+
|
|
259
|
+
def _pk_of(self, table: str) -> str:
|
|
260
|
+
if table in self._cat.pks:
|
|
261
|
+
return self._cat.pks[table]
|
|
262
|
+
raise RuntimeError(f"primary key for table '{table}' is unknown")
|
|
263
|
+
|
|
264
|
+
def _rows_for(self, model: type) -> list[dict[str, Any]]:
|
|
265
|
+
table = self._table(model)
|
|
266
|
+
iso = (self._spec.isolation if self._spec else None) or "read_committed"
|
|
267
|
+
if (
|
|
268
|
+
iso in ("repeatable_read", "snapshot", "serializable")
|
|
269
|
+
and table not in self._snap
|
|
270
|
+
):
|
|
271
|
+
live = self._cat.get_live(table)
|
|
272
|
+
self._snap[table] = [dict(row) for row in live]
|
|
273
|
+
self._snap_ver[table] = self._cat.table_ver.get(table, 0)
|
|
274
|
+
return self._snap.get(table, self._cat.get_live(table))
|
|
275
|
+
|
|
276
|
+
def _inflate(self, model: type, data: Mapping[str, Any]) -> Any:
|
|
277
|
+
obj = model()
|
|
278
|
+
for column in _model_columns(model):
|
|
279
|
+
if column in data:
|
|
280
|
+
setattr(obj, column, data[column])
|
|
281
|
+
return obj
|
|
282
|
+
|
|
283
|
+
def _scan_model(self, model: type) -> List[Any]:
|
|
284
|
+
out = [self._inflate(model, row) for row in self._rows_for(model)]
|
|
285
|
+
pk = _single_pk_name(model)
|
|
286
|
+
by_id = {getattr(obj, pk): obj for obj in out}
|
|
287
|
+
for (known_model, ident), row in self._puts.items():
|
|
288
|
+
if known_model is model:
|
|
289
|
+
by_id[ident] = self._inflate(model, row)
|
|
290
|
+
for known_model, ident in self._dels:
|
|
291
|
+
if known_model is model:
|
|
292
|
+
by_id.pop(ident, None)
|
|
293
|
+
return list(by_id.values())
|
|
294
|
+
|
|
295
|
+
def _persist_workbook(self) -> None:
|
|
296
|
+
workbook = self._cat.workbook
|
|
297
|
+
for table, rows in self._cat.tables.items():
|
|
298
|
+
if table in workbook.sheetnames:
|
|
299
|
+
sheet = workbook[table]
|
|
300
|
+
sheet.delete_rows(1, sheet.max_row)
|
|
301
|
+
else:
|
|
302
|
+
sheet = workbook.create_sheet(table)
|
|
303
|
+
columns: list[str] = []
|
|
304
|
+
for row in rows:
|
|
305
|
+
for key in row:
|
|
306
|
+
if key not in columns:
|
|
307
|
+
columns.append(key)
|
|
308
|
+
if not columns:
|
|
309
|
+
columns = [self._pk_of(table)]
|
|
310
|
+
sheet.append(columns)
|
|
311
|
+
for row in rows:
|
|
312
|
+
sheet.append([row.get(col) for col in columns])
|
|
313
|
+
self._atomic_save_workbook(workbook, self._cat.path)
|
|
314
|
+
|
|
315
|
+
def _atomic_save_workbook(self, workbook: Any, path: str) -> None:
|
|
316
|
+
directory = os.path.dirname(path) or "."
|
|
317
|
+
fd, tmp = tempfile.mkstemp(dir=directory, prefix=".tmp_", suffix=".xlsx")
|
|
318
|
+
os.close(fd)
|
|
319
|
+
try:
|
|
320
|
+
workbook.save(tmp)
|
|
321
|
+
os.replace(tmp, path)
|
|
322
|
+
finally:
|
|
323
|
+
if os.path.exists(tmp):
|
|
324
|
+
os.remove(tmp)
|
|
325
|
+
|
|
326
|
+
def _decompose_select(
|
|
327
|
+
self, stmt: Any
|
|
328
|
+
) -> Tuple[
|
|
329
|
+
type,
|
|
330
|
+
list[Tuple[str, str, Any]],
|
|
331
|
+
list[Tuple[str, str]],
|
|
332
|
+
Optional[int],
|
|
333
|
+
Optional[int],
|
|
334
|
+
]:
|
|
335
|
+
return (
|
|
336
|
+
self._extract_model(stmt),
|
|
337
|
+
self._extract_predicates(stmt),
|
|
338
|
+
self._extract_order_by(stmt),
|
|
339
|
+
self._extract_int(stmt, ["_limit", "_limit_clause", "limit"]),
|
|
340
|
+
self._extract_int(stmt, ["_offset", "_offset_clause", "offset"]),
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
def _decompose_delete(self, stmt: Any) -> Tuple[type, list[Tuple[str, str, Any]]]:
|
|
344
|
+
return self._extract_model(stmt), self._extract_predicates(stmt)
|
|
345
|
+
|
|
346
|
+
def _extract_model(self, stmt: Any) -> type:
|
|
347
|
+
descs = getattr(stmt, "column_descriptions", None) or []
|
|
348
|
+
for desc in descs:
|
|
349
|
+
entity = desc.get("entity") if isinstance(desc, dict) else None
|
|
350
|
+
if isinstance(entity, type):
|
|
351
|
+
return entity
|
|
352
|
+
|
|
353
|
+
def _all_subclasses(base: type) -> list[type]:
|
|
354
|
+
out: list[type] = []
|
|
355
|
+
stack = list(base.__subclasses__())
|
|
356
|
+
while stack:
|
|
357
|
+
cls = stack.pop()
|
|
358
|
+
out.append(cls)
|
|
359
|
+
stack.extend(cls.__subclasses__())
|
|
360
|
+
return out
|
|
361
|
+
|
|
362
|
+
def _find_by_table(name: str) -> type | None:
|
|
363
|
+
for cls in _all_subclasses(object):
|
|
364
|
+
if getattr(cls, "__tablename__", None) == name:
|
|
365
|
+
return cls
|
|
366
|
+
return None
|
|
367
|
+
|
|
368
|
+
for attr_name in ("_from_objects", "_froms", "froms"):
|
|
369
|
+
value = getattr(stmt, attr_name, None)
|
|
370
|
+
if value is not None:
|
|
371
|
+
if isinstance(value, (list, tuple)) and not value:
|
|
372
|
+
continue
|
|
373
|
+
table = value[0] if isinstance(value, (list, tuple)) else value
|
|
374
|
+
name = getattr(table, "name", None)
|
|
375
|
+
if isinstance(name, str):
|
|
376
|
+
found = _find_by_table(name)
|
|
377
|
+
if found is not None:
|
|
378
|
+
return found
|
|
379
|
+
table = getattr(stmt, "table", None)
|
|
380
|
+
name = getattr(table, "name", None)
|
|
381
|
+
if isinstance(name, str):
|
|
382
|
+
found = _find_by_table(name)
|
|
383
|
+
if found is not None:
|
|
384
|
+
return found
|
|
385
|
+
|
|
386
|
+
rc = getattr(stmt, "_raw_columns", None) or getattr(stmt, "columns", None)
|
|
387
|
+
if rc is not None:
|
|
388
|
+
if isinstance(rc, (list, tuple)) and not rc:
|
|
389
|
+
raise RuntimeError("Cannot resolve model from statement")
|
|
390
|
+
entity = rc[0]
|
|
391
|
+
table = getattr(entity, "table", None)
|
|
392
|
+
name = getattr(table, "name", None)
|
|
393
|
+
if isinstance(name, str):
|
|
394
|
+
found = _find_by_table(name)
|
|
395
|
+
if found is not None:
|
|
396
|
+
return found
|
|
397
|
+
raise RuntimeError("Cannot resolve model from statement")
|
|
398
|
+
|
|
399
|
+
def _extract_predicates(self, stmt: Any) -> list[Tuple[str, str, Any]]:
|
|
400
|
+
where = getattr(stmt, "whereclause", None) or getattr(
|
|
401
|
+
stmt, "_whereclause", None
|
|
402
|
+
)
|
|
403
|
+
if where is None:
|
|
404
|
+
return []
|
|
405
|
+
parts = (
|
|
406
|
+
getattr(where, "clauses", None)
|
|
407
|
+
or getattr(where, "get_children", lambda: [])()
|
|
408
|
+
)
|
|
409
|
+
nodes = list(parts) if parts else [where]
|
|
410
|
+
out: list[Tuple[str, str, Any]] = []
|
|
411
|
+
for node in nodes:
|
|
412
|
+
left = getattr(node, "left", None)
|
|
413
|
+
right = getattr(node, "right", None)
|
|
414
|
+
op = getattr(node, "operator", None)
|
|
415
|
+
if left is None or right is None:
|
|
416
|
+
continue
|
|
417
|
+
name = getattr(left, "key", None) or getattr(left, "name", None)
|
|
418
|
+
if name is None:
|
|
419
|
+
continue
|
|
420
|
+
opname = getattr(op, "__name__", str(op))
|
|
421
|
+
if "eq" in opname:
|
|
422
|
+
value = (
|
|
423
|
+
getattr(right, "value", None)
|
|
424
|
+
if hasattr(right, "value")
|
|
425
|
+
else getattr(right, "literal", None)
|
|
426
|
+
)
|
|
427
|
+
out.append((str(name), "eq", value))
|
|
428
|
+
continue
|
|
429
|
+
right_clauses = getattr(right, "clauses", None)
|
|
430
|
+
if right_clauses is not None and "in" in opname:
|
|
431
|
+
vals = [
|
|
432
|
+
getattr(lit, "value", None)
|
|
433
|
+
if hasattr(lit, "value")
|
|
434
|
+
else getattr(lit, "literal", None)
|
|
435
|
+
for lit in right_clauses
|
|
436
|
+
]
|
|
437
|
+
out.append((str(name), "in", vals))
|
|
438
|
+
return out
|
|
439
|
+
|
|
440
|
+
def _extract_order_by(self, stmt: Any) -> list[Tuple[str, str]]:
|
|
441
|
+
order = getattr(stmt, "_order_by_clause", None)
|
|
442
|
+
if order is None:
|
|
443
|
+
order = getattr(stmt, "_order_by_clauses", None)
|
|
444
|
+
if order is None:
|
|
445
|
+
return []
|
|
446
|
+
clauses = getattr(order, "clauses", None) or order
|
|
447
|
+
clauses = clauses if isinstance(clauses, (list, tuple)) else [clauses]
|
|
448
|
+
for ob in clauses:
|
|
449
|
+
col = (
|
|
450
|
+
getattr(ob, "element", None)
|
|
451
|
+
or getattr(ob, "this", None)
|
|
452
|
+
or getattr(ob, "expr", None)
|
|
453
|
+
)
|
|
454
|
+
name = getattr(col, "key", None) or getattr(col, "name", None)
|
|
455
|
+
direction = "desc" if "desc" in type(ob).__name__.lower() else "asc"
|
|
456
|
+
if name:
|
|
457
|
+
return [(str(name), direction)]
|
|
458
|
+
return []
|
|
459
|
+
|
|
460
|
+
def _extract_int(self, stmt: Any, names: Sequence[str]) -> Optional[int]:
|
|
461
|
+
for name in names:
|
|
462
|
+
value = getattr(stmt, name, None)
|
|
463
|
+
if value is None:
|
|
464
|
+
continue
|
|
465
|
+
try:
|
|
466
|
+
return int(value)
|
|
467
|
+
except Exception:
|
|
468
|
+
lit = getattr(value, "value", None)
|
|
469
|
+
if lit is not None:
|
|
470
|
+
try:
|
|
471
|
+
return int(lit)
|
|
472
|
+
except Exception:
|
|
473
|
+
pass
|
|
474
|
+
return None
|
|
475
|
+
|
|
476
|
+
def _matches_obj(self, obj: Any, where: list[Tuple[str, str, Any]]) -> bool:
|
|
477
|
+
for name, op, value in where:
|
|
478
|
+
datum = getattr(obj, name, None)
|
|
479
|
+
if op == "eq" and datum != value:
|
|
480
|
+
return False
|
|
481
|
+
if op == "in" and datum not in set(value):
|
|
482
|
+
return False
|
|
483
|
+
return True
|
|
484
|
+
|
|
485
|
+
def _order_slice(
|
|
486
|
+
self,
|
|
487
|
+
items: List[Any],
|
|
488
|
+
order: list[Tuple[str, str]],
|
|
489
|
+
limit: Optional[int],
|
|
490
|
+
offset: Optional[int],
|
|
491
|
+
) -> List[Any]:
|
|
492
|
+
if order:
|
|
493
|
+
col, direction = order[0]
|
|
494
|
+
items.sort(
|
|
495
|
+
key=lambda obj: getattr(obj, col, None), reverse=(direction == "desc")
|
|
496
|
+
)
|
|
497
|
+
if isinstance(offset, int):
|
|
498
|
+
items = items[max(0, offset) :]
|
|
499
|
+
if isinstance(limit, int):
|
|
500
|
+
items = items[: max(0, limit)]
|
|
501
|
+
return items
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tigrbl_engine_xlsx
|
|
3
|
+
Version: 0.1.1.dev1
|
|
4
|
+
Summary: XLSX engine plugin for tigrbl where each workbook is a database and each sheet is a table.
|
|
5
|
+
Project-URL: Homepage, https://github.com/swarmauri/swarmauri-sdk
|
|
6
|
+
Author-email: Jacob Stewart <jacob@swarmauri.com>
|
|
7
|
+
License: Apache License
|
|
8
|
+
Version 2.0, January 2004
|
|
9
|
+
http://www.apache.org/licenses/
|
|
10
|
+
|
|
11
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
12
|
+
|
|
13
|
+
1. Definitions.
|
|
14
|
+
|
|
15
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
16
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
17
|
+
|
|
18
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
19
|
+
the copyright owner that is granting the License.
|
|
20
|
+
|
|
21
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
22
|
+
other entities that control, are controlled by, or are under common
|
|
23
|
+
control with that entity. For the purposes of this definition,
|
|
24
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
25
|
+
direction or management of such entity, whether by contract or
|
|
26
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
27
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
28
|
+
|
|
29
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
30
|
+
exercising permissions granted by this License.
|
|
31
|
+
|
|
32
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
33
|
+
including but not limited to software source code, documentation
|
|
34
|
+
source, and configuration files.
|
|
35
|
+
|
|
36
|
+
"Object" form shall mean any form resulting from mechanical
|
|
37
|
+
transformation or translation of a Source form, including but
|
|
38
|
+
not limited to compiled object code, generated documentation,
|
|
39
|
+
and conversions to other media types.
|
|
40
|
+
|
|
41
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
42
|
+
Object form, made available under the License, as indicated by a
|
|
43
|
+
copyright notice that is included in or attached to the work
|
|
44
|
+
(an example is provided in the Appendix below).
|
|
45
|
+
|
|
46
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
47
|
+
form, that is based on (or derived from) the Work and for which the
|
|
48
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
49
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
50
|
+
of this License, Derivative Works shall not include works that remain
|
|
51
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
52
|
+
the Work and Derivative Works thereof.
|
|
53
|
+
|
|
54
|
+
"Contribution" shall mean any work of authorship, including
|
|
55
|
+
the original version of the Work and any modifications or additions
|
|
56
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
57
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
58
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
59
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
60
|
+
means any form of electronic, verbal, or written communication sent
|
|
61
|
+
to the Licensor or its representatives, including but not limited to
|
|
62
|
+
communication on electronic mailing lists, source code control systems,
|
|
63
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
64
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
65
|
+
excluding communication that is conspicuously marked or otherwise
|
|
66
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
67
|
+
|
|
68
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
69
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
70
|
+
subsequently incorporated within the Work.
|
|
71
|
+
|
|
72
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
73
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
74
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
75
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
76
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
77
|
+
Work and such Derivative Works in Source or Object form.
|
|
78
|
+
|
|
79
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
80
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
81
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
82
|
+
(except as stated in this section) patent license to make, have made,
|
|
83
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
84
|
+
where such license applies only to those patent claims licensable
|
|
85
|
+
by such Contributor that are necessarily infringed by their
|
|
86
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
87
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
88
|
+
institute patent litigation against any entity (including a
|
|
89
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
90
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
91
|
+
or contributory patent infringement, then any patent licenses
|
|
92
|
+
granted to You under this License for that Work shall terminate
|
|
93
|
+
as of the date such litigation is filed.
|
|
94
|
+
|
|
95
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
96
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
97
|
+
modifications, and in Source or Object form, provided that You
|
|
98
|
+
meet the following conditions:
|
|
99
|
+
|
|
100
|
+
(a) You must give any other recipients of the Work or
|
|
101
|
+
Derivative Works a copy of this License; and
|
|
102
|
+
|
|
103
|
+
(b) You must cause any modified files to carry prominent notices
|
|
104
|
+
stating that You changed the files; and
|
|
105
|
+
|
|
106
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
107
|
+
that You distribute, all copyright, patent, trademark, and
|
|
108
|
+
attribution notices from the Source form of the Work,
|
|
109
|
+
excluding those notices that do not pertain to any part of
|
|
110
|
+
the Derivative Works; and
|
|
111
|
+
|
|
112
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
113
|
+
distribution, then any Derivative Works that You distribute must
|
|
114
|
+
include a readable copy of the attribution notices contained
|
|
115
|
+
within such NOTICE file, excluding those notices that do not
|
|
116
|
+
pertain to any part of the Derivative Works, in at least one
|
|
117
|
+
of the following places: within a NOTICE text file distributed
|
|
118
|
+
as part of the Derivative Works; within the Source form or
|
|
119
|
+
documentation, if provided along with the Derivative Works; or,
|
|
120
|
+
within a display generated by the Derivative Works, if and
|
|
121
|
+
wherever such third-party notices normally appear. The contents
|
|
122
|
+
of the NOTICE file are for informational purposes only and
|
|
123
|
+
do not modify the License. You may add Your own attribution
|
|
124
|
+
notices within Derivative Works that You distribute, alongside
|
|
125
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
126
|
+
that such additional attribution notices cannot be construed
|
|
127
|
+
as modifying the License.
|
|
128
|
+
|
|
129
|
+
You may add Your own copyright statement to Your modifications and
|
|
130
|
+
may provide additional or different license terms and conditions
|
|
131
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
132
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
133
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
134
|
+
the conditions stated in this License.
|
|
135
|
+
|
|
136
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
137
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
138
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
139
|
+
this License, without any additional terms or conditions.
|
|
140
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
141
|
+
the terms of any separate license agreement you may have executed
|
|
142
|
+
with Licensor regarding such Contributions.
|
|
143
|
+
|
|
144
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
145
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
146
|
+
except as required for reasonable and customary use in describing the
|
|
147
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
148
|
+
|
|
149
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
150
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
151
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
152
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
153
|
+
implied, including, without limitation, any warranties or conditions
|
|
154
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
155
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
156
|
+
appropriateness of using or redistributing the Work and assume any
|
|
157
|
+
risks associated with Your exercise of permissions under this License.
|
|
158
|
+
|
|
159
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
160
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
161
|
+
unless required by applicable law (such as deliberate and grossly
|
|
162
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
163
|
+
liable to You for damages, including any direct, indirect, special,
|
|
164
|
+
incidental, or consequential damages of any character arising as a
|
|
165
|
+
result of this License or out of the use or inability to use the
|
|
166
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
167
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
168
|
+
other commercial damages or losses), even if such Contributor
|
|
169
|
+
has been advised of the possibility of such damages.
|
|
170
|
+
|
|
171
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
172
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
173
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
174
|
+
or other liability obligations and/or rights consistent with this
|
|
175
|
+
License. However, in accepting such obligations, You may act only
|
|
176
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
177
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
178
|
+
defend, and hold each Contributor harmless for any liability
|
|
179
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
180
|
+
of your accepting any such warranty or additional liability.
|
|
181
|
+
|
|
182
|
+
END OF TERMS AND CONDITIONS
|
|
183
|
+
|
|
184
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
185
|
+
|
|
186
|
+
To apply the Apache License to your work, attach the following
|
|
187
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
188
|
+
replaced with your own identifying information. (Don't include
|
|
189
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
190
|
+
comment syntax for the file format. We also recommend that a
|
|
191
|
+
file or class name and description of purpose be included on the
|
|
192
|
+
same "printed page" as the copyright notice for easier
|
|
193
|
+
identification within third-party archives.
|
|
194
|
+
|
|
195
|
+
Copyright [2025] [Swarmauri Team]
|
|
196
|
+
|
|
197
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
198
|
+
you may not use this file except in compliance with the License.
|
|
199
|
+
You may obtain a copy of the License at
|
|
200
|
+
|
|
201
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
202
|
+
|
|
203
|
+
Unless required by applicable law or agreed to in writing, software
|
|
204
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
205
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
206
|
+
See the License for the specific language governing permissions and
|
|
207
|
+
limitations under the License.
|
|
208
|
+
License-File: LICENSE
|
|
209
|
+
Keywords: dataframe,engine,excel,experimental,tigrbl,xlsx
|
|
210
|
+
Classifier: Development Status :: 1 - Planning
|
|
211
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
212
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
213
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
214
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
215
|
+
Requires-Python: <3.13,>=3.10
|
|
216
|
+
Requires-Dist: openpyxl>=3.1
|
|
217
|
+
Requires-Dist: tigrbl>=0.3.0.dev4
|
|
218
|
+
Description-Content-Type: text/markdown
|
|
219
|
+
|
|
220
|
+

|
|
221
|
+
|
|
222
|
+
<p align="center">
|
|
223
|
+
<a href="https://pypi.org/project/tigrbl_engine_xlsx/">
|
|
224
|
+
<img src="https://img.shields.io/pypi/v/tigrbl_engine_xlsx?label=tigrbl_engine_xlsx&color=green" alt="PyPI - tigrbl_engine_xlsx"/>
|
|
225
|
+
</a>
|
|
226
|
+
<a href="https://pypi.org/project/tigrbl_engine_xlsx/">
|
|
227
|
+
<img src="https://img.shields.io/pypi/dm/tigrbl_engine_xlsx" alt="PyPI - Downloads"/>
|
|
228
|
+
</a>
|
|
229
|
+
<a href="https://pypi.org/project/tigrbl_engine_xlsx/">
|
|
230
|
+
<img src="https://img.shields.io/pypi/pyversions/tigrbl_engine_xlsx" alt="PyPI - Python Version"/>
|
|
231
|
+
</a>
|
|
232
|
+
<a href="https://pypi.org/project/tigrbl_engine_xlsx/">
|
|
233
|
+
<img src="https://img.shields.io/pypi/l/tigrbl_engine_xlsx" alt="PyPI - License"/>
|
|
234
|
+
</a>
|
|
235
|
+
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/experimental/tigrbl_engine_xlsx/">
|
|
236
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/experimental/tigrbl_engine_xlsx.svg"/>
|
|
237
|
+
</a>
|
|
238
|
+
</p>
|
|
239
|
+
|
|
240
|
+
# tigrbl_engine_xlsx
|
|
241
|
+
|
|
242
|
+
A tigrbl engine plugin where each workbook is a database-like object and each sheet is a table.
|
|
243
|
+
|
|
244
|
+
## Features
|
|
245
|
+
|
|
246
|
+
- Registers `kind="xlsx"` through the `tigrbl.engine` entry-point group.
|
|
247
|
+
- Uses `load_workbook`, `wb[...]`, and `wb.save(...)` directly for workbook operations.
|
|
248
|
+
- Treats each sheet as a table with transactional table semantics.
|
|
249
|
+
|
|
250
|
+
## Installation
|
|
251
|
+
|
|
252
|
+
### uv
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
uv add tigrbl_engine_xlsx
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### pip
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
pip install tigrbl_engine_xlsx
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Usage
|
|
265
|
+
|
|
266
|
+
```python
|
|
267
|
+
from tigrbl.engine import EngineSpec
|
|
268
|
+
|
|
269
|
+
spec = EngineSpec(kind="xlsx", mapping={"path": "./workbook.xlsx", "pk": "id"})
|
|
270
|
+
provider = spec.provider()
|
|
271
|
+
engine, session_factory = provider.build()
|
|
272
|
+
|
|
273
|
+
session = session_factory()
|
|
274
|
+
wb = session.workbook()
|
|
275
|
+
print(wb["Sheet1"])
|
|
276
|
+
print(session.table("Sheet1"))
|
|
277
|
+
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
tigrbl_engine_xlsx/__init__.py,sha256=BfkeKBv3smUIIiZ0uf3Mt0SKMZj5gwZiUiUS-mPCrIM,480
|
|
2
|
+
tigrbl_engine_xlsx/engine.py,sha256=sHNfwMI_yXmBWIzMZ88AX-N8YLhPzjtbdyFWIrRTqNk,3138
|
|
3
|
+
tigrbl_engine_xlsx/session.py,sha256=BL2wdFZfE7vVE7HerD1P-DEVB3sC-xxeEW9RhRebNFI,17545
|
|
4
|
+
tigrbl_engine_xlsx-0.1.1.dev1.dist-info/METADATA,sha256=JnQZ1vPyr21_3tzQHhBfL4gZNyzVO4nlvKPtI5y-NqI,15146
|
|
5
|
+
tigrbl_engine_xlsx-0.1.1.dev1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
6
|
+
tigrbl_engine_xlsx-0.1.1.dev1.dist-info/entry_points.txt,sha256=rR7gnMBbkzbRbpClCTOcBzfPCRnxy2-CduR8LQZxaaE,51
|
|
7
|
+
tigrbl_engine_xlsx-0.1.1.dev1.dist-info/licenses/LICENSE,sha256=708mvS2G_dkXGD6DVfUDngIUW4HW-T14Ws-q7shsacA,10880
|
|
8
|
+
tigrbl_engine_xlsx-0.1.1.dev1.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2025] [Swarmauri Team]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|