ccflow-db 0.1.0__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.
- ccflow_db/__init__.py +3 -0
- ccflow_db/base.py +335 -0
- ccflow_db/config/__init__.py +0 -0
- ccflow_db/config/cache/sqlite.yaml +18 -0
- ccflow_db/config/checkpoint/sqlite.yaml +8 -0
- ccflow_db/tests/test_all.py +5 -0
- ccflow_db/tests/test_sqlite.py +191 -0
- ccflow_db-0.1.0.dist-info/METADATA +73 -0
- ccflow_db-0.1.0.dist-info/RECORD +12 -0
- ccflow_db-0.1.0.dist-info/WHEEL +4 -0
- ccflow_db-0.1.0.dist-info/entry_points.txt +2 -0
- ccflow_db-0.1.0.dist-info/licenses/LICENSE +201 -0
ccflow_db/__init__.py
ADDED
ccflow_db/base.py
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import re
|
|
3
|
+
import sqlite3
|
|
4
|
+
from datetime import datetime, timezone
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any, Dict, List, Literal, Optional, Type, Union
|
|
7
|
+
|
|
8
|
+
from ccflow import BaseModel, CallableModel, ContextBase, ContextType, Flow, ResultBase, ResultType
|
|
9
|
+
from ccflow_etl import CheckpointRecord, CheckpointStatus
|
|
10
|
+
from pydantic import Field
|
|
11
|
+
|
|
12
|
+
__all__ = (
|
|
13
|
+
"SQLiteConfig",
|
|
14
|
+
"SQLiteCacheStore",
|
|
15
|
+
"SQLiteCheckpointStore",
|
|
16
|
+
"SQLiteKeyExistsContext",
|
|
17
|
+
"SQLiteKeyExistsModel",
|
|
18
|
+
"SQLiteKeyExistsResult",
|
|
19
|
+
"SQLiteQueryContext",
|
|
20
|
+
"SQLiteQueryModel",
|
|
21
|
+
"SQLiteQueryResult",
|
|
22
|
+
"SQLiteTableWriteContext",
|
|
23
|
+
"SQLiteTableWriteModel",
|
|
24
|
+
"SQLiteTableWriteResult",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
SQLiteTableWriteMode = Literal["append", "replace", "upsert"]
|
|
28
|
+
SQLiteTableWriteStatus = Literal["written", "replaced", "upserted", "empty"]
|
|
29
|
+
|
|
30
|
+
_IDENTIFIER_PATTERN = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class SQLiteConfig(BaseModel):
|
|
34
|
+
path: Union[str, Path] = ":memory:"
|
|
35
|
+
|
|
36
|
+
def connect(self):
|
|
37
|
+
database_path = str(self.path)
|
|
38
|
+
if database_path != ":memory:":
|
|
39
|
+
Path(database_path).parent.mkdir(parents=True, exist_ok=True)
|
|
40
|
+
connection = sqlite3.connect(database_path)
|
|
41
|
+
connection.row_factory = sqlite3.Row
|
|
42
|
+
return connection
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class SQLiteCheckpointStore(BaseModel):
|
|
46
|
+
config: SQLiteConfig = Field(default_factory=SQLiteConfig)
|
|
47
|
+
table: str = "checkpoints"
|
|
48
|
+
|
|
49
|
+
def _ensure_table(self, connection: sqlite3.Connection) -> None:
|
|
50
|
+
connection.execute(
|
|
51
|
+
f"""
|
|
52
|
+
CREATE TABLE IF NOT EXISTS {_quote_identifier(self.table)} (
|
|
53
|
+
key TEXT PRIMARY KEY,
|
|
54
|
+
status TEXT NOT NULL,
|
|
55
|
+
updated_at TEXT NOT NULL,
|
|
56
|
+
metadata TEXT NOT NULL
|
|
57
|
+
)
|
|
58
|
+
"""
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def get(self, key: str) -> Optional[CheckpointRecord]:
|
|
62
|
+
with self.config.connect() as connection:
|
|
63
|
+
self._ensure_table(connection)
|
|
64
|
+
row = connection.execute(
|
|
65
|
+
f"SELECT key, status, updated_at, metadata FROM {_quote_identifier(self.table)} WHERE key = ?", (key,)
|
|
66
|
+
).fetchone()
|
|
67
|
+
if row is None:
|
|
68
|
+
return None
|
|
69
|
+
return CheckpointRecord(key=row["key"], status=row["status"], updated_at=row["updated_at"], metadata=json.loads(row["metadata"]))
|
|
70
|
+
|
|
71
|
+
def mark(self, key: str, status: CheckpointStatus, metadata: Optional[Dict[str, Any]] = None) -> CheckpointRecord:
|
|
72
|
+
record = CheckpointRecord(
|
|
73
|
+
key=key,
|
|
74
|
+
status=status,
|
|
75
|
+
updated_at=datetime.now(timezone.utc).isoformat(),
|
|
76
|
+
metadata=metadata or {},
|
|
77
|
+
)
|
|
78
|
+
with self.config.connect() as connection:
|
|
79
|
+
self._ensure_table(connection)
|
|
80
|
+
connection.execute(
|
|
81
|
+
f"""
|
|
82
|
+
INSERT INTO {_quote_identifier(self.table)} (key, status, updated_at, metadata)
|
|
83
|
+
VALUES (?, ?, ?, ?)
|
|
84
|
+
ON CONFLICT(key) DO UPDATE SET
|
|
85
|
+
status = excluded.status,
|
|
86
|
+
updated_at = excluded.updated_at,
|
|
87
|
+
metadata = excluded.metadata
|
|
88
|
+
""",
|
|
89
|
+
(record.key, record.status, record.updated_at, json.dumps(record.metadata, sort_keys=True)),
|
|
90
|
+
)
|
|
91
|
+
return record
|
|
92
|
+
|
|
93
|
+
def mark_succeeded(self, key: str, metadata: Optional[Dict[str, Any]] = None) -> CheckpointRecord:
|
|
94
|
+
return self.mark(key=key, status="succeeded", metadata=metadata)
|
|
95
|
+
|
|
96
|
+
def should_skip(self, key: str) -> bool:
|
|
97
|
+
record = self.get(key)
|
|
98
|
+
return record is not None and record.status == "succeeded"
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class SQLiteCacheStore(BaseModel):
|
|
102
|
+
config: SQLiteConfig = Field(default_factory=SQLiteConfig)
|
|
103
|
+
table: str = "cache_entries"
|
|
104
|
+
|
|
105
|
+
def _ensure_table(self, connection: sqlite3.Connection) -> None:
|
|
106
|
+
connection.execute(
|
|
107
|
+
f"""
|
|
108
|
+
CREATE TABLE IF NOT EXISTS {_quote_identifier(self.table)} (
|
|
109
|
+
key TEXT PRIMARY KEY,
|
|
110
|
+
payload BLOB NOT NULL,
|
|
111
|
+
content_type TEXT,
|
|
112
|
+
updated_at TEXT NOT NULL
|
|
113
|
+
)
|
|
114
|
+
"""
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
def uri(self, key: str) -> str:
|
|
118
|
+
return f"sqlite://{self.config.path}/{self.table}/{key}"
|
|
119
|
+
|
|
120
|
+
def exists(self, key: str) -> bool:
|
|
121
|
+
with self.config.connect() as connection:
|
|
122
|
+
self._ensure_table(connection)
|
|
123
|
+
row = connection.execute(f"SELECT 1 FROM {_quote_identifier(self.table)} WHERE key = ? LIMIT 1", (key,)).fetchone()
|
|
124
|
+
return row is not None
|
|
125
|
+
|
|
126
|
+
def put_bytes(self, key: str, value: bytes, content_type: Optional[str] = None) -> Dict[str, Any]:
|
|
127
|
+
with self.config.connect() as connection:
|
|
128
|
+
self._ensure_table(connection)
|
|
129
|
+
connection.execute(
|
|
130
|
+
f"""
|
|
131
|
+
INSERT INTO {_quote_identifier(self.table)} (key, payload, content_type, updated_at)
|
|
132
|
+
VALUES (?, ?, ?, ?)
|
|
133
|
+
ON CONFLICT(key) DO UPDATE SET
|
|
134
|
+
payload = excluded.payload,
|
|
135
|
+
content_type = excluded.content_type,
|
|
136
|
+
updated_at = excluded.updated_at
|
|
137
|
+
""",
|
|
138
|
+
(key, sqlite3.Binary(value), content_type, datetime.now(timezone.utc).isoformat()),
|
|
139
|
+
)
|
|
140
|
+
return {"table": self.table, "key": key}
|
|
141
|
+
|
|
142
|
+
def get_bytes(self, key: str) -> bytes:
|
|
143
|
+
with self.config.connect() as connection:
|
|
144
|
+
self._ensure_table(connection)
|
|
145
|
+
row = connection.execute(f"SELECT payload FROM {_quote_identifier(self.table)} WHERE key = ? LIMIT 1", (key,)).fetchone()
|
|
146
|
+
if row is None:
|
|
147
|
+
raise FileNotFoundError(self.uri(key))
|
|
148
|
+
return bytes(row["payload"])
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class SQLiteQueryContext(ContextBase):
|
|
152
|
+
sql: str
|
|
153
|
+
params: Union[List[Any], Dict[str, Any]] = Field(default_factory=list)
|
|
154
|
+
fetch: bool = False
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class SQLiteQueryResult(ResultBase):
|
|
158
|
+
rows: List[Dict[str, Any]] = Field(default_factory=list)
|
|
159
|
+
rowcount: int
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class SQLiteKeyExistsContext(ContextBase):
|
|
163
|
+
table: str
|
|
164
|
+
key: Dict[str, Any] = Field(default_factory=dict)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class SQLiteKeyExistsResult(ResultBase):
|
|
168
|
+
table: str
|
|
169
|
+
key: Dict[str, Any] = Field(default_factory=dict)
|
|
170
|
+
exists: bool
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class SQLiteQueryModel(CallableModel):
|
|
174
|
+
config: SQLiteConfig = Field(default_factory=SQLiteConfig)
|
|
175
|
+
|
|
176
|
+
@property
|
|
177
|
+
def context_type(self) -> Type[ContextType]:
|
|
178
|
+
return SQLiteQueryContext
|
|
179
|
+
|
|
180
|
+
@property
|
|
181
|
+
def result_type(self) -> Type[ResultType]:
|
|
182
|
+
return SQLiteQueryResult
|
|
183
|
+
|
|
184
|
+
@Flow.call
|
|
185
|
+
def __call__(self, context: SQLiteQueryContext) -> SQLiteQueryResult:
|
|
186
|
+
with self.config.connect() as connection:
|
|
187
|
+
cursor = connection.execute(context.sql, context.params)
|
|
188
|
+
rows = [dict(row) for row in cursor.fetchall()] if context.fetch else []
|
|
189
|
+
return SQLiteQueryResult(rows=rows, rowcount=cursor.rowcount)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
class SQLiteTableWriteContext(ContextBase):
|
|
193
|
+
table: str
|
|
194
|
+
rows: List[Dict[str, Any]] = Field(default_factory=list)
|
|
195
|
+
mode: SQLiteTableWriteMode = "append"
|
|
196
|
+
primary_key: List[str] = Field(default_factory=list)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
class SQLiteTableWriteResult(ResultBase):
|
|
200
|
+
table: str
|
|
201
|
+
status: SQLiteTableWriteStatus
|
|
202
|
+
rows_written: int
|
|
203
|
+
columns: List[str] = Field(default_factory=list)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _quote_identifier(identifier: str) -> str:
|
|
207
|
+
if not _IDENTIFIER_PATTERN.fullmatch(identifier):
|
|
208
|
+
raise ValueError(f"Invalid SQLite identifier: {identifier!r}")
|
|
209
|
+
return f'"{identifier}"'
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def _columns(rows: List[Dict[str, Any]]) -> List[str]:
|
|
213
|
+
columns = []
|
|
214
|
+
for row in rows:
|
|
215
|
+
for column in row:
|
|
216
|
+
if column not in columns:
|
|
217
|
+
columns.append(column)
|
|
218
|
+
return columns
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def _sqlite_type(values: List[Any]) -> str:
|
|
222
|
+
for value in values:
|
|
223
|
+
if value is None:
|
|
224
|
+
continue
|
|
225
|
+
if isinstance(value, bool):
|
|
226
|
+
return "INTEGER"
|
|
227
|
+
if isinstance(value, int):
|
|
228
|
+
return "INTEGER"
|
|
229
|
+
if isinstance(value, float):
|
|
230
|
+
return "REAL"
|
|
231
|
+
if isinstance(value, bytes):
|
|
232
|
+
return "BLOB"
|
|
233
|
+
return "TEXT"
|
|
234
|
+
return "TEXT"
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def _column_types(rows: List[Dict[str, Any]], columns: List[str]) -> Dict[str, str]:
|
|
238
|
+
return {column: _sqlite_type([row.get(column) for row in rows]) for column in columns}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _sqlite_value(value: Any) -> Any:
|
|
242
|
+
if isinstance(value, bool):
|
|
243
|
+
return int(value)
|
|
244
|
+
if isinstance(value, (dict, list)):
|
|
245
|
+
return json.dumps(value, sort_keys=True)
|
|
246
|
+
return value
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _table_exists(connection: sqlite3.Connection, table: str) -> bool:
|
|
250
|
+
row = connection.execute("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?", (table,)).fetchone()
|
|
251
|
+
return row is not None
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _create_table_sql(table: str, columns: List[str], column_types: Dict[str, str], primary_key: List[str]) -> str:
|
|
255
|
+
column_sql = [f"{_quote_identifier(column)} {column_types[column]}" for column in columns]
|
|
256
|
+
if primary_key:
|
|
257
|
+
missing_keys = [column for column in primary_key if column not in columns]
|
|
258
|
+
if missing_keys:
|
|
259
|
+
raise ValueError(f"Primary key columns are missing from rows: {missing_keys}")
|
|
260
|
+
column_sql.append(f"PRIMARY KEY ({', '.join(_quote_identifier(column) for column in primary_key)})")
|
|
261
|
+
return f"CREATE TABLE IF NOT EXISTS {_quote_identifier(table)} ({', '.join(column_sql)})"
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def _insert_sql(table: str, columns: List[str], mode: SQLiteTableWriteMode, primary_key: List[str]) -> str:
|
|
265
|
+
quoted_columns = [_quote_identifier(column) for column in columns]
|
|
266
|
+
placeholders = ", ".join("?" for _column in columns)
|
|
267
|
+
sql = f"INSERT INTO {_quote_identifier(table)} ({', '.join(quoted_columns)}) VALUES ({placeholders})"
|
|
268
|
+
if mode != "upsert":
|
|
269
|
+
return sql
|
|
270
|
+
if not primary_key:
|
|
271
|
+
raise ValueError("SQLite upsert mode requires primary_key.")
|
|
272
|
+
|
|
273
|
+
update_columns = [column for column in columns if column not in primary_key]
|
|
274
|
+
if not update_columns:
|
|
275
|
+
return f"{sql} ON CONFLICT({', '.join(_quote_identifier(column) for column in primary_key)}) DO NOTHING"
|
|
276
|
+
assignments = ", ".join(f"{_quote_identifier(column)} = excluded.{_quote_identifier(column)}" for column in update_columns)
|
|
277
|
+
return f"{sql} ON CONFLICT({', '.join(_quote_identifier(column) for column in primary_key)}) DO UPDATE SET {assignments}"
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
class SQLiteTableWriteModel(CallableModel):
|
|
281
|
+
config: SQLiteConfig = Field(default_factory=SQLiteConfig)
|
|
282
|
+
|
|
283
|
+
@property
|
|
284
|
+
def context_type(self) -> Type[ContextType]:
|
|
285
|
+
return SQLiteTableWriteContext
|
|
286
|
+
|
|
287
|
+
@property
|
|
288
|
+
def result_type(self) -> Type[ResultType]:
|
|
289
|
+
return SQLiteTableWriteResult
|
|
290
|
+
|
|
291
|
+
@Flow.call
|
|
292
|
+
def __call__(self, context: SQLiteTableWriteContext) -> SQLiteTableWriteResult:
|
|
293
|
+
if not context.rows:
|
|
294
|
+
return SQLiteTableWriteResult(table=context.table, status="empty", rows_written=0, columns=[])
|
|
295
|
+
|
|
296
|
+
columns = _columns(context.rows)
|
|
297
|
+
values = [[_sqlite_value(row.get(column)) for column in columns] for row in context.rows]
|
|
298
|
+
column_types = _column_types(context.rows, columns)
|
|
299
|
+
|
|
300
|
+
with self.config.connect() as connection:
|
|
301
|
+
if context.mode == "replace":
|
|
302
|
+
connection.execute(f"DROP TABLE IF EXISTS {_quote_identifier(context.table)}")
|
|
303
|
+
connection.execute(_create_table_sql(context.table, columns, column_types, context.primary_key))
|
|
304
|
+
connection.executemany(_insert_sql(context.table, columns, context.mode, context.primary_key), values)
|
|
305
|
+
|
|
306
|
+
status: SQLiteTableWriteStatus = {"append": "written", "replace": "replaced", "upsert": "upserted"}[context.mode]
|
|
307
|
+
return SQLiteTableWriteResult(table=context.table, status=status, rows_written=len(context.rows), columns=columns)
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
class SQLiteKeyExistsModel(CallableModel):
|
|
311
|
+
config: SQLiteConfig = Field(default_factory=SQLiteConfig)
|
|
312
|
+
|
|
313
|
+
@property
|
|
314
|
+
def context_type(self) -> Type[ContextType]:
|
|
315
|
+
return SQLiteKeyExistsContext
|
|
316
|
+
|
|
317
|
+
@property
|
|
318
|
+
def result_type(self) -> Type[ResultType]:
|
|
319
|
+
return SQLiteKeyExistsResult
|
|
320
|
+
|
|
321
|
+
@Flow.call
|
|
322
|
+
def __call__(self, context: SQLiteKeyExistsContext) -> SQLiteKeyExistsResult:
|
|
323
|
+
if not context.key:
|
|
324
|
+
raise ValueError("SQLite key existence checks require at least one key column.")
|
|
325
|
+
|
|
326
|
+
table = _quote_identifier(context.table)
|
|
327
|
+
columns = list(context.key)
|
|
328
|
+
where_clause = " AND ".join(f"{_quote_identifier(column)} = ?" for column in columns)
|
|
329
|
+
values = [_sqlite_value(context.key[column]) for column in columns]
|
|
330
|
+
|
|
331
|
+
with self.config.connect() as connection:
|
|
332
|
+
if not _table_exists(connection, context.table):
|
|
333
|
+
return SQLiteKeyExistsResult(table=context.table, key=context.key, exists=False)
|
|
334
|
+
row = connection.execute(f"SELECT 1 FROM {table} WHERE {where_clause} LIMIT 1", values).fetchone()
|
|
335
|
+
return SQLiteKeyExistsResult(table=context.table, key=context.key, exists=row is not None)
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @package cache
|
|
2
|
+
|
|
3
|
+
store:
|
|
4
|
+
_target_: ccflow_db.SQLiteCacheStore
|
|
5
|
+
config:
|
|
6
|
+
_target_: ccflow_db.SQLiteConfig
|
|
7
|
+
path: ccflow-cache.sqlite
|
|
8
|
+
table: cache_entries
|
|
9
|
+
|
|
10
|
+
put:
|
|
11
|
+
_target_: ccflow_etl.CachePutModel
|
|
12
|
+
store: /cache/store
|
|
13
|
+
format: json
|
|
14
|
+
|
|
15
|
+
get:
|
|
16
|
+
_target_: ccflow_etl.CacheGetModel
|
|
17
|
+
store: /cache/store
|
|
18
|
+
format: json
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
import tomllib
|
|
5
|
+
from ccflow_etl import CacheGetContext, CacheGetModel, CachePutContext, CachePutModel, ETLArtifact
|
|
6
|
+
from hydra import compose, initialize_config_dir
|
|
7
|
+
from hydra.utils import instantiate
|
|
8
|
+
|
|
9
|
+
from ccflow_db import (
|
|
10
|
+
SQLiteCacheStore,
|
|
11
|
+
SQLiteCheckpointStore,
|
|
12
|
+
SQLiteConfig,
|
|
13
|
+
SQLiteKeyExistsContext,
|
|
14
|
+
SQLiteKeyExistsModel,
|
|
15
|
+
SQLiteQueryContext,
|
|
16
|
+
SQLiteQueryModel,
|
|
17
|
+
SQLiteTableWriteContext,
|
|
18
|
+
SQLiteTableWriteModel,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_sqlite_config_package_is_exposed_for_hydra_lerna_plugins(tmp_path):
|
|
23
|
+
pyproject = tomllib.loads((Path(__file__).parents[2] / "pyproject.toml").read_text())
|
|
24
|
+
assert pyproject["project"]["entry-points"]["hydra.lernaplugins"]["ccflow-db"] == "pkg:ccflow_db.config"
|
|
25
|
+
|
|
26
|
+
(tmp_path / "runner.yaml").write_text(
|
|
27
|
+
"""
|
|
28
|
+
defaults:
|
|
29
|
+
- _self_
|
|
30
|
+
- cache: sqlite
|
|
31
|
+
- checkpoint: sqlite
|
|
32
|
+
|
|
33
|
+
hydra:
|
|
34
|
+
searchpath:
|
|
35
|
+
- pkg://ccflow_db.config
|
|
36
|
+
""".lstrip()
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
with initialize_config_dir(config_dir=str(tmp_path), version_base=None):
|
|
40
|
+
cfg = compose(config_name="runner")
|
|
41
|
+
|
|
42
|
+
assert isinstance(instantiate(cfg.cache.store), SQLiteCacheStore)
|
|
43
|
+
assert isinstance(instantiate(cfg.checkpoint.store), SQLiteCheckpointStore)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_sqlite_table_write_appends_and_queries_rows(tmp_path):
|
|
47
|
+
config = SQLiteConfig(path=tmp_path / "market.sqlite")
|
|
48
|
+
|
|
49
|
+
write_result = SQLiteTableWriteModel(config=config)(
|
|
50
|
+
SQLiteTableWriteContext(
|
|
51
|
+
table="daily_bars",
|
|
52
|
+
rows=[
|
|
53
|
+
{"ticker": "AAA", "date": "2024-01-03", "close": 103.6, "volume": 12345},
|
|
54
|
+
{"ticker": "BBB", "date": "2024-01-03", "close": 27.5, "volume": 45678},
|
|
55
|
+
],
|
|
56
|
+
)
|
|
57
|
+
)
|
|
58
|
+
rows = SQLiteQueryModel(config=config)(
|
|
59
|
+
SQLiteQueryContext(sql="SELECT ticker, date, close, volume FROM daily_bars WHERE ticker = ?", params=["AAA"], fetch=True)
|
|
60
|
+
).rows
|
|
61
|
+
|
|
62
|
+
assert write_result.table == "daily_bars"
|
|
63
|
+
assert write_result.status == "written"
|
|
64
|
+
assert write_result.rows_written == 2
|
|
65
|
+
assert rows == [{"ticker": "AAA", "date": "2024-01-03", "close": 103.6, "volume": 12345}]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_sqlite_table_write_replaces_and_upserts_rows(tmp_path):
|
|
69
|
+
config = SQLiteConfig(path=tmp_path / "market.sqlite")
|
|
70
|
+
writer = SQLiteTableWriteModel(config=config)
|
|
71
|
+
reader = SQLiteQueryModel(config=config)
|
|
72
|
+
|
|
73
|
+
writer(
|
|
74
|
+
SQLiteTableWriteContext(
|
|
75
|
+
table="daily_bars",
|
|
76
|
+
rows=[{"ticker": "AAA", "date": "2024-01-03", "close": 103.6}],
|
|
77
|
+
primary_key=["ticker", "date"],
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
replace_result = writer(
|
|
81
|
+
SQLiteTableWriteContext(
|
|
82
|
+
table="daily_bars",
|
|
83
|
+
rows=[{"ticker": "BBB", "date": "2024-01-03", "close": 27.5}],
|
|
84
|
+
mode="replace",
|
|
85
|
+
primary_key=["ticker", "date"],
|
|
86
|
+
)
|
|
87
|
+
)
|
|
88
|
+
upsert_result = writer(
|
|
89
|
+
SQLiteTableWriteContext(
|
|
90
|
+
table="daily_bars",
|
|
91
|
+
rows=[
|
|
92
|
+
{"ticker": "BBB", "date": "2024-01-03", "close": 28.0},
|
|
93
|
+
{"ticker": "CCC", "date": "2024-01-03", "close": 11.0},
|
|
94
|
+
],
|
|
95
|
+
mode="upsert",
|
|
96
|
+
primary_key=["ticker", "date"],
|
|
97
|
+
)
|
|
98
|
+
)
|
|
99
|
+
rows = reader(SQLiteQueryContext(sql="SELECT ticker, close FROM daily_bars ORDER BY ticker", fetch=True)).rows
|
|
100
|
+
|
|
101
|
+
assert replace_result.status == "replaced"
|
|
102
|
+
assert upsert_result.status == "upserted"
|
|
103
|
+
assert rows == [{"ticker": "BBB", "close": 28.0}, {"ticker": "CCC", "close": 11.0}]
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_sqlite_key_exists_checks_rows_by_key(tmp_path):
|
|
107
|
+
config = SQLiteConfig(path=tmp_path / "market.sqlite")
|
|
108
|
+
SQLiteTableWriteModel(config=config)(
|
|
109
|
+
SQLiteTableWriteContext(
|
|
110
|
+
table="daily_bars",
|
|
111
|
+
rows=[{"ticker": "AAA", "date": "2024-01-03", "close": 103.6}],
|
|
112
|
+
primary_key=["ticker", "date"],
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
exists_model = SQLiteKeyExistsModel(config=config)
|
|
116
|
+
|
|
117
|
+
existing = exists_model(SQLiteKeyExistsContext(table="daily_bars", key={"ticker": "AAA", "date": "2024-01-03"}))
|
|
118
|
+
missing = exists_model(SQLiteKeyExistsContext(table="daily_bars", key={"ticker": "BBB", "date": "2024-01-03"}))
|
|
119
|
+
missing_table = exists_model(SQLiteKeyExistsContext(table="other_daily_bars", key={"ticker": "AAA", "date": "2024-01-03"}))
|
|
120
|
+
|
|
121
|
+
assert existing.exists is True
|
|
122
|
+
assert existing.table == "daily_bars"
|
|
123
|
+
assert existing.key == {"ticker": "AAA", "date": "2024-01-03"}
|
|
124
|
+
assert missing.exists is False
|
|
125
|
+
assert missing_table.exists is False
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def test_sqlite_table_write_rolls_back_transaction_on_insert_failure(tmp_path):
|
|
129
|
+
config = SQLiteConfig(path=tmp_path / "market.sqlite")
|
|
130
|
+
writer = SQLiteTableWriteModel(config=config)
|
|
131
|
+
reader = SQLiteQueryModel(config=config)
|
|
132
|
+
|
|
133
|
+
writer(
|
|
134
|
+
SQLiteTableWriteContext(
|
|
135
|
+
table="daily_bars",
|
|
136
|
+
rows=[{"ticker": "AAA", "date": "2024-01-03", "close": 103.6}],
|
|
137
|
+
primary_key=["ticker", "date"],
|
|
138
|
+
)
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
with pytest.raises(Exception):
|
|
142
|
+
writer(
|
|
143
|
+
SQLiteTableWriteContext(
|
|
144
|
+
table="daily_bars",
|
|
145
|
+
rows=[
|
|
146
|
+
{"ticker": "BBB", "date": "2024-01-03", "close": 27.5},
|
|
147
|
+
{"ticker": "AAA", "date": "2024-01-03", "close": 104.0},
|
|
148
|
+
],
|
|
149
|
+
)
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
rows = reader(SQLiteQueryContext(sql="SELECT ticker, close FROM daily_bars ORDER BY ticker", fetch=True)).rows
|
|
153
|
+
|
|
154
|
+
assert rows == [{"ticker": "AAA", "close": 103.6}]
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def test_sqlite_checkpoint_store_marks_and_reads_completed_units(tmp_path):
|
|
158
|
+
store = SQLiteCheckpointStore(config=SQLiteConfig(path=tmp_path / "checkpoints.sqlite"))
|
|
159
|
+
|
|
160
|
+
store.mark_succeeded("massive:daily:AAA:2024-01-03", metadata={"path": "daily/AAA/2024-01-03.json"})
|
|
161
|
+
|
|
162
|
+
record = store.get("massive:daily:AAA:2024-01-03")
|
|
163
|
+
assert record is not None
|
|
164
|
+
assert record.key == "massive:daily:AAA:2024-01-03"
|
|
165
|
+
assert record.status == "succeeded"
|
|
166
|
+
assert record.metadata == {"path": "daily/AAA/2024-01-03.json"}
|
|
167
|
+
assert store.should_skip("massive:daily:AAA:2024-01-03") is True
|
|
168
|
+
assert store.should_skip("massive:daily:AAA:2024-01-04") is False
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def test_sqlite_cache_put_and_get_exposes_typed_artifacts(tmp_path):
|
|
172
|
+
store = SQLiteCacheStore(config=SQLiteConfig(path=tmp_path / "cache.sqlite"), table="cache_entries")
|
|
173
|
+
|
|
174
|
+
put_model = CachePutModel(store=store, format="json")
|
|
175
|
+
get_model = CacheGetModel(store=store, format="json")
|
|
176
|
+
put_result = put_model(CachePutContext(key="massive/stocks/normalized/2024-01-03/AAA", payload={"ticker": "AAA"}, dataset="stocks", stage="load"))
|
|
177
|
+
second_put = put_model(CachePutContext(key="massive/stocks/normalized/2024-01-03/AAA", payload={"ticker": "BBB"}, dataset="stocks", stage="load"))
|
|
178
|
+
get_result = get_model(CacheGetContext(key="massive/stocks/normalized/2024-01-03/AAA", dataset="stocks", stage="load"))
|
|
179
|
+
|
|
180
|
+
assert put_result.status == "written"
|
|
181
|
+
assert second_put.status == "exists"
|
|
182
|
+
assert get_result.status == "hit"
|
|
183
|
+
assert get_result.payload == {"ticker": "AAA"}
|
|
184
|
+
assert put_result.artifact == ETLArtifact(
|
|
185
|
+
key="massive/stocks/normalized/2024-01-03/AAA",
|
|
186
|
+
dataset="stocks",
|
|
187
|
+
stage="load",
|
|
188
|
+
uri=f"sqlite://{tmp_path / 'cache.sqlite'}/cache_entries/massive/stocks/normalized/2024-01-03/AAA.json",
|
|
189
|
+
media_type="application/json",
|
|
190
|
+
status="written",
|
|
191
|
+
)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ccflow-db
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ccflow models for database access
|
|
5
|
+
Project-URL: Repository, https://github.com/1kbgz/ccflow-db
|
|
6
|
+
Project-URL: Homepage, https://github.com/1kbgz/ccflow-db
|
|
7
|
+
Author-email: 1kbgz <dev@1kbgz.com>
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
19
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: ccflow-etl>=0.1.1
|
|
22
|
+
Requires-Dist: ccflow>=0.6.10
|
|
23
|
+
Provides-Extra: develop
|
|
24
|
+
Requires-Dist: build; extra == 'develop'
|
|
25
|
+
Requires-Dist: bump-my-version; extra == 'develop'
|
|
26
|
+
Requires-Dist: check-dist; extra == 'develop'
|
|
27
|
+
Requires-Dist: codespell; extra == 'develop'
|
|
28
|
+
Requires-Dist: hatchling; extra == 'develop'
|
|
29
|
+
Requires-Dist: mdformat; extra == 'develop'
|
|
30
|
+
Requires-Dist: mdformat-tables>=1; extra == 'develop'
|
|
31
|
+
Requires-Dist: pytest; extra == 'develop'
|
|
32
|
+
Requires-Dist: pytest-cov; extra == 'develop'
|
|
33
|
+
Requires-Dist: ruff; extra == 'develop'
|
|
34
|
+
Requires-Dist: twine; extra == 'develop'
|
|
35
|
+
Requires-Dist: ty; extra == 'develop'
|
|
36
|
+
Requires-Dist: uv; extra == 'develop'
|
|
37
|
+
Requires-Dist: wheel; extra == 'develop'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# ccflow-db
|
|
41
|
+
|
|
42
|
+
ccflow models for database access
|
|
43
|
+
|
|
44
|
+
[](https://github.com/1kbgz/ccflow-db/actions/workflows/build.yaml)
|
|
45
|
+
[](https://codecov.io/gh/1kbgz/ccflow-db)
|
|
46
|
+
[](https://github.com/1kbgz/ccflow-db)
|
|
47
|
+
[](https://pypi.python.org/pypi/ccflow-db)
|
|
48
|
+
|
|
49
|
+
## Overview
|
|
50
|
+
|
|
51
|
+
`ccflow-db` provides public, domain-neutral database callable models and publishers for `ccflow` workflows. It owns connection configuration, SQL execution, tabular reads, bulk writes, transaction handling, upsert/merge patterns, database-backed checkpoint/cache adapters, and Hydra config groups exposed through the lerna plugin entry point.
|
|
52
|
+
|
|
53
|
+
It should stay generic across domains and database backends. Domain schemas, provider-specific assumptions, and application deployment conventions belong outside this package.
|
|
54
|
+
|
|
55
|
+
## Current Status
|
|
56
|
+
|
|
57
|
+
- Implemented: package scaffold, version metadata, `SQLiteConfig`, parameterized `SQLiteQueryModel`, `SQLiteKeyExistsModel`, `SQLiteTableWriteModel` for append, replace, and primary-key upsert writes, `SQLiteCheckpointStore`, byte-oriented `SQLiteCacheStore` for use with `ccflow-etl` cache format models, and `cache=sqlite` / `checkpoint=sqlite` config groups.
|
|
58
|
+
- Partial: SQLite uses the Python standard library as the first local backend; broad SQLAlchemy-style engine/session management and backend extras remain future work.
|
|
59
|
+
- Missing: dataframe reads, chunked writes, dry-run SQL rendering, merge helpers beyond SQLite upsert, and non-SQLite integration tests.
|
|
60
|
+
|
|
61
|
+
## Dependency Contract
|
|
62
|
+
|
|
63
|
+
- Depends on `ccflow` for callable model and publisher interfaces.
|
|
64
|
+
- Depends on `ccflow-etl` for generic checkpoint records and cache format/result contracts.
|
|
65
|
+
- Uses `sqlite3` for the first local backend and may add a broader abstraction layer such as SQLAlchemy plus optional backend extras later.
|
|
66
|
+
- Must not depend on finance packages or application-specific packages.
|
|
67
|
+
|
|
68
|
+
## Test Convention
|
|
69
|
+
|
|
70
|
+
Default tests should use SQLite or in-memory database fixtures. Backend-specific tests such as Postgres should be opt-in and skipped unless the required environment variables are set.
|
|
71
|
+
|
|
72
|
+
> [!NOTE]
|
|
73
|
+
> This library was generated using [copier](https://copier.readthedocs.io/en/stable/) from the [Base Python Project Template repository](https://github.com/python-project-templates/base).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
ccflow_db/__init__.py,sha256=GZa5kRIfRkSwASZsKw2rf3LPXqLZmmppxKbLjKZC2UU,43
|
|
2
|
+
ccflow_db/base.py,sha256=gglYQGykjHiC1-5qLbpoi5EV5_0WoRATxqTZIpz6-6o,12858
|
|
3
|
+
ccflow_db/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
ccflow_db/config/cache/sqlite.yaml,sha256=buMkmKwD4_TRM56TsmNFq9_qErqFNLl0hqe43WaYw2s,323
|
|
5
|
+
ccflow_db/config/checkpoint/sqlite.yaml,sha256=snYbmQmCLzn6XHAFUM1-z7d9mXguM58ZRkyqG6rQ-pQ,177
|
|
6
|
+
ccflow_db/tests/test_all.py,sha256=iCzfjXrdAk6iHKfgQ0x8-YY_s6tYD7N101GWRZpo5Ng,66
|
|
7
|
+
ccflow_db/tests/test_sqlite.py,sha256=G8p7CYSMLkv2PA9WPm1vHUMgXFFdAxZ-JCk_b0lhsuQ,7322
|
|
8
|
+
ccflow_db-0.1.0.dist-info/METADATA,sha256=5Td-Ulai4Fx9X6CghOlM_2HUhREppBnKD612aIrF0wk,4154
|
|
9
|
+
ccflow_db-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
10
|
+
ccflow_db-0.1.0.dist-info/entry_points.txt,sha256=-54XfntLasAimLUU9mDiwq1Tt7FgLYP9LTDhXLKqtk4,54
|
|
11
|
+
ccflow_db-0.1.0.dist-info/licenses/LICENSE,sha256=RcPqVYf2JyhlV4FlBQud0104R3fT1_-7XbT-vp4eLyE,11335
|
|
12
|
+
ccflow_db-0.1.0.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 1kbgz
|
|
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.
|