database-wrapper-mssql 0.1.28__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,92 @@
1
+ Metadata-Version: 2.1
2
+ Name: database_wrapper_mssql
3
+ Version: 0.1.28
4
+ Summary: database_wrapper for MSSQL 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,mssql,sqlserver
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.1.28
36
+ Requires-Dist: pymssql>=2.2.10
37
+
38
+ # database_wrapper
39
+
40
+ _Part of the `database_wrapper` package._
41
+
42
+ This python package is a database wrapper for [MSSQL](https://www.microsoft.com/en-us/sql-server/sql-server-downloads) databases.
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ pip install database_wrapper[mssql]
48
+ ```
49
+
50
+ ## Usage
51
+
52
+ ```python
53
+ from database_wrapper_mssql import MSSQL, DBWrapperMSSQL
54
+
55
+ db = MSSQL({
56
+ "hostname": "localhost",
57
+ "port": "1433",
58
+ "username": "sa",
59
+ "password": "your_password",
60
+ "database": "master"
61
+ })
62
+ db.open()
63
+ dbWrapper = DBWrapperMSSQL(db=db)
64
+
65
+ # Simple query
66
+ aModel = MyModel()
67
+ res = await dbWrapper.getByKey(
68
+ aModel,
69
+ "id",
70
+ 3005,
71
+ )
72
+ if res:
73
+ print(f"getByKey: {res.toDict()}")
74
+ else:
75
+ print("No results")
76
+
77
+ # Raw query
78
+ res = await dbWrapper.getAll(
79
+ aModel,
80
+ """
81
+ SELECT t1.*, t2.name AS other_name
82
+ FROM my_table AS t1
83
+ LEFT JOIN other_table AS t2 ON t1.other_id = t2.id
84
+ """
85
+ )
86
+ async for record in res:
87
+ print(f"getAll: {record.toDict()}")
88
+ else:
89
+ print("No results")
90
+
91
+ db.close()
92
+ ```
@@ -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 [MSSQL](https://www.microsoft.com/en-us/sql-server/sql-server-downloads) databases.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install database_wrapper[mssql]
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```python
16
+ from database_wrapper_mssql import MSSQL, DBWrapperMSSQL
17
+
18
+ db = MSSQL({
19
+ "hostname": "localhost",
20
+ "port": "1433",
21
+ "username": "sa",
22
+ "password": "your_password",
23
+ "database": "master"
24
+ })
25
+ db.open()
26
+ dbWrapper = DBWrapperMSSQL(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
+ """
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_mssql package - MSSQL 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_mssql import DBWrapperMSSQL
12
+ from .connector import MsConfig, MSSQL
13
+
14
+ # Set the logger to a quiet default, can be enabled if needed
15
+ logger = logging.getLogger("database_wrapper_mssql")
16
+ if logger.level == logging.NOTSET:
17
+ logger.setLevel(logging.WARNING)
18
+
19
+
20
+ __all__ = [
21
+ "DBWrapperMSSQL",
22
+ "MsConfig",
23
+ "MSSQL",
24
+ ]
@@ -0,0 +1,86 @@
1
+ from typing import Any, NotRequired, TypedDict
2
+
3
+ from pymssql import (
4
+ connect as MssqlConnect,
5
+ Connection as MssqlConnection,
6
+ Cursor as MssqlCursor,
7
+ )
8
+
9
+ from database_wrapper import DatabaseBackend
10
+
11
+
12
+ class MsConfig(TypedDict):
13
+ hostname: str
14
+ port: NotRequired[str]
15
+ username: str
16
+ password: str
17
+ database: str
18
+ tds_version: NotRequired[str]
19
+ kwargs: NotRequired[dict[str, Any]]
20
+
21
+
22
+ class MSSQL(DatabaseBackend):
23
+ """
24
+ MSSQL database backend
25
+
26
+ :param config: Configuration for MSSQL
27
+ :type config: MsConfig
28
+
29
+ Defaults:
30
+ port = 1433
31
+ tds_version = 7.0
32
+ """
33
+
34
+ config: MsConfig
35
+
36
+ connection: MssqlConnection
37
+ cursor: MssqlCursor
38
+
39
+ def open(self):
40
+ self.logger.debug("Connecting to DB")
41
+
42
+ # Set defaults
43
+ if "port" not in self.config or not self.config["port"]:
44
+ self.config["port"] = "1433"
45
+
46
+ if "tds_version" not in self.config or not self.config["tds_version"]:
47
+ self.config["tds_version"] = "7.0"
48
+
49
+ if "kwargs" not in self.config or not self.config["kwargs"]:
50
+ self.config["kwargs"] = {}
51
+
52
+ self.connection = MssqlConnect(
53
+ server=self.config["hostname"],
54
+ user=self.config["username"],
55
+ password=self.config["password"],
56
+ database=self.config["database"],
57
+ port=self.config["port"],
58
+ tds_version="7.0",
59
+ as_dict=True,
60
+ timeout=self.connectionTimeout,
61
+ login_timeout=self.connectionTimeout,
62
+ **self.config["kwargs"],
63
+ )
64
+ self.cursor = self.connection.cursor(as_dict=True)
65
+
66
+ def lastInsertId(self) -> int:
67
+ assert self.cursor, "Cursor is not initialized"
68
+ return self.cursor.lastrowid
69
+
70
+ def affectedRows(self) -> int:
71
+ assert self.cursor, "Cursor is not initialized"
72
+ return self.cursor.rowcount
73
+
74
+ def commit(self) -> None:
75
+ """Commit DB queries"""
76
+ assert self.connection, "Connection is not initialized"
77
+
78
+ self.logger.debug(f"Commit DB queries")
79
+ self.connection.commit()
80
+
81
+ def rollback(self) -> None:
82
+ """Rollback DB queries"""
83
+ assert self.connection, "Connection is not initialized"
84
+
85
+ self.logger.debug(f"Rollback DB queries")
86
+ self.connection.rollback()
@@ -0,0 +1,65 @@
1
+ import logging
2
+ from pymssql import (
3
+ Connection as MssqlConnection,
4
+ Cursor as MssqlCursor,
5
+ )
6
+
7
+ from database_wrapper import DBWrapper, DBDataModel
8
+
9
+ from .connector import MSSQL
10
+
11
+
12
+ class DBWrapperMSSQL(DBWrapper):
13
+ """Database wrapper for mssql database"""
14
+
15
+ # Override db instance
16
+ db: MSSQL
17
+
18
+ #######################
19
+ ### Class lifecycle ###
20
+ #######################
21
+
22
+ # Meta methods
23
+ def __init__(
24
+ self,
25
+ db: MSSQL,
26
+ dbConn: MssqlConnection | None = None,
27
+ logger: logging.Logger | None = None,
28
+ ):
29
+ """
30
+ Initializes a new instance of the DBWrapper class.
31
+
32
+ Args:
33
+ db (MSSQL): The MSSQL object.
34
+ logger (logging.Logger, optional): The logger object. Defaults to None.
35
+ """
36
+ super().__init__(db, dbConn, logger)
37
+
38
+ ######################
39
+ ### Helper methods ###
40
+ ######################
41
+
42
+ async def createCursor(
43
+ self,
44
+ emptyDataClass: DBDataModel | None = None,
45
+ ) -> MssqlCursor:
46
+ """
47
+ Creates a new cursor object.
48
+
49
+ Args:
50
+ emptyDataClass (DBDataModel | None, optional): The data model to use for the cursor. Defaults to None.
51
+
52
+ Returns:
53
+ PgAsyncCursorType | AsyncCursor[DBDataModel]: The created cursor object.
54
+ """
55
+ return self.db.connection.cursor(as_dict=True)
56
+
57
+ #####################
58
+ ### Query methods ###
59
+ #####################
60
+
61
+ def limitQuery(self, offset: int = 0, limit: int = 100) -> str:
62
+ return f"""
63
+ OFFSET {offset} ROWS
64
+ FETCH NEXT {limit} ROWS ONLY
65
+ """
@@ -0,0 +1,92 @@
1
+ Metadata-Version: 2.1
2
+ Name: database_wrapper_mssql
3
+ Version: 0.1.28
4
+ Summary: database_wrapper for MSSQL 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,mssql,sqlserver
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.1.28
36
+ Requires-Dist: pymssql>=2.2.10
37
+
38
+ # database_wrapper
39
+
40
+ _Part of the `database_wrapper` package._
41
+
42
+ This python package is a database wrapper for [MSSQL](https://www.microsoft.com/en-us/sql-server/sql-server-downloads) databases.
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ pip install database_wrapper[mssql]
48
+ ```
49
+
50
+ ## Usage
51
+
52
+ ```python
53
+ from database_wrapper_mssql import MSSQL, DBWrapperMSSQL
54
+
55
+ db = MSSQL({
56
+ "hostname": "localhost",
57
+ "port": "1433",
58
+ "username": "sa",
59
+ "password": "your_password",
60
+ "database": "master"
61
+ })
62
+ db.open()
63
+ dbWrapper = DBWrapperMSSQL(db=db)
64
+
65
+ # Simple query
66
+ aModel = MyModel()
67
+ res = await dbWrapper.getByKey(
68
+ aModel,
69
+ "id",
70
+ 3005,
71
+ )
72
+ if res:
73
+ print(f"getByKey: {res.toDict()}")
74
+ else:
75
+ print("No results")
76
+
77
+ # Raw query
78
+ res = await dbWrapper.getAll(
79
+ aModel,
80
+ """
81
+ SELECT t1.*, t2.name AS other_name
82
+ FROM my_table AS t1
83
+ LEFT JOIN other_table AS t2 ON t1.other_id = t2.id
84
+ """
85
+ )
86
+ async for record in res:
87
+ print(f"getAll: {record.toDict()}")
88
+ else:
89
+ print("No results")
90
+
91
+ db.close()
92
+ ```
@@ -0,0 +1,11 @@
1
+ README.md
2
+ pyproject.toml
3
+ database_wrapper_mssql/__init__.py
4
+ database_wrapper_mssql/connector.py
5
+ database_wrapper_mssql/db_wrapper_mssql.py
6
+ database_wrapper_mssql/py.typed
7
+ database_wrapper_mssql.egg-info/PKG-INFO
8
+ database_wrapper_mssql.egg-info/SOURCES.txt
9
+ database_wrapper_mssql.egg-info/dependency_links.txt
10
+ database_wrapper_mssql.egg-info/requires.txt
11
+ database_wrapper_mssql.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ database_wrapper==0.1.28
2
+ pymssql>=2.2.10
@@ -0,0 +1 @@
1
+ database_wrapper_mssql
@@ -0,0 +1,51 @@
1
+ [build-system]
2
+ requires = ["setuptools >= 61.0.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "database_wrapper_mssql"
7
+ version = "0.1.28"
8
+ description = "database_wrapper for MSSQL database"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = {text = "GNU General Public License v3.0 (GPL-3.0)"}
12
+ authors = [
13
+ {name = "Gints Murans", email = "gm@gm.lv"}
14
+ ]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
19
+ "Operating System :: MacOS :: MacOS X",
20
+ "Operating System :: Microsoft :: Windows",
21
+ "Operating System :: POSIX",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3.8",
24
+ "Programming Language :: Python :: 3.9",
25
+ "Programming Language :: Python :: 3.10",
26
+ "Programming Language :: Python :: 3.11",
27
+ "Programming Language :: Python :: 3.12",
28
+ "Programming Language :: Python :: 3.13",
29
+ "Programming Language :: Python :: Implementation :: CPython",
30
+ "Programming Language :: Python :: Implementation :: PyPy",
31
+ "Topic :: Database",
32
+ "Topic :: Database :: Front-Ends",
33
+ "Topic :: Software Development",
34
+ "Topic :: Software Development :: Libraries :: Python Modules"
35
+ ]
36
+ keywords = ["database", "wrapper", "python", "mssql", "sqlserver"]
37
+ dependencies = [
38
+ "database_wrapper == 0.1.28",
39
+ "pymssql >= 2.2.10",
40
+ ]
41
+
42
+ [project.urls]
43
+ Homepage = "https://github.com/gintsmurans/py_database_wrapper"
44
+ Documentation = "https://github.com/gintsmurans/py_database_wrapper"
45
+ Changes = "https://github.com/gintsmurans/py_database_wrapper"
46
+ Code = "https://github.com/gintsmurans/py_database_wrapper"
47
+ "Issue Tracker" = "https://github.com/gintsmurans/py_database_wrapper/issues"
48
+ Download = "https://pypi.org/project/database_wrapper/"
49
+
50
+ [tool.setuptools.package-data]
51
+ database_wrapper_mssql = ["py.typed"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+