SQLPyHelper 0.1.1__tar.gz → 0.1.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.
@@ -1,12 +1,15 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SQLPyHelper
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: A simple SQL database helper package for Python.
5
5
  Author: Adebayo Olaonipekun
6
6
  Author-email: pekunmi@live.com
7
7
  Classifier: Programming Language :: Python :: 3
8
- Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Development Status :: 5 - Production/Stable
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Topic :: Database :: Database Engines/Servers
9
11
  Classifier: Operating System :: OS Independent
12
+ Classifier: License :: OSI Approved :: MIT License
10
13
  Requires-Python: >=3.8
11
14
  Description-Content-Type: text/markdown
12
15
  License-File: LICENSE
@@ -15,12 +18,22 @@ Requires-Dist: mysql-connector-python
15
18
  Requires-Dist: pyodbc
16
19
  Requires-Dist: cx_Oracle
17
20
  Requires-Dist: python-dotenv
21
+ Provides-Extra: mysql
22
+ Requires-Dist: mysql-connector-python; extra == "mysql"
23
+ Provides-Extra: postgres
24
+ Requires-Dist: psycopg2; extra == "postgres"
25
+ Provides-Extra: oracle
26
+ Requires-Dist: cx_Oracle; extra == "oracle"
27
+ Provides-Extra: sqlserver
28
+ Requires-Dist: pyodbc; extra == "sqlserver"
29
+ Provides-Extra: sqlite
18
30
  Dynamic: author
19
31
  Dynamic: author-email
20
32
  Dynamic: classifier
21
33
  Dynamic: description
22
34
  Dynamic: description-content-type
23
35
  Dynamic: license-file
36
+ Dynamic: provides-extra
24
37
  Dynamic: requires-dist
25
38
  Dynamic: requires-python
26
39
  Dynamic: summary
@@ -54,9 +67,12 @@ A Python library for simplified database interactions across **SQLite, PostgreSQ
54
67
 
55
68
  ---
56
69
  ## 📦 Installation
70
+ #### Install via PyPI:
57
71
  ```sh
58
72
  pip install sqlpyhelper
59
73
  ```
