qodalis-cli-server-plugin-data-explorer-sql 1.0.0b24__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.
@@ -0,0 +1,44 @@
1
+ # Byte-compiled / optimized
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # Distribution / packaging
7
+ *.egg-info/
8
+ dist/
9
+ build/
10
+ .eggs/
11
+ *.egg
12
+
13
+ # Virtual environments
14
+ .venv/
15
+ venv/
16
+ env/
17
+
18
+ # Environment variables
19
+ .env
20
+
21
+ # Testing
22
+ .pytest_cache/
23
+ .coverage
24
+ htmlcov/
25
+ TestResults/
26
+
27
+ # Type checking / linting
28
+ .mypy_cache/
29
+ .ruff_cache/
30
+
31
+ # C extensions
32
+ *.so
33
+
34
+ # IDEs and editors
35
+ .idea/
36
+ .vscode/*
37
+ !.vscode/settings.json
38
+ !.vscode/launch.json
39
+ !.vscode/extensions.json
40
+
41
+ # System files
42
+ .DS_Store
43
+ Thumbs.db
44
+ node_modules/
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.5
2
+ Name: qodalis-cli-server-plugin-data-explorer-sql
3
+ Version: 1.0.0b24
4
+ Summary: SQLite Data Explorer provider plugin for Qodalis CLI servers
5
+ Project-URL: Homepage, https://github.com/qodalis-solutions/cli-server-python
6
+ Project-URL: Repository, https://github.com/qodalis-solutions/cli-server-python
7
+ Project-URL: Issues, https://github.com/qodalis-solutions/cli-server-python/issues
8
+ Author-email: Nicolae Lupei <nicolae.lupei@qodalis.com>
9
+ License-Expression: MIT
10
+ Keywords: cli,data-explorer,plugin,qodalis,sql,sqlite
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: qodalis-cli-server-abstractions
@@ -0,0 +1,39 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "qodalis-cli-server-plugin-data-explorer-sql"
7
+ version = "1.0.0b24"
8
+ description = "SQLite Data Explorer provider plugin for Qodalis CLI servers"
9
+ readme = { text = "", content-type = "text/plain" }
10
+ license = "MIT"
11
+ requires-python = ">=3.10"
12
+ authors = [
13
+ { name = "Nicolae Lupei", email = "nicolae.lupei@qodalis.com" },
14
+ ]
15
+ keywords = ["cli", "qodalis", "data-explorer", "sql", "sqlite", "plugin"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Intended Audience :: Developers",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ ]
26
+ dependencies = [
27
+ "qodalis-cli-server-abstractions",
28
+ ]
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/qodalis-solutions/cli-server-python"
32
+ Repository = "https://github.com/qodalis-solutions/cli-server-python"
33
+ Issues = "https://github.com/qodalis-solutions/cli-server-python/issues"
34
+
35
+ [tool.hatch.build.targets.wheel]
36
+ packages = ["qodalis_cli_data_explorer_sql"]
37
+
38
+ [tool.hatch.build.targets.sdist]
39
+ include = ["qodalis_cli_data_explorer_sql/**"]
@@ -0,0 +1,5 @@
1
+ """Qodalis CLI Data Explorer SQL plugin — SQLite provider."""
2
+
3
+ from .sql_provider import SqlDataExplorerProvider
4
+
5
+ __all__ = ["SqlDataExplorerProvider"]
@@ -0,0 +1,122 @@
1
+ """SQLite-backed Data Explorer provider."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sqlite3
6
+ import time
7
+
8
+ from qodalis_cli_server_abstractions import (
9
+ DataExplorerExecutionContext,
10
+ DataExplorerProviderOptions,
11
+ DataExplorerResult,
12
+ DataExplorerSchemaColumn,
13
+ DataExplorerSchemaResult,
14
+ DataExplorerSchemaTable,
15
+ IDataExplorerProvider,
16
+ )
17
+
18
+
19
+ class SqlDataExplorerProvider(IDataExplorerProvider):
20
+ """Executes SQL queries against a SQLite database."""
21
+
22
+ def __init__(self, filename: str = ":memory:") -> None:
23
+ self._filename = filename
24
+
25
+ async def execute_async(
26
+ self, context: DataExplorerExecutionContext
27
+ ) -> DataExplorerResult:
28
+ """Execute a SQL query against the SQLite database."""
29
+ start = time.monotonic()
30
+ conn: sqlite3.Connection | None = None
31
+ try:
32
+ conn = sqlite3.connect(self._filename)
33
+ conn.row_factory = sqlite3.Row
34
+ cursor = conn.cursor()
35
+ cursor.execute(context.query, context.parameters or {})
36
+
37
+ if cursor.description:
38
+ columns = [desc[0] for desc in cursor.description]
39
+ rows_raw = cursor.fetchall()
40
+ rows = [list(row) for row in rows_raw]
41
+ return DataExplorerResult(
42
+ success=True,
43
+ source=context.options.name,
44
+ language=context.options.language,
45
+ default_output_format=context.options.default_output_format,
46
+ execution_time=int((time.monotonic() - start) * 1000),
47
+ columns=columns,
48
+ rows=rows,
49
+ row_count=len(rows),
50
+ truncated=False,
51
+ error=None,
52
+ )
53
+ else:
54
+ conn.commit()
55
+ return DataExplorerResult(
56
+ success=True,
57
+ source=context.options.name,
58
+ language=context.options.language,
59
+ default_output_format=context.options.default_output_format,
60
+ execution_time=int((time.monotonic() - start) * 1000),
61
+ columns=["changes"],
62
+ rows=[[cursor.rowcount]],
63
+ row_count=1,
64
+ truncated=False,
65
+ error=None,
66
+ )
67
+ except Exception as exc:
68
+ return DataExplorerResult(
69
+ success=False,
70
+ source=context.options.name,
71
+ language=context.options.language,
72
+ default_output_format=context.options.default_output_format,
73
+ execution_time=int((time.monotonic() - start) * 1000),
74
+ columns=None,
75
+ rows=[],
76
+ row_count=0,
77
+ truncated=False,
78
+ error=str(exc),
79
+ )
80
+ finally:
81
+ if conn is not None:
82
+ conn.close()
83
+
84
+ async def get_schema_async(
85
+ self, options: DataExplorerProviderOptions
86
+ ) -> DataExplorerSchemaResult | None:
87
+ """Return the database schema (tables, views, and their columns)."""
88
+ conn: sqlite3.Connection | None = None
89
+ try:
90
+ conn = sqlite3.connect(self._filename)
91
+ cursor = conn.cursor()
92
+
93
+ cursor.execute(
94
+ "SELECT name, type FROM sqlite_master "
95
+ "WHERE type IN ('table', 'view') AND name NOT LIKE 'sqlite_%' "
96
+ "ORDER BY name"
97
+ )
98
+ table_rows = cursor.fetchall()
99
+
100
+ tables: list[DataExplorerSchemaTable] = []
101
+ for table_name, table_type in table_rows:
102
+ cursor.execute(f'PRAGMA table_info("{table_name}")')
103
+ col_rows = cursor.fetchall()
104
+ columns = [
105
+ DataExplorerSchemaColumn(
106
+ name=row[1],
107
+ type=row[2] or "TEXT",
108
+ nullable=row[3] == 0,
109
+ primary_key=row[5] > 0,
110
+ )
111
+ for row in col_rows
112
+ ]
113
+ tables.append(DataExplorerSchemaTable(
114
+ name=table_name,
115
+ type=table_type,
116
+ columns=columns,
117
+ ))
118
+
119
+ return DataExplorerSchemaResult(source=options.name, tables=tables)
120
+ finally:
121
+ if conn is not None:
122
+ conn.close()