metta-sqlite 0.9.2__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.
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: metta-sqlite
|
|
3
|
+
Version: 0.9.2
|
|
4
|
+
Summary: sqlite3 as a SQL engine a MeTTa head can be registered into
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Classifier: Development Status :: 3 - Alpha
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Intended Audience :: Science/Research
|
|
9
|
+
Requires-Python: >=3.12
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: pymetta==0.9.2
|
|
12
|
+
|
|
13
|
+
# metta-sqlite
|
|
14
|
+
|
|
15
|
+
sqlite3 as a SQL engine a MeTTa head can be registered into.
|
|
16
|
+
|
|
17
|
+
`pymetta` names no third-party library. This package is one row against the `sql` point, and the seat
|
|
18
|
+
finds it exactly as it finds a package written by somebody else: through the
|
|
19
|
+
`metta.extensions` entry point, loaded at the first dispatch that has no answer
|
|
20
|
+
without it, or through `import metta_sqlite`, whose module body registers the same
|
|
21
|
+
rows.
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
pip install metta-sqlite # or: pip install 'pymetta[sql]'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Its tests are in `tests/`, and they run in the workspace suite:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
sh extensions/python/test.sh ext/metta-sqlite
|
|
31
|
+
```
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
metta_sqlite.py,sha256=N2VEFaN1OKD17hMCeJW4Qapn17ElrGMkqpRKrviafkk,1956
|
|
2
|
+
metta_sqlite-0.9.2.dist-info/METADATA,sha256=7c1_FcFXCVo1YV96IHlRzkZ86UqeJQ9T-63IzNwnBvg,1012
|
|
3
|
+
metta_sqlite-0.9.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
4
|
+
metta_sqlite-0.9.2.dist-info/entry_points.txt,sha256=0FeD5iKGz16J-9gpaQgY-Of2W-k6uFQw9jxgZQen6zA,47
|
|
5
|
+
metta_sqlite-0.9.2.dist-info/top_level.txt,sha256=nSAMq0u3kWXg1SwJJRJ4JEAZZFSiejR0TTVSrFbQqsY,13
|
|
6
|
+
metta_sqlite-0.9.2.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
metta_sqlite
|
metta_sqlite.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Purpose: sqlite3 as a SQL engine of the MeTTa Python seat, in one row.
|
|
2
|
+
|
|
3
|
+
A MeTTa head registered into a sqlite3 connection becomes a scalar SQL
|
|
4
|
+
function, so a query can call a definition the space holds. One row against
|
|
5
|
+
the seat's `sql` point; pymetta names no engine.
|
|
6
|
+
|
|
7
|
+
sqlite3 is the standard library, so this distribution depends on nothing but
|
|
8
|
+
pymetta. It is still a distribution and not a shipped row, because "in the
|
|
9
|
+
standard library" is not a reason for the core to know a SQL engine: the second
|
|
10
|
+
engine of the class has to reach the same door the first did, and a row that
|
|
11
|
+
lived in the core would be the branch a fork starts from.
|
|
12
|
+
|
|
13
|
+
Assumes:
|
|
14
|
+
- sqlite3 wants an ARITY and no types, which is why an undeclared head
|
|
15
|
+
registers here where DuckDB refuses one
|
|
16
|
+
Guarantees:
|
|
17
|
+
- a head with no declared arrow still registers, taking its argument count
|
|
18
|
+
from the signature [tested: tests/test_sqlite.py; commit=94057a0f073c0fab0a35c42beff2c324d8a0addd]
|
|
19
|
+
- a connection of any other engine is declined, so the next row is consulted
|
|
20
|
+
[tested: tests/test_sqlite.py::test_a_foreign_connection_is_declined;
|
|
21
|
+
commit=94057a0f073c0fab0a35c42beff2c324d8a0addd]
|
|
22
|
+
Open Obligations:
|
|
23
|
+
To Do: None
|
|
24
|
+
Hacks: None
|
|
25
|
+
Future Enhancements: None
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
30
|
+
import sqlite3
|
|
31
|
+
from typing import Any
|
|
32
|
+
|
|
33
|
+
from metta import seam
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _claims(connection: Any) -> Any:
|
|
37
|
+
"""sqlite3's own connection type, which is in the standard library."""
|
|
38
|
+
return connection if isinstance(connection, sqlite3.Connection) else None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _define(connection: Any, name: str, call: Any, head: Any, signature: Any) -> None:
|
|
42
|
+
"""sqlite3 wants the arity and no types, so an undeclared head registers."""
|
|
43
|
+
del head
|
|
44
|
+
connection.create_function(name, seam.sql_arity(signature), call)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def register() -> None:
|
|
48
|
+
"""This package's one row, against the seat's `sql` point."""
|
|
49
|
+
seam.sql.register("sqlite3", claims=_claims, define=_define)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
register()
|