database-wrapper-sqlite 0.2.12__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.
- database_wrapper_sqlite/__init__.py +24 -0
- database_wrapper_sqlite/connector.py +63 -0
- database_wrapper_sqlite/py.typed +0 -0
- database_wrapper_sqlite-0.2.12.dist-info/METADATA +91 -0
- database_wrapper_sqlite-0.2.12.dist-info/RECORD +7 -0
- database_wrapper_sqlite-0.2.12.dist-info/WHEEL +5 -0
- database_wrapper_sqlite-0.2.12.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
database_wrapper_sqlite package - Sqlite database wrapper
|
|
3
|
+
|
|
4
|
+
Part of the database_wrapper package
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
# Copyright 2024 Gints Murans
|
|
8
|
+
|
|
9
|
+
import logging
|
|
10
|
+
|
|
11
|
+
# from .db_wrapper_sqlite import DBWrapperSqlite
|
|
12
|
+
from .connector import SqliteConfig, Sqlite
|
|
13
|
+
|
|
14
|
+
# Set the logger to a quiet default, can be enabled if needed
|
|
15
|
+
logger = logging.getLogger("database_wrapper_sqlite")
|
|
16
|
+
if logger.level == logging.NOTSET:
|
|
17
|
+
logger.setLevel(logging.WARNING)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
# "DBWrapperSqlite",
|
|
22
|
+
"SqliteConfig",
|
|
23
|
+
"Sqlite",
|
|
24
|
+
]
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from typing import Any, NotRequired, TypedDict
|
|
2
|
+
|
|
3
|
+
from database_wrapper import DatabaseBackend
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SqliteConfig(TypedDict):
|
|
7
|
+
database: str
|
|
8
|
+
kwargs: NotRequired[dict[str, Any]]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# TODO: Needs to finish the implementation
|
|
12
|
+
class Sqlite(DatabaseBackend):
|
|
13
|
+
"""
|
|
14
|
+
Sqlite database backend
|
|
15
|
+
|
|
16
|
+
:param config: Configuration for Sqlite
|
|
17
|
+
:type config: MyConfig
|
|
18
|
+
|
|
19
|
+
Defaults:
|
|
20
|
+
_no defaults_
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
config: SqliteConfig
|
|
24
|
+
|
|
25
|
+
connection: Any
|
|
26
|
+
cursor: Any
|
|
27
|
+
|
|
28
|
+
def open(self) -> None:
|
|
29
|
+
# Free resources
|
|
30
|
+
if hasattr(self, "connection") and self.connection:
|
|
31
|
+
self.close()
|
|
32
|
+
|
|
33
|
+
# Set defaults
|
|
34
|
+
if "kwargs" not in self.config or not self.config["kwargs"]:
|
|
35
|
+
self.config["kwargs"] = {}
|
|
36
|
+
|
|
37
|
+
self.logger.debug("Connecting to DB")
|
|
38
|
+
|
|
39
|
+
raise NotImplementedError(
|
|
40
|
+
"Sqlite is not yet implemented. See here: https://github.com/gintsmurans/py_database_wrapper/"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
def last_insert_id(self) -> int:
|
|
44
|
+
assert self.cursor, "Cursor is not initialized"
|
|
45
|
+
return self.cursor.lastrowid
|
|
46
|
+
|
|
47
|
+
def affected_rows(self) -> int:
|
|
48
|
+
assert self.cursor, "Cursor is not initialized"
|
|
49
|
+
return self.cursor.rowcount
|
|
50
|
+
|
|
51
|
+
def commit(self) -> None:
|
|
52
|
+
"""Commit DB queries"""
|
|
53
|
+
assert self.connection, "Connection is not initialized"
|
|
54
|
+
|
|
55
|
+
self.logger.debug("Commit DB queries..")
|
|
56
|
+
self.connection.commit()
|
|
57
|
+
|
|
58
|
+
def rollback(self) -> None:
|
|
59
|
+
"""Rollback DB queries"""
|
|
60
|
+
assert self.connection, "Connection is not initialized"
|
|
61
|
+
|
|
62
|
+
self.logger.debug("Rollback DB queries..")
|
|
63
|
+
self.connection.rollback()
|
|
File without changes
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: database_wrapper_sqlite
|
|
3
|
+
Version: 0.2.12
|
|
4
|
+
Summary: database_wrapper for PostgreSQL database
|
|
5
|
+
Author-email: Gints Murans <gm@gm.lv>
|
|
6
|
+
License: GNU General Public License v3.0 (GPL-3.0)
|
|
7
|
+
Project-URL: Homepage, https://github.com/gintsmurans/py_database_wrapper
|
|
8
|
+
Project-URL: Documentation, https://github.com/gintsmurans/py_database_wrapper
|
|
9
|
+
Project-URL: Changes, https://github.com/gintsmurans/py_database_wrapper
|
|
10
|
+
Project-URL: Code, https://github.com/gintsmurans/py_database_wrapper
|
|
11
|
+
Project-URL: Issue Tracker, https://github.com/gintsmurans/py_database_wrapper/issues
|
|
12
|
+
Project-URL: Download, https://pypi.org/project/database_wrapper/
|
|
13
|
+
Keywords: database,wrapper,python,sqlite
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
17
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
18
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
19
|
+
Classifier: Operating System :: POSIX
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
27
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
28
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
29
|
+
Classifier: Topic :: Database
|
|
30
|
+
Classifier: Topic :: Database :: Front-Ends
|
|
31
|
+
Classifier: Topic :: Software Development
|
|
32
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
33
|
+
Requires-Python: >=3.8
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
Requires-Dist: database_wrapper==0.2.12
|
|
36
|
+
|
|
37
|
+
# database_wrapper_sqlite
|
|
38
|
+
|
|
39
|
+
_Part of the `database_wrapper` package._
|
|
40
|
+
|
|
41
|
+
This python package is a database wrapper for [sqlite](https://www.sqlite.org/) database.
|
|
42
|
+
|
|
43
|
+
## !!! IMPORTANT !!!
|
|
44
|
+
|
|
45
|
+
This package is not yet implemented. The README is a placeholder for future implementation.
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install database_wrapper[sqlite]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from database_wrapper_sqlite import Sqlite, DBWrapperSqlite
|
|
57
|
+
|
|
58
|
+
db = Sqlite({
|
|
59
|
+
"database": "my_database.db",
|
|
60
|
+
})
|
|
61
|
+
db.open()
|
|
62
|
+
dbWrapper = DBWrapperSqlite(dbCursor=db.cursor)
|
|
63
|
+
|
|
64
|
+
# Simple query
|
|
65
|
+
aModel = MyModel()
|
|
66
|
+
res = await dbWrapper.getByKey(
|
|
67
|
+
aModel,
|
|
68
|
+
"id",
|
|
69
|
+
3005,
|
|
70
|
+
)
|
|
71
|
+
if res:
|
|
72
|
+
print(f"getByKey: {res.toDict()}")
|
|
73
|
+
else:
|
|
74
|
+
print("No results")
|
|
75
|
+
|
|
76
|
+
# Raw query
|
|
77
|
+
res = await dbWrapper.getAll(
|
|
78
|
+
aModel,
|
|
79
|
+
customQuery="""
|
|
80
|
+
SELECT t1.*, t2.name AS other_name
|
|
81
|
+
FROM my_table AS t1
|
|
82
|
+
LEFT JOIN other_table AS t2 ON t1.other_id = t2.id
|
|
83
|
+
"""
|
|
84
|
+
)
|
|
85
|
+
async for record in res:
|
|
86
|
+
print(f"getAll: {record.toDict()}")
|
|
87
|
+
else:
|
|
88
|
+
print("No results")
|
|
89
|
+
|
|
90
|
+
db.close()
|
|
91
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
database_wrapper_sqlite/__init__.py,sha256=r1Kw78EQGgfsxuiTvTMpY_SWIfjD-h7dLv3NJ6TzJnY,509
|
|
2
|
+
database_wrapper_sqlite/connector.py,sha256=kZtVpBLtdCof5Pjj8fS8EMp0R_z-NQo_EV2kH_crRa0,1635
|
|
3
|
+
database_wrapper_sqlite/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
database_wrapper_sqlite-0.2.12.dist-info/METADATA,sha256=NYUt2Ow-POwiVI8LIqS8oiASKcr3eKbrgqQME__aTz4,2823
|
|
5
|
+
database_wrapper_sqlite-0.2.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
6
|
+
database_wrapper_sqlite-0.2.12.dist-info/top_level.txt,sha256=53mm8n6modSF012UMCHllRLbCLajpC0uDwHE0WU1Lxo,24
|
|
7
|
+
database_wrapper_sqlite-0.2.12.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
database_wrapper_sqlite
|