odbms 0.4.2__tar.gz → 0.4.4__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.
Files changed (41) hide show
  1. odbms-0.4.4/PKG-INFO +207 -0
  2. odbms-0.4.4/README.md +176 -0
  3. {odbms-0.4.2 → odbms-0.4.4}/odbms/cli.py +1 -1
  4. {odbms-0.4.2 → odbms-0.4.4}/odbms/dbms.py +22 -16
  5. {odbms-0.4.2 → odbms-0.4.4}/odbms/model.py +213 -92
  6. odbms-0.4.4/odbms/orms/mongodb.py +151 -0
  7. odbms-0.4.4/odbms/orms/mysqldb.py +201 -0
  8. odbms-0.4.4/odbms/orms/postgresqldb.py +215 -0
  9. odbms-0.4.4/odbms.egg-info/PKG-INFO +207 -0
  10. {odbms-0.4.2 → odbms-0.4.4}/odbms.egg-info/SOURCES.txt +5 -1
  11. {odbms-0.4.2 → odbms-0.4.4}/odbms.egg-info/requires.txt +3 -2
  12. {odbms-0.4.2 → odbms-0.4.4}/setup.py +2 -2
  13. {odbms-0.4.2 → odbms-0.4.4}/tests/test_models.py +60 -1
  14. odbms-0.4.4/tests/test_mongodb.py +218 -0
  15. odbms-0.4.4/tests/test_mysql.py +158 -0
  16. odbms-0.4.4/tests/test_mysqldb.py +146 -0
  17. odbms-0.4.4/tests/test_postgresql.py +140 -0
  18. odbms-0.4.2/PKG-INFO +0 -103
  19. odbms-0.4.2/README.md +0 -73
  20. odbms-0.4.2/odbms/orms/mongodb.py +0 -75
  21. odbms-0.4.2/odbms/orms/mysqldb.py +0 -253
  22. odbms-0.4.2/odbms/orms/postgresqldb.py +0 -121
  23. odbms-0.4.2/odbms.egg-info/PKG-INFO +0 -103
  24. {odbms-0.4.2 → odbms-0.4.4}/LICENSE +0 -0
  25. {odbms-0.4.2 → odbms-0.4.4}/MANIFEST.in +0 -0
  26. {odbms-0.4.2 → odbms-0.4.4}/odbms/__init__.py +0 -0
  27. {odbms-0.4.2 → odbms-0.4.4}/odbms/connection_pool.py +0 -0
  28. {odbms-0.4.2 → odbms-0.4.4}/odbms/database.py +0 -0
  29. {odbms-0.4.2 → odbms-0.4.4}/odbms/fields.py +0 -0
  30. {odbms-0.4.2 → odbms-0.4.4}/odbms/migrations.py +0 -0
  31. {odbms-0.4.2 → odbms-0.4.4}/odbms/orms/__init__.py +0 -0
  32. {odbms-0.4.2 → odbms-0.4.4}/odbms/orms/base.py +0 -0
  33. {odbms-0.4.2 → odbms-0.4.4}/odbms/orms/sqlitedb.py +0 -0
  34. {odbms-0.4.2 → odbms-0.4.4}/odbms/validators.py +0 -0
  35. {odbms-0.4.2 → odbms-0.4.4}/odbms.egg-info/dependency_links.txt +0 -0
  36. {odbms-0.4.2 → odbms-0.4.4}/odbms.egg-info/entry_points.txt +0 -0
  37. {odbms-0.4.2 → odbms-0.4.4}/odbms.egg-info/top_level.txt +0 -0
  38. {odbms-0.4.2 → odbms-0.4.4}/setup.cfg +0 -0
  39. {odbms-0.4.2 → odbms-0.4.4}/tests/test_connection_pool.py +0 -0
  40. {odbms-0.4.2 → odbms-0.4.4}/tests/test_database.py +0 -0
  41. {odbms-0.4.2 → odbms-0.4.4}/tests/test_fields.py +0 -0