74
+ 📌 Package on PyPI: [SQLPyHelper on PyPI](https://pypi.org/project/SQLPyHelper/)
75
+
60
76
  Or, if working from source:
61
77
  ```sh
62
78
  git clone https://github.com/adebayopeter/sqlpyhelper.git
@@ -75,11 +91,10 @@ DB_TYPE=postgres
75
91
  DB_HOST=localhost
76
92
  DB_USER=your_user
77
93
  DB_PASSWORD=your_secure_password
78
- DB_NAME=test_db
79
- DB_PORT=5432
94
+ DB_NAME=database_name
80
95
  DB_DRIVER={ODBC Driver 17 for SQL Server}
81
96
  ORACLE_SID=XE
82
- ORACLE_PORT=1521
97
+ ORACLE_DB_PORT=1521
83
98
  ```
84
99
  ### Loading `.env` in Code
85
100
  ```pycon
@@ -124,6 +139,16 @@ db.execute_query("SELECT * FROM customers")
124
139
  print(db.fetch_all())
125
140
  db.close()
126
141
  ```
142
+ ```pycon
143
+ db = SQLPyHelper()
144
+
145
+ # Fetch rows where customer_id = 3
146
+ customers = db.fetch_by_param("customers", "id", 3)
147
+ print(customers)
148
+
149
+ db.close()
150
+ ```
151
+
127
152
  ### SQL Server Example
128
153
  ```pycon
129
154
  db = SQLPyHelper()
@@ -27,9 +27,12 @@ A Python library for simplified database interactions across **SQLite, PostgreSQ
27
27
 
28
28
  ---
29
29
  ## 📦 Installation
30
+ #### Install via PyPI:
30
31
  ```sh
31
32
  pip install sqlpyhelper
32
33
  ```
34
+ 📌 Package on PyPI: [SQLPyHelper on PyPI](https://pypi.org/project/SQLPyHelper/)
35
+
33
36
  Or, if working from source:
34
37
  ```sh
35
38
  git clone https://github.com/adebayopeter/sqlpyhelper.git
@@ -48,11 +51,10 @@ DB_TYPE=postgres
48
51
  DB_HOST=localhost
49
52
  DB_USER=your_user
50
53
  DB_PASSWORD=your_secure_password
51
- DB_NAME=test_db
52
- DB_PORT=5432
54
+ DB_NAME=database_name
53
55
  DB_DRIVER={ODBC Driver 17 for SQL Server}
54
56
  ORACLE_SID=XE
55
- ORACLE_PORT=1521
57
+ ORACLE_DB_PORT=1521
56
58
  ```
57
59
  ### Loading `.env` in Code
58
60
  ```pycon
@@ -97,6 +99,16 @@ db.execute_query("SELECT * FROM customers")
97
99
  print(db.fetch_all())
98
100
  db.close()
99
101
  ```
102
+ ```pycon
103
+ db = SQLPyHelper()
104
+
105
+ # Fetch rows where customer_id = 3
106
+ customers = db.fetch_by_param("customers", "id", 3)
107
+ print(customers)
108
+
109
+ db.close()
110
+ ```
111
+
100
112
  ### SQL Server Example
101
113
  ```pycon
102
114
  db = SQLPyHelper()
@@ -1,12 +1,15 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SQLPyHelper
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: A simple SQL database helper package for Python.
5
5
  Author: Adebayo Olaonipekun
6
6
  Author-email: pekunmi@live.com
7
7
  Classifier: Programming Language :: Python :: 3
8
- Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Development Status :: 5 - Production/Stable
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Topic :: Database :: Database Engines/Servers
9
11
  Classifier: Operating System :: OS Independent
12
+ Classifier: License :: OSI Approved :: MIT License
10
13
  Requires-Python: >=3.8
11
14
  Description-Content-Type: text/markdown
12
15
  License-File: LICENSE
@@ -15,12 +18,22 @@ Requires-Dist: mysql-connector-python
15
18
  Requires-Dist: pyodbc
16
19
  Requires-Dist: cx_Oracle
17
20
  Requires-Dist: python-dotenv
21
+ Provides-Extra: mysql
22
+ Requires-Dist: mysql-connector-python; extra == "mysql"
23
+ Provides-Extra: postgres
24
+ Requires-Dist: psycopg2; extra == "postgres"
25
+ Provides-Extra: oracle
26
+ Requires-Dist: cx_Oracle; extra == "oracle"
27
+ Provides-Extra: sqlserver
28
+ Requires-Dist: pyodbc; extra == "sqlserver"
29
+ Provides-Extra: sqlite
18
30
  Dynamic: author
19
31
  Dynamic: author-email
20
32
  Dynamic: classifier
21
33
  Dynamic: description
22
34
  Dynamic: description-content-type
23
35
  Dynamic: license-file
36
+ Dynamic: provides-extra
24
37
  Dynamic: requires-dist
25
38
  Dynamic: requires-python
26
39
  Dynamic: summary
@@ -54,9 +67,12 @@ A Python library for simplified database interactions across **SQLite, PostgreSQ
54
67
 
55
68
  ---
56
69
  ## 📦 Installation
70
+ #### Install via PyPI:
57
71
  ```sh
58
72
  pip install sqlpyhelper
59
73
  ```
74
+ 📌 Package on PyPI: [SQLPyHelper on PyPI](https://pypi.org/project/SQLPyHelper/)
75
+
60
76
  Or, if working from source:
61
77
  ```sh
62
78
  git clone https://github.com/adebayopeter/sqlpyhelper.git
@@ -75,11 +91,10 @@ DB_TYPE=postgres
75
91
  DB_HOST=localhost
76
92
  DB_USER=your_user
77
93
  DB_PASSWORD=your_secure_password
78
- DB_NAME=test_db
79
- DB_PORT=5432
94
+ DB_NAME=database_name
80
95
  DB_DRIVER={ODBC Driver 17 for SQL Server}
81
96
  ORACLE_SID=XE
82
- ORACLE_PORT=1521
97
+ ORACLE_DB_PORT=1521
83
98
  ```
84
99
  ### Loading `.env` in Code
85
100
  ```pycon
@@ -124,6 +139,16 @@ db.execute_query("SELECT * FROM customers")
124
139
  print(db.fetch_all())
125
140
  db.close()
126
141
  ```
142
+ ```pycon
143
+ db = SQLPyHelper()
144
+
145
+ # Fetch rows where customer_id = 3
146
+ customers = db.fetch_by_param("customers", "id", 3)
147
+ print(customers)
148
+
149
+ db.close()
150
+ ```
151
+
127
152
  ### SQL Server Example
128
153
  ```pycon
129
154
  db = SQLPyHelper()
@@ -0,0 +1,19 @@
1
+ psycopg2
2
+ mysql-connector-python
3
+ pyodbc
4
+ cx_Oracle
5
+ python-dotenv
6
+
7
+ [mysql]
8
+ mysql-connector-python
9
+
10
+ [oracle]
11
+ cx_Oracle
12
+
13
+ [postgres]
14
+ psycopg2
15
+
16
+ [sqlite]
17
+
18
+ [sqlserver]
19
+ pyodbc
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as f:
5
5
 
6
6
  setup(
7
7
  name='SQLPyHelper',
8
- version='0.1.1',
8
+ version='0.1.2',
9
9
  description='A simple SQL database helper package for Python.',
10
10
  long_description=long_description,
11
11
  long_description_content_type="text/markdown",
@@ -19,10 +19,20 @@ setup(
19
19
  'cx_Oracle',
20
20
  'python-dotenv'
21
21
  ],
22
+ extras_require={
23
+ "mysql": ["mysql-connector-python"],
24
+ "postgres": ["psycopg2"],
25
+ "oracle": ["cx_Oracle"],
26
+ "sqlserver": ["pyodbc"],
27
+ "sqlite": []
28
+ },
22
29
  python_requires=">=3.8",
23
30
  classifiers=[
24
31
  "Programming Language :: Python :: 3",
25
- "License :: OSI Approved :: MIT License",
26
- "Operating System :: OS Independent"
32
+ "Development Status :: 5 - Production/Stable",
33
+ "Intended Audience :: Developers",
34
+ "Topic :: Database :: Database Engines/Servers",
35
+ "Operating System :: OS Independent",
36
+ "License :: OSI Approved :: MIT License"
27
37
  ],
28
38
  )
@@ -1,2 +1,2 @@
1
1
  # Match the version in setup.py
2
- __version__ = "0.1.1"
2
+ __version__ = "0.1.2"
@@ -1,16 +1,16 @@
1
- import sqlite3
2
- import psycopg2
3
- import mysql.connector
4
- import pyodbc
5
- import cx_Oracle
6
1
  import csv
7
- from psycopg2 import pool
8
2
  from dotenv import load_dotenv
9
3
  import os
10
4
 
11
5
  load_dotenv() # Load environment variables from .env file
12
6
 
13
7
 
8
+ def log_query(query):
9
+ """Logs queries for debugging purposes."""
10
+ with open("query_log.txt", "a") as f:
11
+ f.write(query + "\n")
12
+
13
+
14
14
  class SQLPyHelper:
15
15
  def __init__(self):
16
16
  self.db_type = os.getenv("DB_TYPE").lower()
@@ -20,19 +20,25 @@ class SQLPyHelper:
20
20
  self.database = os.getenv("DB_NAME")
21
21
  self.driver = os.getenv("DB_DRIVER")
22
22
  self.oracle_sid = os.getenv("ORACLE_SID")
23
+ self.pool = None
23
24
 
24
25
  if self.db_type == "sqlite":
26
+ import sqlite3
25
27
  self.connection = sqlite3.connect(self.database)
26
28
  elif self.db_type == "postgres":
29
+ import psycopg2
27
30
  self.connection = psycopg2.connect(host=self.host, user=self.user,
28
31
  password=self.password, dbname=self.database)
29
32
  elif self.db_type == "mysql":
33
+ import mysql.connector
30
34
  self.connection = mysql.connector.connect(host=self.host, user=self.user,
31
35
  password=self.password, database=self.database)
32
36
  elif self.db_type == "sqlserver":
37
+ import pyodbc
33
38
  self.connection = pyodbc.connect(f"DRIVER={self.driver};SERVER={self.host};DATABASE={self.database};"
34
39
  f"UID={self.user};PWD={self.password}")
35
40
  elif self.db_type == "oracle":
41
+ import cx_Oracle
36
42
  oracle_port = os.getenv("ORACLE_DB_PORT", "1521") # Default to 1521 if not set
37
43
  dsn = cx_Oracle.makedsn(self.host, oracle_port, self.oracle_sid)
38
44
  self.connection = cx_Oracle.connect(self.user, self.password, dsn)
@@ -52,10 +58,18 @@ class SQLPyHelper:
52
58
  except Exception as e:
53
59
  print(f"Error executing query: {e}")
54
60
 
61
+ def fetch_one(self):
62
+ return self.cursor.fetchone()
63
+
55
64
  def fetch_all(self):
56
65
  """Fetches all rows from the last executed query"""
57
66
  return self.cursor.fetchall()
58
67
 
68
+ def fetch_by_param(self, table_name, column_name, value):
69
+ query = f"SELECT * FROM {table_name} WHERE {column_name} = %s"
70
+ self.cursor.execute(query, (value,))
71
+ return self.cursor.fetchall() # Fetch matching rows
72
+
59
73
  def close(self):
60
74
  """Closes the connection"""
61
75
  self.cursor.close()
@@ -84,11 +98,6 @@ class SQLPyHelper:
84
98
  self.cursor.executemany(query, values)
85
99
  self.connection.commit()
86
100
 
87
- def log_query(self, query):
88
- """Logs queries for debugging purposes."""
89
- with open("query_log.txt", "a") as f:
90
- f.write(query + "\n")
91
-
92
101
  def backup_table(self, table_name, backup_file):
93
102
  """
94
103
  Exports table data into a CSV file.
@@ -110,6 +119,7 @@ class SQLPyHelper:
110
119
  Example:
111
120
  setup_postgres_pool(min_conn=2, max_conn=10)
112
121
  """
122
+ from psycopg2 import pool
113
123
  self.pool = pool.SimpleConnectionPool(min_conn, max_conn,
114
124
  host=self.host,
115
125
  user=self.user,
@@ -123,6 +133,3 @@ class SQLPyHelper:
123
133
  def return_connection_to_pool(self, conn):
124
134
  """Returns a connection back to the pool."""
125
135
  self.pool.putconn(conn)
126
-
127
-
128
-
@@ -1,5 +0,0 @@
1
- psycopg2
2
- mysql-connector-python
3
- pyodbc
4
- cx_Oracle
5
- python-dotenv
File without changes
File without changes