database-wrapper-sqlite 0.1.20__tar.gz → 0.1.33__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: database_wrapper_sqlite
3
- Version: 0.1.20
3
+ Version: 0.1.33
4
4
  Summary: database_wrapper for PostgreSQL database
5
5
  Author-email: Gints Murans <gm@gm.lv>
6
6
  License: GNU General Public License v3.0 (GPL-3.0)
@@ -32,4 +32,60 @@ Classifier: Topic :: Software Development
32
32
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
33
33
  Requires-Python: >=3.8
34
34
  Description-Content-Type: text/markdown
35
- Requires-Dist: database_wrapper==0.1.28
35
+ Requires-Dist: database_wrapper==0.1.33
36
+
37
+ # database_wrapper
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(db=db)
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,55 @@
1
+ # database_wrapper
2
+
3
+ _Part of the `database_wrapper` package._
4
+
5
+ This python package is a database wrapper for [sqlite](https://www.sqlite.org/) database.
6
+
7
+ ## !!! IMPORTANT !!!
8
+
9
+ This package is not yet implemented. The README is a placeholder for future implementation.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pip install database_wrapper[sqlite]
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```python
20
+ from database_wrapper_sqlite import Sqlite, DBWrapperSqlite
21
+
22
+ db = Sqlite({
23
+ "database": "my_database.db",
24
+ })
25
+ db.open()
26
+ dbWrapper = DBWrapperSqlite(db=db)
27
+
28
+ # Simple query
29
+ aModel = MyModel()
30
+ res = await dbWrapper.getByKey(
31
+ aModel,
32
+ "id",
33
+ 3005,
34
+ )
35
+ if res:
36
+ print(f"getByKey: {res.toDict()}")
37
+ else:
38
+ print("No results")
39
+
40
+ # Raw query
41
+ res = await dbWrapper.getAll(
42
+ aModel,
43
+ customQuery="""
44
+ SELECT t1.*, t2.name AS other_name
45
+ FROM my_table AS t1
46
+ LEFT JOIN other_table AS t2 ON t1.other_id = t2.id
47
+ """
48
+ )
49
+ async for record in res:
50
+ print(f"getAll: {record.toDict()}")
51
+ else:
52
+ print("No results")
53
+
54
+ db.close()
55
+ ```
@@ -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):
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 lastInsertId(self) -> int:
44
+ assert self.cursor, "Cursor is not initialized"
45
+ return self.cursor.lastrowid
46
+
47
+ def affectedRows(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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: database_wrapper_sqlite
3
- Version: 0.1.20
3
+ Version: 0.1.33
4
4
  Summary: database_wrapper for PostgreSQL database
5
5
  Author-email: Gints Murans <gm@gm.lv>
6
6
  License: GNU General Public License v3.0 (GPL-3.0)
@@ -32,4 +32,60 @@ Classifier: Topic :: Software Development
32
32
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
33
33
  Requires-Python: >=3.8
34
34
  Description-Content-Type: text/markdown
35
- Requires-Dist: database_wrapper==0.1.28
35
+ Requires-Dist: database_wrapper==0.1.33
36
+
37
+ # database_wrapper
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(db=db)
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
+ ```
@@ -1,5 +1,8 @@
1
+ README.md
1
2
  pyproject.toml
2
3
  database_wrapper_sqlite/__init__.py
4
+ database_wrapper_sqlite/connector.py
5
+ database_wrapper_sqlite/py.typed
3
6
  database_wrapper_sqlite.egg-info/PKG-INFO
4
7
  database_wrapper_sqlite.egg-info/SOURCES.txt
5
8
  database_wrapper_sqlite.egg-info/dependency_links.txt
@@ -0,0 +1 @@
1
+ database_wrapper==0.1.33
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "database_wrapper_sqlite"
7
- version = "0.1.20"
7
+ version = "0.1.33"
8
8
  description = "database_wrapper for PostgreSQL database"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -35,7 +35,7 @@ classifiers = [
35
35
  ]
36
36
  keywords = ["database", "wrapper", "python", "sqlite"]
37
37
  dependencies = [
38
- "database_wrapper == 0.1.28",
38
+ "database_wrapper == 0.1.33",
39
39
  ]
40
40
 
41
41
  [project.urls]
@@ -1 +0,0 @@
1
- raise Exception("Not yet implemented")
@@ -1 +0,0 @@
1
- database_wrapper==0.1.28