odbms-0.4.4/PKG-INFO ADDED
@@ -0,0 +1,207 @@
1
+ Metadata-Version: 2.1
2
+ Name: odbms
3
+ Version: 0.4.4
4
+ Summary: Database client for Mysql, MongoDB and Sqlite
5
+ Author: Amos Amissah
6
+ Author-email: theonlyamos@gmail.com
7
+ Project-URL: Source, https://github.com/theonlyamos/odbms/
8
+ Project-URL: Tracker, https://github.com/theonlyamos/odbms/issues
9
+ Keywords: python3 runit developer serverless architecture docker sqlite mysql mongodb
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Topic :: Software Development :: Build Tools
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.6
16
+ Classifier: Programming Language :: Python :: 3.7
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: python-dotenv
25
+ Requires-Dist: motor
26
+ Requires-Dist: aiopg
27
+ Requires-Dist: aiomysql
28
+ Requires-Dist: inflect
29
+ Requires-Dist: pydantic
30
+ Requires-Dist: pyreadline3
31
+
32
+ # ODBMS - Object Document/Relational Mapping System
33
+
34
+ A flexible and modern Python ORM supporting multiple databases (MongoDB, PostgreSQL, MySQL) with both synchronous and asynchronous operations.
35
+
36
+ ## Features
37
+
38
+ - Support for multiple databases:
39
+ - SQLite (using sqlite3)
40
+ - MongoDB (using Motor)
41
+ - PostgreSQL (using aiopg)
42
+ - MySQL (using aiomysql)
43
+ - Both synchronous and asynchronous operations
44
+ - Connection pooling for better performance
45
+ - Type-safe field definitions
46
+ - Pydantic integration for validation
47
+ - Automatic table/collection creation
48
+ - Relationship handling
49
+ - Computed fields
50
+ - Flexible query interface
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ pip install -r requirements.txt
56
+ ```
57
+
58
+ ## Quick Start
59
+
60
+ ```python
61
+ from odbms import Model, StringField, IntegerField, EmailField
62
+ from odbms.dbms import DBMS
63
+
64
+ # Initialize database connection
65
+ DBMS.initialize(
66
+ dbms='postgresql', # or 'mongodb', 'mysql'
67
+ host='localhost',
68
+ port=5432,
69
+ database='mydb',
70
+ username='user',
71
+ password='pass'
72
+ )
73
+
74
+ # Define your model
75
+ class User(Model):
76
+ name: str = StringField()
77
+ email: str = EmailField()
78
+ age: int = IntegerField(min_value=0)
79
+
80
+ # Create a new user
81
+ user = User(name='John Doe', email='john@example.com', age=30)
82
+ await user.save_async() # or user.save() for sync operation
83
+
84
+ # Find users
85
+ users = await User.find_async({'age': {'$gte': 25}}) # or User.find() for sync
86
+ ```
87
+
88
+ ## Field Types
89
+
90
+ - `StringField`: For text data
91
+ - `IntegerField`: For integer values
92
+ - `FloatField`: For floating-point numbers
93
+ - `BooleanField`: For true/false values
94
+ - `DateTimeField`: For timestamps
95
+ - `EmailField`: For email addresses with validation
96
+ - `IDField`: For primary keys/IDs
97
+ - `ComputedField`: For dynamically computed values
98
+ - `ListField`: For arrays/lists
99
+ - `DictField`: For nested documents/objects
100
+
101
+ ## Database Operations
102
+
103
+ ### Synchronous Operations
104
+
105
+ ```python
106
+ # Create
107
+ user = User(name='John', email='john@example.com')
108
+ user.save()
109
+
110
+ # Read
111
+ user = User.find_one({'email': 'john@example.com'})
112
+ users = User.find({'age': {'$gte': 25}})
113
+ all_users = User.all()
114
+
115
+ # Update
116
+ User.update({'age': {'$lt': 18}}, {'is_minor': True})
117
+
118
+ # Delete
119
+ User.remove({'status': 'inactive'})
120
+
121
+ # Aggregation
122
+ total_age = User.sum('age', {'country': 'US'})
123
+ ```
124
+
125
+ ### Asynchronous Operations
126
+
127
+ ```python
128
+ # Create
129
+ user = User(name='Jane', email='jane@example.com')
130
+ await user.save_async()
131
+
132
+ # Read
133
+ user = await User.find_one_async({'email': 'jane@example.com'})
134
+ users = await User.find_async({'age': {'$gte': 25}})
135
+ all_users = await User.all_async()
136
+
137
+ # Update
138
+ await User.update_async({'age': {'$lt': 18}}, {'is_minor': True})
139
+
140
+ # Delete
141
+ await User.remove_async({'status': 'inactive'})
142
+
143
+ # Aggregation
144
+ total_age = await User.sum_async('age', {'country': 'US'})
145
+ ```
146
+
147
+ ## Relationships
148
+
149
+ ```python
150
+ class Post(Model):
151
+ title: str = StringField()
152
+ content: str = StringField()
153
+ author_id: str = IDField()
154
+
155
+ class User(Model):
156
+ name: str = StringField()
157
+ posts: List[Post] = ListField(model=Post)
158
+
159
+ # Create related records
160
+ user = User(name='John')
161
+ await user.save_async()
162
+
163
+ post = Post(title='Hello', content='World', author_id=user.id)
164
+ await post.save_async()
165
+
166
+ # Access relationships
167
+ user_posts = await user.posts # Automatically fetches related posts
168
+ ```
169
+
170
+ ## Testing
171
+
172
+ Run the test suite:
173
+
174
+ ```bash
175
+ pytest tests/
176
+ ```
177
+
178
+ The test suite includes comprehensive tests for:
179
+
180
+ - All database operations (CRUD)
181
+ - Both sync and async operations
182
+ - Field validations
183
+ - Relationships
184
+ - Computed fields
185
+ - Aggregations
186
+
187
+ ## Requirements
188
+
189
+ - Python 3.7+
190
+ - pydantic >= 2.0.0
191
+ - motor >= 3.3.0 (for MongoDB)
192
+ - aiopg >= 1.4.0 (for PostgreSQL)
193
+ - aiomysql >= 0.2.0 (for MySQL)
194
+ - inflect >= 5.0.0
195
+ - python-dotenv >= 0.19.0
196
+
197
+ ## Contributing
198
+
199
+ 1. Fork the repository
200
+ 2. Create a feature branch
201
+ 3. Commit your changes
202
+ 4. Push to the branch
203
+ 5. Create a Pull Request
204
+
205
+ ## License
206
+
207
+ MIT License
odbms-0.4.4/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # ODBMS - Object Document/Relational Mapping System
2
+
3
+ A flexible and modern Python ORM supporting multiple databases (MongoDB, PostgreSQL, MySQL) with both synchronous and asynchronous operations.
4
+
5
+ ## Features
6
+
7
+ - Support for multiple databases:
8
+ - SQLite (using sqlite3)
9
+ - MongoDB (using Motor)
10
+ - PostgreSQL (using aiopg)
11
+ - MySQL (using aiomysql)
12
+ - Both synchronous and asynchronous operations
13
+ - Connection pooling for better performance
14
+ - Type-safe field definitions
15
+ - Pydantic integration for validation
16
+ - Automatic table/collection creation
17
+ - Relationship handling
18
+ - Computed fields
19
+ - Flexible query interface
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ pip install -r requirements.txt
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ```python
30
+ from odbms import Model, StringField, IntegerField, EmailField
31
+ from odbms.dbms import DBMS
32
+
33
+ # Initialize database connection
34
+ DBMS.initialize(
35
+ dbms='postgresql', # or 'mongodb', 'mysql'
36
+ host='localhost',
37
+ port=5432,
38
+ database='mydb',
39
+ username='user',
40
+ password='pass'
41
+ )
42
+
43
+ # Define your model
44
+ class User(Model):
45
+ name: str = StringField()
46
+ email: str = EmailField()
47
+ age: int = IntegerField(min_value=0)
48
+
49
+ # Create a new user
50
+ user = User(name='John Doe', email='john@example.com', age=30)
51
+ await user.save_async() # or user.save() for sync operation
52
+
53
+ # Find users
54
+ users = await User.find_async({'age': {'$gte': 25}}) # or User.find() for sync
55
+ ```
56
+
57
+ ## Field Types
58
+
59
+ - `StringField`: For text data
60
+ - `IntegerField`: For integer values
61
+ - `FloatField`: For floating-point numbers
62
+ - `BooleanField`: For true/false values
63
+ - `DateTimeField`: For timestamps
64
+ - `EmailField`: For email addresses with validation
65
+ - `IDField`: For primary keys/IDs
66
+ - `ComputedField`: For dynamically computed values
67
+ - `ListField`: For arrays/lists
68
+ - `DictField`: For nested documents/objects
69
+
70
+ ## Database Operations
71
+
72
+ ### Synchronous Operations
73
+
74
+ ```python
75
+ # Create
76
+ user = User(name='John', email='john@example.com')
77
+ user.save()
78
+
79
+ # Read
80
+ user = User.find_one({'email': 'john@example.com'})
81
+ users = User.find({'age': {'$gte': 25}})
82
+ all_users = User.all()
83
+
84
+ # Update
85
+ User.update({'age': {'$lt': 18}}, {'is_minor': True})
86
+
87
+ # Delete
88
+ User.remove({'status': 'inactive'})
89
+
90
+ # Aggregation
91
+ total_age = User.sum('age', {'country': 'US'})
92
+ ```
93
+
94
+ ### Asynchronous Operations
95
+
96
+ ```python
97
+ # Create
98
+ user = User(name='Jane', email='jane@example.com')
99
+ await user.save_async()
100
+
101
+ # Read
102
+ user = await User.find_one_async({'email': 'jane@example.com'})
103
+ users = await User.find_async({'age': {'$gte': 25}})
104
+ all_users = await User.all_async()
105
+
106
+ # Update
107
+ await User.update_async({'age': {'$lt': 18}}, {'is_minor': True})
108
+
109
+ # Delete
110
+ await User.remove_async({'status': 'inactive'})
111
+
112
+ # Aggregation
113
+ total_age = await User.sum_async('age', {'country': 'US'})
114
+ ```
115
+
116
+ ## Relationships
117
+
118
+ ```python
119
+ class Post(Model):
120
+ title: str = StringField()
121
+ content: str = StringField()
122
+ author_id: str = IDField()
123
+
124
+ class User(Model):
125
+ name: str = StringField()
126
+ posts: List[Post] = ListField(model=Post)
127
+
128
+ # Create related records
129
+ user = User(name='John')
130
+ await user.save_async()
131
+
132
+ post = Post(title='Hello', content='World', author_id=user.id)
133
+ await post.save_async()
134
+
135
+ # Access relationships
136
+ user_posts = await user.posts # Automatically fetches related posts
137
+ ```
138
+
139
+ ## Testing
140
+
141
+ Run the test suite:
142
+
143
+ ```bash
144
+ pytest tests/
145
+ ```
146
+
147
+ The test suite includes comprehensive tests for:
148
+
149
+ - All database operations (CRUD)
150
+ - Both sync and async operations
151
+ - Field validations
152
+ - Relationships
153
+ - Computed fields
154
+ - Aggregations
155
+
156
+ ## Requirements
157
+
158
+ - Python 3.7+
159
+ - pydantic >= 2.0.0
160
+ - motor >= 3.3.0 (for MongoDB)
161
+ - aiopg >= 1.4.0 (for PostgreSQL)
162
+ - aiomysql >= 0.2.0 (for MySQL)
163
+ - inflect >= 5.0.0
164
+ - python-dotenv >= 0.19.0
165
+
166
+ ## Contributing
167
+
168
+ 1. Fork the repository
169
+ 2. Create a feature branch
170
+ 3. Commit your changes
171
+ 4. Push to the branch
172
+ 5. Create a Pull Request
173
+
174
+ ## License
175
+
176
+ MIT License
@@ -3,7 +3,7 @@ import argparse
3
3
 
4
4
  Database = None
5
5
 
6
- VERSION = "0.4.2"
6
+ VERSION = "0.4.4"
7
7
 
8
8
  def start(args):
9
9
  import code
@@ -1,20 +1,14 @@
1
- #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
- # @Date : 2022-08-06 17:37:00
4
- # @Author : Amos Amissah (theonlyamos@gmail.com)
5
- # @Link : link
6
- # @Version : 1.0.0
7
-
8
1
  from typing import Optional, Type, Union
9
2
  from .database import Database
10
3
  from .orms.mongodb import MongoDB
11
4
  from .orms.sqlitedb import SQLiteDB
12
5
  from .orms.postgresqldb import PostgresqlDB
6
+ from .orms.mysqldb import MysqlDB
13
7
 
14
8
  class DBMS:
15
9
  """Database Management System class."""
16
10
 
17
- Database: Optional[Union[MongoDB, SQLiteDB, PostgresqlDB]] = None
11
+ Database: Optional[Union[MongoDB, SQLiteDB, PostgresqlDB, MysqlDB]] = None
18
12
 
19
13
  @classmethod
20
14
  def initialize(cls, dbms: str, database: str, host: str = 'localhost', port: Optional[int] = None,
@@ -33,14 +27,26 @@ class DBMS:
33
27
  cls.Database.connect()
34
28
  cls.Database.dbms = 'sqlite'
35
29
  elif dbms == 'postgresql':
36
- cls.Database = PostgresqlDB(
37
- host=host,
38
- port=port or 5432,
39
- database=database,
40
- username=username,
41
- password=password
42
- )
43
- cls.Database.connect()
30
+ cls.Database = PostgresqlDB()
31
+ dbsettings = {
32
+ 'host': host,
33
+ 'port': port or 5432,
34
+ 'database': database,
35
+ 'user': username,
36
+ 'password': password
37
+ }
38
+ cls.Database.connect(dbsettings=dbsettings)
44
39
  cls.Database.dbms = 'postgresql'
40
+ elif dbms == 'mysql':
41
+ cls.Database = MysqlDB()
42
+ dbsettings = {
43
+ 'host': host,
44
+ 'port': port or 3306,
45
+ 'database': database,
46
+ 'user': username,
47
+ 'password': password
48
+ }
49
+ cls.Database.connect(dbsettings=dbsettings)
50
+ cls.Database.dbms = 'mysql'
45
51
  else:
46
52
  raise ValueError(f"Unsupported database type: {dbms}")