storepy 5.2.1__tar.gz → 5.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {storepy-5.2.1/src/storepy.egg-info → storepy-5.3.0}/PKG-INFO +3 -2
- {storepy-5.2.1 → storepy-5.3.0}/README.md +2 -1
- {storepy-5.2.1 → storepy-5.3.0}/pyproject.toml +1 -1
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/datasource.py +31 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/ddl.py +4 -0
- {storepy-5.2.1 → storepy-5.3.0/src/storepy.egg-info}/PKG-INFO +3 -2
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_raw_sql_and_ddl.py +67 -0
- {storepy-5.2.1 → storepy-5.3.0}/LICENSE +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/setup.cfg +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/__init__.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/adapters/__init__.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/adapters/http.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/ask.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/ask_knowledge.md +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/bootstrap.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/cache/__init__.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/cache/context.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/cache/provider.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/cache/redis_io.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/capabilities.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/core.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/crud/__init__.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/crud/claim.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/crud/exec.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/crud/id.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/crud/mutation.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/crud/query.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/crud/triggers.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/crud/write.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/degraded.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/executors/__init__.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/executors/_values.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/executors/mongo.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/executors/mysql.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/executors/postgres.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/executors/sqlite.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/feedback.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/introspect/__init__.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/introspect/mysql.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/introspect/postgres.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/introspect/sqlite.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/llm.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/load.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/local/__init__.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/local/handle.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/local/store.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/memory/__init__.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/metadef.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/migrate.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/naming.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/permission.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/reindex.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/resource/__init__.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/resource/providers/__init__.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/resource/providers/local.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/resource/providers/s3.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/scheduler/__init__.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/schema.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/scope.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/secure.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/sync.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/vector_index.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/vector_scan.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/py_store/workflow.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/storepy.egg-info/SOURCES.txt +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/storepy.egg-info/dependency_links.txt +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/storepy.egg-info/requires.txt +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/src/storepy.egg-info/top_level.txt +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_access_keys.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_adapters.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_ask.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_cache.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_cache_link.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_claim_concurrency.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_compute_override.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_coverage_margin.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_federation_e2e.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_feedback_flush.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_field_name_type.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_fns_binding.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_host_contract.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_host_paths.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_inline_agg.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_load.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_local_store.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_memory.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_metadef.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_migrate.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_migration.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_mongo_executor.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_mongo_session.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_multi_datasource.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_parity_deny.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_parity_local.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_parity_local_memory.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_parity_scope.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_policy_isolation.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_profile.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_py_store.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_rbac_host.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_real_backends_e2e.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_require_context.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_resource.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_resource_e2e.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_resource_pools.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_resource_units.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_scenario_course_platform.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_scenario_manager_transaction.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_scheduler.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_session.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_sql_commit_and_registry.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_triggers.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_vector_conformance.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_vector_index.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_vector_scan.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_vector_units.py +0 -0
- {storepy-5.2.1 → storepy-5.3.0}/tests/test_workflow.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: storepy
|
|
3
|
-
Version: 5.
|
|
3
|
+
Version: 5.3.0
|
|
4
4
|
Summary: Multi-backend data layer for Python asyncio (MongoDB, MySQL, SQLite, PostgreSQL, local disk): pure JSON schemas, GQL tree queries compiled to a single native query, GROUP BY/HAVING aggregation, computed columns, soft-delete and role-based access control
|
|
5
5
|
Author-email: 丁滔 <coen_ddt@qq.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -458,7 +458,8 @@ sql = store.generate_ddl("postgres", ["Course", "CourseDeleted"])
|
|
|
458
458
|
- Only scalar fields become columns; `object` / `array` fields do not.
|
|
459
459
|
- Every table gets the `__present` sentinel column; `timestamps` models also get `createdAt` / `updatedAt`; the `<collection>_deleted` archive table is generated like any other registered def.
|
|
460
460
|
- The `<Name>Deleted` archive def is **derived by the Rust core when the model is registered**; the Python host only mirrors it (`collection` `<c>_deleted`, the `deletedAt` field, empty `idPrefix`) and never re-registers it into the core. So `schema.list()` and `generate_ddl()` contain each archive table exactly once; if a duplicate ever appears (upstream regression), they deduplicate and emit a `schemaDuplicateName` / `ddlDuplicateTable` feedback event instead of silently emitting duplicate `CREATE TABLE`s.
|
|
461
|
-
-
|
|
461
|
+
- `schema.indexes` (`{keys: {f: 1|-1}}`, Mongo shape) are emitted as `CREATE [UNIQUE] INDEX` after the table (phase 3 landed; see `ddl.py::_index_stmts`). The generator is still pure text.
|
|
462
|
+
- Field type `text` maps to `MEDIUMTEXT` (MySQL) / `TEXT` (PG, SQLite) for long strings (serialized state, base64, bodies). `string` stays `VARCHAR(255)`.
|
|
462
463
|
- MySQL `__present` is `VARCHAR(255)`; a schema whose present-token string would overflow emits a `ddlPresentOverflow` feedback event rather than failing silently.
|
|
463
464
|
|
|
464
465
|
### Schema migration (orchestrator)
|
|
@@ -416,7 +416,8 @@ sql = store.generate_ddl("postgres", ["Course", "CourseDeleted"])
|
|
|
416
416
|
- Only scalar fields become columns; `object` / `array` fields do not.
|
|
417
417
|
- Every table gets the `__present` sentinel column; `timestamps` models also get `createdAt` / `updatedAt`; the `<collection>_deleted` archive table is generated like any other registered def.
|
|
418
418
|
- The `<Name>Deleted` archive def is **derived by the Rust core when the model is registered**; the Python host only mirrors it (`collection` `<c>_deleted`, the `deletedAt` field, empty `idPrefix`) and never re-registers it into the core. So `schema.list()` and `generate_ddl()` contain each archive table exactly once; if a duplicate ever appears (upstream regression), they deduplicate and emit a `schemaDuplicateName` / `ddlDuplicateTable` feedback event instead of silently emitting duplicate `CREATE TABLE`s.
|
|
419
|
-
-
|
|
419
|
+
- `schema.indexes` (`{keys: {f: 1|-1}}`, Mongo shape) are emitted as `CREATE [UNIQUE] INDEX` after the table (phase 3 landed; see `ddl.py::_index_stmts`). The generator is still pure text.
|
|
420
|
+
- Field type `text` maps to `MEDIUMTEXT` (MySQL) / `TEXT` (PG, SQLite) for long strings (serialized state, base64, bodies). `string` stays `VARCHAR(255)`.
|
|
420
421
|
- MySQL `__present` is `VARCHAR(255)`; a schema whose present-token string would overflow emits a `ddlPresentOverflow` feedback event rather than failing silently.
|
|
421
422
|
|
|
422
423
|
### Schema migration (orchestrator)
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "storepy"
|
|
7
|
-
version = "5.
|
|
7
|
+
version = "5.3.0"
|
|
8
8
|
description = "Multi-backend data layer for Python asyncio (MongoDB, MySQL, SQLite, PostgreSQL, local disk): pure JSON schemas, GQL tree queries compiled to a single native query, GROUP BY/HAVING aggregation, computed columns, soft-delete and role-based access control"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -50,6 +50,16 @@ LOCAL_KIND = 'local'
|
|
|
50
50
|
# 进程内内存数据源类型标记(与 local 同族:同为嵌入式载体)
|
|
51
51
|
MEMORY_KIND = 'memory'
|
|
52
52
|
|
|
53
|
+
# MySQL 两步化 claim / compareAndSet 的 SQL 文本占位符(core 规划产物;
|
|
54
|
+
# 领取结果在下一条 stmt 文本中占位,由执行层回填,见 _exec_sql_direct)
|
|
55
|
+
_CLAIMED_IDS = '___claimed_ids___'
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _render_claimed_ids(ids) -> str:
|
|
59
|
+
"""_id 列表 → SQL IN 字面量(单引号转义;_id 为框架生成值,转义为防御)"""
|
|
60
|
+
return '(' + ','.join("'" + str(v).replace("'", "''") + "'" for v in ids) + ')'
|
|
61
|
+
|
|
62
|
+
|
|
53
63
|
_MISSING = object()
|
|
54
64
|
# Mongo 事务能力缓存:client -> True/False(探测失败不写缓存,下次重探)
|
|
55
65
|
_mongo_tx_cap: 'weakref.WeakKeyDictionary[object, bool]' = weakref.WeakKeyDictionary()
|
|
@@ -550,6 +560,27 @@ async def _exec_sql_direct(source, connection, cmd):
|
|
|
550
560
|
if not callable(exec_fn):
|
|
551
561
|
raise RuntimeError(
|
|
552
562
|
f'SQL 数据源 {source}({_kind_of(connection)}) 的执行器未接入(见执行文档 Phase 4)')
|
|
563
|
+
stmts = plan.get('stmts') or []
|
|
564
|
+
if len(stmts) >= 2 and _CLAIMED_IDS in (stmts[1].get('text') or ''):
|
|
565
|
+
# MySQL 两步化 claim / compareAndSet:core 把领取结果下沉为 SQL 文本占位符
|
|
566
|
+
# (PG/SQLite 走 UPDATE…RETURNING 单条,不出现该分支)。必须先执行首条取回
|
|
567
|
+
# 命中 _id,回填后再执行置标语句——跳过回填会让驱动直接报
|
|
568
|
+
# ``1054 Unknown column '___claimed_ids___'``。
|
|
569
|
+
first = await exec_fn({'stmts': [stmts[0]]})
|
|
570
|
+
ids = [r['_id'] for r in (first.get('rows') or [])
|
|
571
|
+
if isinstance(r, Mapping) and '_id' in r]
|
|
572
|
+
if not ids:
|
|
573
|
+
# 零领取:不执行置标语句(与 run_atomic_commands「零领取直接返回空」一致)
|
|
574
|
+
return executors.shape_result(cmd, {
|
|
575
|
+
'docs': None, 'rows': [], 'affectedRows': 0, 'insertId': None})
|
|
576
|
+
second = dict(stmts[1])
|
|
577
|
+
second['text'] = second['text'].replace(_CLAIMED_IDS, _render_claimed_ids(ids))
|
|
578
|
+
out1 = await exec_fn({'stmts': [second]})
|
|
579
|
+
# docs 置 None:首条只取 _id,其 restore 出的残行不能当作完整领取结果
|
|
580
|
+
# (「docs 直返」分支专为 SQLite UPDATE…RETURNING 设计)
|
|
581
|
+
return executors.shape_result(cmd, {
|
|
582
|
+
'docs': None, 'rows': first.get('rows'),
|
|
583
|
+
'affectedRows': out1.get('affectedRows', 0), 'insertId': None})
|
|
553
584
|
out = await exec_fn(plan)
|
|
554
585
|
return executors.shape_result(cmd, out)
|
|
555
586
|
|
|
@@ -29,6 +29,10 @@ _BACKENDS = ('mysql', 'postgres', 'sqlite')
|
|
|
29
29
|
# schema 声明类型 → (mysql, postgres, sqlite) 列类型
|
|
30
30
|
_TYPES = {
|
|
31
31
|
'string': ('VARCHAR(255)', 'TEXT', 'TEXT'),
|
|
32
|
+
# 长文本(序列化状态、正文、base64 等数 KB 起步的字符串):MySQL 用 MEDIUMTEXT
|
|
33
|
+
# (16MB),避免调用方只能声明 string 再在建表后手改列型(宿主私改列型即绕过
|
|
34
|
+
# DDL 真源,见 AGENTS §22)。PG / SQLite 的 TEXT 本身无长度上限。
|
|
35
|
+
'text': ('MEDIUMTEXT', 'TEXT', 'TEXT'),
|
|
32
36
|
'int': ('INT', 'INTEGER', 'INTEGER'),
|
|
33
37
|
'long': ('BIGINT', 'BIGINT', 'INTEGER'),
|
|
34
38
|
'number': ('BIGINT', 'BIGINT', 'INTEGER'),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: storepy
|
|
3
|
-
Version: 5.
|
|
3
|
+
Version: 5.3.0
|
|
4
4
|
Summary: Multi-backend data layer for Python asyncio (MongoDB, MySQL, SQLite, PostgreSQL, local disk): pure JSON schemas, GQL tree queries compiled to a single native query, GROUP BY/HAVING aggregation, computed columns, soft-delete and role-based access control
|
|
5
5
|
Author-email: 丁滔 <coen_ddt@qq.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -458,7 +458,8 @@ sql = store.generate_ddl("postgres", ["Course", "CourseDeleted"])
|
|
|
458
458
|
- Only scalar fields become columns; `object` / `array` fields do not.
|
|
459
459
|
- Every table gets the `__present` sentinel column; `timestamps` models also get `createdAt` / `updatedAt`; the `<collection>_deleted` archive table is generated like any other registered def.
|
|
460
460
|
- The `<Name>Deleted` archive def is **derived by the Rust core when the model is registered**; the Python host only mirrors it (`collection` `<c>_deleted`, the `deletedAt` field, empty `idPrefix`) and never re-registers it into the core. So `schema.list()` and `generate_ddl()` contain each archive table exactly once; if a duplicate ever appears (upstream regression), they deduplicate and emit a `schemaDuplicateName` / `ddlDuplicateTable` feedback event instead of silently emitting duplicate `CREATE TABLE`s.
|
|
461
|
-
-
|
|
461
|
+
- `schema.indexes` (`{keys: {f: 1|-1}}`, Mongo shape) are emitted as `CREATE [UNIQUE] INDEX` after the table (phase 3 landed; see `ddl.py::_index_stmts`). The generator is still pure text.
|
|
462
|
+
- Field type `text` maps to `MEDIUMTEXT` (MySQL) / `TEXT` (PG, SQLite) for long strings (serialized state, base64, bodies). `string` stays `VARCHAR(255)`.
|
|
462
463
|
- MySQL `__present` is `VARCHAR(255)`; a schema whose present-token string would overflow emits a `ddlPresentOverflow` feedback event rather than failing silently.
|
|
463
464
|
|
|
464
465
|
### Schema migration (orchestrator)
|
|
@@ -599,3 +599,70 @@ def test_ddl_present_overflow_emits_feedback():
|
|
|
599
599
|
store.generate_ddl('mysql', ['DdlWide'])
|
|
600
600
|
|
|
601
601
|
assert any(e.get('code') == 'ddlPresentOverflow' for e in events), events
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
def test_ddl_text_field_uses_backend_long_text():
|
|
605
|
+
"""text 类型 → MySQL MEDIUMTEXT / PG·SQLite TEXT
|
|
606
|
+
|
|
607
|
+
长字符串(任务序列化状态、base64、正文等数 KB 起步)此前只能声明 string,
|
|
608
|
+
而 string 在 MySQL 侧固定 VARCHAR(255),宿主被迫在建表后手改列型(绕过 DDL 真源)。
|
|
609
|
+
"""
|
|
610
|
+
store.register({
|
|
611
|
+
'name': 'DdlText', 'collection': 'ddl_text', 'idPrefix': 'x', 'timestamps': False,
|
|
612
|
+
'fields': {'_id': {'type': 'string'}, 'payload': {'type': 'text'}},
|
|
613
|
+
})
|
|
614
|
+
my = store.generate_ddl('mysql', ['DdlText'])
|
|
615
|
+
pg = store.generate_ddl('postgres', ['DdlText'])
|
|
616
|
+
lite = store.generate_ddl('sqlite', ['DdlText'])
|
|
617
|
+
|
|
618
|
+
assert '`payload` MEDIUMTEXT' in my
|
|
619
|
+
assert '"payload" TEXT' in pg
|
|
620
|
+
assert '"payload" TEXT' in lite
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
# ─── ③ 两步化 claim / compareAndSet:SQL 文本占位符回填 ─────────
|
|
624
|
+
|
|
625
|
+
class _TwoStepCore:
|
|
626
|
+
"""dialect_translate 桩:返回 core 在 MySQL 侧产出的两条 stmt(首条取 _id、次条占位)"""
|
|
627
|
+
|
|
628
|
+
def dialect_translate(self, kind, cmd):
|
|
629
|
+
return {'stmts': [
|
|
630
|
+
{'text': 'SELECT _id FROM claim_jobs WHERE status = 0 LIMIT 2'},
|
|
631
|
+
{'text': 'UPDATE claim_jobs SET status = 1 WHERE _id IN ___claimed_ids___'},
|
|
632
|
+
]}
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
def test_two_step_claim_backfills_sql_text_placeholder(monkeypatch):
|
|
636
|
+
calls = []
|
|
637
|
+
|
|
638
|
+
async def fake_exec(plan):
|
|
639
|
+
calls.append([dict(s) for s in plan['stmts']])
|
|
640
|
+
if len(calls) == 1:
|
|
641
|
+
return {'rows': [{'_id': 'a1'}, {'_id': 'a2'}], 'affectedRows': 0, 'insertId': None}
|
|
642
|
+
return {'rows': [], 'affectedRows': 2, 'insertId': None}
|
|
643
|
+
|
|
644
|
+
monkeypatch.setattr(datasource, 'get_core', lambda: _TwoStepCore())
|
|
645
|
+
out = _run(datasource._exec_sql_direct(
|
|
646
|
+
'default', {'kind': 'mysql', 'exec': fake_exec},
|
|
647
|
+
{'kind': 'updateMany', 'collection': 'claim_jobs', 'filter': {}}))
|
|
648
|
+
|
|
649
|
+
# 置标语句的占位符必须按首条取回的 _id 回填,否则 MySQL 报 1054 Unknown column
|
|
650
|
+
assert calls[1][0]['text'] == (
|
|
651
|
+
"UPDATE claim_jobs SET status = 1 WHERE _id IN ('a1','a2')"), calls
|
|
652
|
+
assert out.modified_count == 2
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
def test_two_step_claim_zero_rows_skips_marker_stmt(monkeypatch):
|
|
656
|
+
calls = []
|
|
657
|
+
|
|
658
|
+
async def fake_exec(plan):
|
|
659
|
+
calls.append([dict(s) for s in plan['stmts']])
|
|
660
|
+
return {'rows': [], 'affectedRows': 0, 'insertId': None}
|
|
661
|
+
|
|
662
|
+
monkeypatch.setattr(datasource, 'get_core', lambda: _TwoStepCore())
|
|
663
|
+
out = _run(datasource._exec_sql_direct(
|
|
664
|
+
'default', {'kind': 'mysql', 'exec': fake_exec},
|
|
665
|
+
{'kind': 'updateMany', 'collection': 'claim_jobs', 'filter': {}}))
|
|
666
|
+
|
|
667
|
+
assert len(calls) == 1 # 零领取:不执行置标语句(与 run_atomic_commands 一致)
|
|
668
|
+
assert out.modified_count == 0
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|