pgconnect 0.0.1__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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,271 @@
1
+ Metadata-Version: 2.1
2
+ Name: pgconnect
3
+ Version: 0.0.1
4
+ Summary: A PostgreSQL connection and ORM library
5
+ Home-page: https://github.com/AdnanBinPulok/PgConnect
6
+ Author: AdnanBinPulok
7
+ Author-email: Adnan Bin Pulok <adnanbinpulok@gmail.com>
8
+ Project-URL: Homepage, https://github.com/adnanbinpulok
9
+ Project-URL: Issues, https://github.com/adnanbinpulok/pgconnect/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.6
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+
17
+ # PgConnect
18
+
19
+ PgConnect is a PostgreSQL connection and ORM library for Python. It provides an easy-to-use interface for connecting to PostgreSQL databases and performing common database operations.
20
+
21
+ ## Features
22
+
23
+ - Easy connection to PostgreSQL databases
24
+ - ORM-like interface for defining and interacting with database tables
25
+ - Support for various PostgreSQL data types
26
+ - Caching mechanism for improved performance
27
+
28
+ ## Installation
29
+
30
+ You can install PgConnect using pip:
31
+
32
+ ```bash
33
+ pip install git+https://github.com/AdnanBinPulok/PgConnect.git
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ### Connecting to the Database
39
+
40
+ ```python
41
+ import pgconnect
42
+ import asyncio
43
+
44
+ async def main():
45
+ connection = pgconnect.Connection(
46
+ host="your_host",
47
+ port=5432,
48
+ user="your_user",
49
+ password="your_password",
50
+ database="your_database"
51
+ )
52
+
53
+ # Define your table schema
54
+ users = pgconnect.Table(
55
+ name="users",
56
+ connection=connection,
57
+ columns=[
58
+ pgconnect.Column(
59
+ name="id",
60
+ type=pgconnect.DataType.SERIAL().primary_key().not_null()
61
+ ),
62
+ pgconnect.Column(
63
+ name="email",
64
+ type=pgconnect.DataType.VARCHAR().unique().not_null()
65
+ ),
66
+ pgconnect.Column(
67
+ name="username",
68
+ type=pgconnect.DataType.VARCHAR()
69
+ ),
70
+ pgconnect.Column(
71
+ name="password",
72
+ type=pgconnect.DataType.TEXT(),
73
+ ),
74
+ pgconnect.Column(
75
+ name="created_at",
76
+ type=pgconnect.DataType.TIMESTAMP().default("NOW()")
77
+ )
78
+ ],
79
+ cache=True,
80
+ cache_key="id",
81
+ )
82
+
83
+ await users.create()
84
+ print(users)
85
+
86
+ if __name__ == "__main__":
87
+ asyncio.run(main())
88
+ ```
89
+
90
+ ### Inserting Data
91
+
92
+ ```python
93
+ await users.insert(
94
+ email="example@gmail.com",
95
+ username="example",
96
+ password="password"
97
+ )
98
+ ```
99
+
100
+ Here, this is inserting a new row into the `users` table with the `email` as `example@gmail.com`, `username` as `example`, and `password` as `password`.
101
+
102
+ ### Selecting Data
103
+
104
+ ```python
105
+ user = await users.select("id", "username", email="example@gmail.com")
106
+ print(user)
107
+ ```
108
+
109
+ Here, this is selecting the `id` and `username` columns for the row where the `email` is `example@gmail.com`.
110
+
111
+ ### Updating Data
112
+
113
+ ```python
114
+ await users.update({"id": 1}, username="new_username")
115
+ ```
116
+
117
+ Here, this is updating the `username` column to `new_username` for the row where the `id` is `1`.
118
+
119
+ ### Deleting Data
120
+
121
+ ```python
122
+ await users.delete(id=1)
123
+ ```
124
+
125
+ Here, this is deleting the row from the `users` table where the `id` is `1`.
126
+
127
+ ### Counting Rows
128
+
129
+ ```python
130
+ user_count = await users.count()
131
+ print(user_count)
132
+ ```
133
+
134
+ Here, this is counting the total number of rows in the `users` table.
135
+
136
+ ### Checking Existence
137
+
138
+ ```python
139
+ user_exists = await users.exists(id=1)
140
+ print(user_exists)
141
+ ```
142
+
143
+ Here, this is checking if there is any row in the `users` table where the `id` is `1`.
144
+
145
+ ### Getting Columns
146
+
147
+ ```python
148
+ columns = await users.get_columns()
149
+ print(columns)
150
+ ```
151
+
152
+ Here, this is retrieving the names and data types of all columns in the `users` table.
153
+
154
+ ### Dropping the Table
155
+
156
+ ```python
157
+ await users.drop()
158
+ ```
159
+
160
+ Here, this is dropping the `users` table from the PostgreSQL database.
161
+
162
+ ### Truncating the Table
163
+
164
+ ```python
165
+ await users.truncate()
166
+ ```
167
+
168
+ Here, this is truncating the `users` table, which removes all rows from the table.
169
+
170
+ ### Example Usage in a Script
171
+
172
+ Here is a complete example script demonstrating how to use these methods:
173
+
174
+ ```python
175
+ import pgconnect
176
+ import asyncio
177
+
178
+ async def main():
179
+ connection = pgconnect.Connection(
180
+ host="your_host",
181
+ port=5432,
182
+ user="your_user",
183
+ password="your_password",
184
+ database="your_database"
185
+ )
186
+
187
+ users = pgconnect.Table(
188
+ name="users",
189
+ connection=connection,
190
+ columns=[
191
+ pgconnect.Column(
192
+ name="id",
193
+ type=pgconnect.DataType.SERIAL().primary_key().not_null()
194
+ ),
195
+ pgconnect.Column(
196
+ name="email",
197
+ type=pgconnect.DataType.VARCHAR().unique().not_null()
198
+ ),
199
+ pgconnect.Column(
200
+ name="username",
201
+ type=pgconnect.DataType.VARCHAR()
202
+ ),
203
+ pgconnect.Column(
204
+ name="password",
205
+ type=pgconnect.DataType.TEXT(),
206
+ ),
207
+ pgconnect.Column(
208
+ name="created_at",
209
+ type=pgconnect.DataType.TIMESTAMP().default("NOW()")
210
+ )
211
+ ],
212
+ cache=True,
213
+ cache_key="id",
214
+ )
215
+
216
+ await users.create()
217
+ print("Table created")
218
+
219
+ # Insert data
220
+ await users.insert(
221
+ email="example@gmail.com",
222
+ username="example",
223
+ password="password"
224
+ )
225
+ print("Data inserted")
226
+
227
+ # Select data
228
+ user = await users.select("id", "username", email="example@gmail.com")
229
+ print("Selected user:", user)
230
+
231
+ # Update data
232
+ await users.update({"id": 1}, username="new_username")
233
+ print("Data updated")
234
+
235
+ # Delete data
236
+ await users.delete(id=1)
237
+ print("Data deleted")
238
+
239
+ # Count rows
240
+ user_count = await users.count()
241
+ print("User count:", user_count)
242
+
243
+ # Check existence
244
+ user_exists = await users.exists(id=1)
245
+ print("User exists:", user_exists)
246
+
247
+ # Get columns
248
+ columns = await users.get_columns()
249
+ print("Table columns:", columns)
250
+
251
+ # Drop table
252
+ await users.drop()
253
+ print("Table dropped")
254
+
255
+ # Truncate table
256
+ await users.truncate()
257
+ print("Table truncated")
258
+
259
+ if __name__ == "__main__":
260
+ asyncio.run(main())
261
+ ```
262
+
263
+ This script demonstrates how to use the `Table` class to perform various database operations, including creating a table, inserting, updating, deleting, selecting data, counting rows, checking existence, getting columns, dropping the table, and truncating the table.
264
+
265
+ ## License
266
+
267
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
268
+
269
+ ## Author
270
+
271
+ AdnanBinPulok - [GitHub](https://github.com/AdnanBinPulok)
@@ -0,0 +1,255 @@
1
+ # PgConnect
2
+
3
+ PgConnect is a PostgreSQL connection and ORM library for Python. It provides an easy-to-use interface for connecting to PostgreSQL databases and performing common database operations.
4
+
5
+ ## Features
6
+
7
+ - Easy connection to PostgreSQL databases
8
+ - ORM-like interface for defining and interacting with database tables
9
+ - Support for various PostgreSQL data types
10
+ - Caching mechanism for improved performance
11
+
12
+ ## Installation
13
+
14
+ You can install PgConnect using pip:
15
+
16
+ ```bash
17
+ pip install git+https://github.com/AdnanBinPulok/PgConnect.git
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ### Connecting to the Database
23
+
24
+ ```python
25
+ import pgconnect
26
+ import asyncio
27
+
28
+ async def main():
29
+ connection = pgconnect.Connection(
30
+ host="your_host",
31
+ port=5432,
32
+ user="your_user",
33
+ password="your_password",
34
+ database="your_database"
35
+ )
36
+
37
+ # Define your table schema
38
+ users = pgconnect.Table(
39
+ name="users",
40
+ connection=connection,
41
+ columns=[
42
+ pgconnect.Column(
43
+ name="id",
44
+ type=pgconnect.DataType.SERIAL().primary_key().not_null()
45
+ ),
46
+ pgconnect.Column(
47
+ name="email",
48
+ type=pgconnect.DataType.VARCHAR().unique().not_null()
49
+ ),
50
+ pgconnect.Column(
51
+ name="username",
52
+ type=pgconnect.DataType.VARCHAR()
53
+ ),
54
+ pgconnect.Column(
55
+ name="password",
56
+ type=pgconnect.DataType.TEXT(),
57
+ ),
58
+ pgconnect.Column(
59
+ name="created_at",
60
+ type=pgconnect.DataType.TIMESTAMP().default("NOW()")
61
+ )
62
+ ],
63
+ cache=True,
64
+ cache_key="id",
65
+ )
66
+
67
+ await users.create()
68
+ print(users)
69
+
70
+ if __name__ == "__main__":
71
+ asyncio.run(main())
72
+ ```
73
+
74
+ ### Inserting Data
75
+
76
+ ```python
77
+ await users.insert(
78
+ email="example@gmail.com",
79
+ username="example",
80
+ password="password"
81
+ )
82
+ ```
83
+
84
+ Here, this is inserting a new row into the `users` table with the `email` as `example@gmail.com`, `username` as `example`, and `password` as `password`.
85
+
86
+ ### Selecting Data
87
+
88
+ ```python
89
+ user = await users.select("id", "username", email="example@gmail.com")
90
+ print(user)
91
+ ```
92
+
93
+ Here, this is selecting the `id` and `username` columns for the row where the `email` is `example@gmail.com`.
94
+
95
+ ### Updating Data
96
+
97
+ ```python
98
+ await users.update({"id": 1}, username="new_username")
99
+ ```
100
+
101
+ Here, this is updating the `username` column to `new_username` for the row where the `id` is `1`.
102
+
103
+ ### Deleting Data
104
+
105
+ ```python
106
+ await users.delete(id=1)
107
+ ```
108
+
109
+ Here, this is deleting the row from the `users` table where the `id` is `1`.
110
+
111
+ ### Counting Rows
112
+
113
+ ```python
114
+ user_count = await users.count()
115
+ print(user_count)
116
+ ```
117
+
118
+ Here, this is counting the total number of rows in the `users` table.
119
+
120
+ ### Checking Existence
121
+
122
+ ```python
123
+ user_exists = await users.exists(id=1)
124
+ print(user_exists)
125
+ ```
126
+
127
+ Here, this is checking if there is any row in the `users` table where the `id` is `1`.
128
+
129
+ ### Getting Columns
130
+
131
+ ```python
132
+ columns = await users.get_columns()
133
+ print(columns)
134
+ ```
135
+
136
+ Here, this is retrieving the names and data types of all columns in the `users` table.
137
+
138
+ ### Dropping the Table
139
+
140
+ ```python
141
+ await users.drop()
142
+ ```
143
+
144
+ Here, this is dropping the `users` table from the PostgreSQL database.
145
+
146
+ ### Truncating the Table
147
+
148
+ ```python
149
+ await users.truncate()
150
+ ```
151
+
152
+ Here, this is truncating the `users` table, which removes all rows from the table.
153
+
154
+ ### Example Usage in a Script
155
+
156
+ Here is a complete example script demonstrating how to use these methods:
157
+
158
+ ```python
159
+ import pgconnect
160
+ import asyncio
161
+
162
+ async def main():
163
+ connection = pgconnect.Connection(
164
+ host="your_host",
165
+ port=5432,
166
+ user="your_user",
167
+ password="your_password",
168
+ database="your_database"
169
+ )
170
+
171
+ users = pgconnect.Table(
172
+ name="users",
173
+ connection=connection,
174
+ columns=[
175
+ pgconnect.Column(
176
+ name="id",
177
+ type=pgconnect.DataType.SERIAL().primary_key().not_null()
178
+ ),
179
+ pgconnect.Column(
180
+ name="email",
181
+ type=pgconnect.DataType.VARCHAR().unique().not_null()
182
+ ),
183
+ pgconnect.Column(
184
+ name="username",
185
+ type=pgconnect.DataType.VARCHAR()
186
+ ),
187
+ pgconnect.Column(
188
+ name="password",
189
+ type=pgconnect.DataType.TEXT(),
190
+ ),
191
+ pgconnect.Column(
192
+ name="created_at",
193
+ type=pgconnect.DataType.TIMESTAMP().default("NOW()")
194
+ )
195
+ ],
196
+ cache=True,
197
+ cache_key="id",
198
+ )
199
+
200
+ await users.create()
201
+ print("Table created")
202
+
203
+ # Insert data
204
+ await users.insert(
205
+ email="example@gmail.com",
206
+ username="example",
207
+ password="password"
208
+ )
209
+ print("Data inserted")
210
+
211
+ # Select data
212
+ user = await users.select("id", "username", email="example@gmail.com")
213
+ print("Selected user:", user)
214
+
215
+ # Update data
216
+ await users.update({"id": 1}, username="new_username")
217
+ print("Data updated")
218
+
219
+ # Delete data
220
+ await users.delete(id=1)
221
+ print("Data deleted")
222
+
223
+ # Count rows
224
+ user_count = await users.count()
225
+ print("User count:", user_count)
226
+
227
+ # Check existence
228
+ user_exists = await users.exists(id=1)
229
+ print("User exists:", user_exists)
230
+
231
+ # Get columns
232
+ columns = await users.get_columns()
233
+ print("Table columns:", columns)
234
+
235
+ # Drop table
236
+ await users.drop()
237
+ print("Table dropped")
238
+
239
+ # Truncate table
240
+ await users.truncate()
241
+ print("Table truncated")
242
+
243
+ if __name__ == "__main__":
244
+ asyncio.run(main())
245
+ ```
246
+
247
+ This script demonstrates how to use the `Table` class to perform various database operations, including creating a table, inserting, updating, deleting, selecting data, counting rows, checking existence, getting columns, dropping the table, and truncating the table.
248
+
249
+ ## License
250
+
251
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
252
+
253
+ ## Author
254
+
255
+ AdnanBinPulok - [GitHub](https://github.com/AdnanBinPulok)
@@ -0,0 +1,23 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+
6
+ [project]
7
+ name = "pgconnect"
8
+ version = "0.0.1"
9
+ authors = [
10
+ { name="Adnan Bin Pulok", email="adnanbinpulok@gmail.com" },
11
+ ]
12
+ description = "A PostgreSQL connection and ORM library"
13
+ readme = "README.md"
14
+ requires-python = ">=3.8"
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ ]
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/adnanbinpulok"
23
+ Issues = "https://github.com/adnanbinpulok/pgconnect/issues"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,23 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name='pgconnect',
5
+ version='0.0.1',
6
+ author='AdnanBinPulok',
7
+ author_email='adnanbinpulok@gmail.com',
8
+ description='A PostgreSQL connection and ORM library',
9
+ long_description=open('readme.md').read(),
10
+ long_description_content_type='text/markdown',
11
+ url='https://github.com/AdnanBinPulok/PgConnect',
12
+ packages=find_packages(where='src', include=['pgconnect', 'pgconnect.*']),
13
+ package_dir={'': 'src'},
14
+ classifiers=[
15
+ 'Programming Language :: Python :: 3',
16
+ 'License :: OSI Approved :: MIT License',
17
+ 'Operating System :: OS Independent',
18
+ ],
19
+ python_requires='>=3.6',
20
+ install_requires=[
21
+ 'asyncpg',
22
+ ],
23
+ )
@@ -0,0 +1,25 @@
1
+ import asyncpg
2
+ import pgconnect
3
+
4
+
5
+ class Column:
6
+ def __init__(
7
+ self,
8
+ name: str,
9
+ type: pgconnect.DataType
10
+ ) -> None:
11
+ """
12
+ Initializes the column with specified properties.
13
+
14
+ Notes:
15
+ - Length should only be set for VARCHAR and CHAR types.
16
+ - Default values will be applied if provided.
17
+ """
18
+ self.name = name
19
+ self.type = type
20
+
21
+ def __repr__(self) -> str:
22
+ return f"<Column {self.name}>"
23
+
24
+ def __str__(self) -> str:
25
+ return f"<Column {self.name}>"