metta-sqlite 0.9.2__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.
- metta_sqlite-0.9.2/PKG-INFO +31 -0
- metta_sqlite-0.9.2/README.md +19 -0
- metta_sqlite-0.9.2/metta_sqlite.egg-info/PKG-INFO +31 -0
- metta_sqlite-0.9.2/metta_sqlite.egg-info/SOURCES.txt +10 -0
- metta_sqlite-0.9.2/metta_sqlite.egg-info/dependency_links.txt +1 -0
- metta_sqlite-0.9.2/metta_sqlite.egg-info/entry_points.txt +2 -0
- metta_sqlite-0.9.2/metta_sqlite.egg-info/requires.txt +1 -0
- metta_sqlite-0.9.2/metta_sqlite.egg-info/top_level.txt +1 -0
- metta_sqlite-0.9.2/metta_sqlite.py +52 -0
- metta_sqlite-0.9.2/pyproject.toml +39 -0
- metta_sqlite-0.9.2/setup.cfg +4 -0
- metta_sqlite-0.9.2/tests/test_sqlite.py +46 -0
|
@@ -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,19 @@
|
|
|
1
|
+
# metta-sqlite
|
|
2
|
+
|
|
3
|
+
sqlite3 as a SQL engine a MeTTa head can be registered into.
|
|
4
|
+
|
|
5
|
+
`pymetta` names no third-party library. This package is one row against the `sql` point, and the seat
|
|
6
|
+
finds it exactly as it finds a package written by somebody else: through the
|
|
7
|
+
`metta.extensions` entry point, loaded at the first dispatch that has no answer
|
|
8
|
+
without it, or through `import metta_sqlite`, whose module body registers the same
|
|
9
|
+
rows.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
pip install metta-sqlite # or: pip install 'pymetta[sql]'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Its tests are in `tests/`, and they run in the workspace suite:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
sh extensions/python/test.sh ext/metta-sqlite
|
|
19
|
+
```
|
|
@@ -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,10 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
metta_sqlite.py
|
|
3
|
+
pyproject.toml
|
|
4
|
+
metta_sqlite.egg-info/PKG-INFO
|
|
5
|
+
metta_sqlite.egg-info/SOURCES.txt
|
|
6
|
+
metta_sqlite.egg-info/dependency_links.txt
|
|
7
|
+
metta_sqlite.egg-info/entry_points.txt
|
|
8
|
+
metta_sqlite.egg-info/requires.txt
|
|
9
|
+
metta_sqlite.egg-info/top_level.txt
|
|
10
|
+
tests/test_sqlite.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pymetta==0.9.2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
metta_sqlite
|
|
@@ -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()
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Purpose: package metta-sqlite, one distribution for one library.
|
|
2
|
+
# Assumes: pymetta of the same version is installed; this is a workspace member
|
|
3
|
+
# released with it and pinned to it exactly.
|
|
4
|
+
# Guarantees: importing metta_sqlite registers this package's rows, and so does the
|
|
5
|
+
# `metta.extensions` entry point below when a dispatch discovers it.
|
|
6
|
+
# Decides: the dependency set is this library and nothing else, which is what
|
|
7
|
+
# makes "the core names no library" hold without an allowlist.
|
|
8
|
+
[build-system]
|
|
9
|
+
requires = ["setuptools>=83"]
|
|
10
|
+
build-backend = "setuptools.build_meta"
|
|
11
|
+
|
|
12
|
+
[project]
|
|
13
|
+
name = "metta-sqlite"
|
|
14
|
+
version = "0.9.2"
|
|
15
|
+
description = "sqlite3 as a SQL engine a MeTTa head can be registered into"
|
|
16
|
+
readme = "README.md"
|
|
17
|
+
requires-python = ">=3.12"
|
|
18
|
+
license = "MIT"
|
|
19
|
+
dependencies = [
|
|
20
|
+
#: pymetta of exactly this version. A member is released with the core and
|
|
21
|
+
#: reads its seam, so a floating pin would let a row meet a seam that no
|
|
22
|
+
#: longer declares its point.
|
|
23
|
+
"pymetta==0.9.2",
|
|
24
|
+
]
|
|
25
|
+
classifiers = [
|
|
26
|
+
"Development Status :: 3 - Alpha",
|
|
27
|
+
"Programming Language :: Python :: 3",
|
|
28
|
+
"Intended Audience :: Science/Research",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
#: How a seat that never heard of this package finds it: one entry in the
|
|
32
|
+
#: group `metta.seam` reads, loaded at the first dispatch that has no answer
|
|
33
|
+
#: without it. The target is the MODULE, whose body registers on import, which
|
|
34
|
+
#: is the same door `import metta_sqlite` opens.
|
|
35
|
+
[project.entry-points."metta.extensions"]
|
|
36
|
+
metta-sqlite = "metta_sqlite"
|
|
37
|
+
|
|
38
|
+
[tool.setuptools]
|
|
39
|
+
py-modules = ["metta_sqlite"]
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Purpose: prove the sqlite3 row registers a MeTTa head as a SQL function.
|
|
2
|
+
|
|
3
|
+
Blackbox through `metta.tables.sql_function`, which is the door a program
|
|
4
|
+
takes; this package's row is what makes a sqlite3 connection one the seat
|
|
5
|
+
recognises.
|
|
6
|
+
Open Obligations:
|
|
7
|
+
To Do: None
|
|
8
|
+
Hacks: None
|
|
9
|
+
Future Enhancements: None
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import sqlite3
|
|
15
|
+
|
|
16
|
+
import metta_sqlite # noqa: F401 -- imported for the sql row it registers
|
|
17
|
+
|
|
18
|
+
from metta import seam, tables
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_the_row_is_registered_against_the_sql_point():
|
|
22
|
+
"""One row, named for the engine, carrying claims and define."""
|
|
23
|
+
row = seam.sql.find("sqlite3")
|
|
24
|
+
assert row is not None
|
|
25
|
+
assert not row.fallback
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_an_undeclared_head_registers_by_its_arity(scratch_space):
|
|
29
|
+
"""sqlite3 wants the arity and no types, so no arrow is needed."""
|
|
30
|
+
scratch_space.run("(= (dbl $x) (* 2 $x))")
|
|
31
|
+
connection = sqlite3.connect(":memory:")
|
|
32
|
+
try:
|
|
33
|
+
assert tables.sql_function(connection, scratch_space.fn.dbl) == "dbl"
|
|
34
|
+
assert connection.execute("select dbl(21)").fetchone() == (42,)
|
|
35
|
+
finally:
|
|
36
|
+
connection.close()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_a_foreign_connection_is_declined(scratch_space):
|
|
40
|
+
"""A connection this engine does not own leaves the next row to answer."""
|
|
41
|
+
scratch_space.run("(= (dbl $x) (* 2 $x))")
|
|
42
|
+
|
|
43
|
+
class SqliteProbeConnection:
|
|
44
|
+
"""Not a connection any registered engine claims."""
|
|
45
|
+
|
|
46
|
+
assert seam.sql.claim(SqliteProbeConnection()) is None
|