Skip to content

Commit ceb6445

Browse files
author
Peng Ren
committed
Clean up the folders
1 parent e899df3 commit ceb6445

File tree

3 files changed

+12
-596
lines changed

3 files changed

+12
-596
lines changed

README.md

Lines changed: 12 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,28 @@
99
[![MongoDB](https://img.shields.io/badge/MongoDB-7.0+-green.svg)](https://www.mongodb.com/)
1010
[![SQLAlchemy](https://img.shields.io/badge/SQLAlchemy-1.4+_2.0+-darkgreen.svg)](https://www.sqlalchemy.org/)
1111

12-
PyMongoSQL is a Python [DB API 2.0 (PEP 249)](https://www.python.org/dev/peps/pep-0249/) client for [MongoDB](https://www.mongodb.com/). It provides a familiar SQL interface to MongoDB, allowing developers to use SQL queries to interact with MongoDB collections.
12+
PyMongoSQL is a Python [DB API 2.0 (PEP 249)](https://www.python.org/dev/peps/pep-0249/) client for [MongoDB](https://www.mongodb.com/). It provides a familiar SQL interface to MongoDB, allowing developers to use SQL to interact with MongoDB collections.
1313

1414
## Objectives
1515

1616
PyMongoSQL implements the DB API 2.0 interfaces to provide SQL-like access to MongoDB. The project aims to:
1717

18-
- Bridge the gap between SQL and NoSQL by providing SQL query capabilities for MongoDB
18+
- Bridge the gap between SQL and NoSQL by providing SQL capabilities for MongoDB
1919
- Support standard SQL DQL (Data Query Language) operations including SELECT statements with WHERE, ORDER BY, and LIMIT clauses
2020
- Provide seamless integration with existing Python applications that expect DB API 2.0 compliance
2121
- Enable easy migration from traditional SQL databases to MongoDB
22-
- Support field aliasing and projection mapping for flexible result set handling
23-
- Maintain high performance through direct `db.command()` execution instead of high-level APIs
2422

2523
## Features
2624

2725
- **DB API 2.0 Compliant**: Full compatibility with Python Database API 2.0 specification
26+
- **SQLAlchemy Integration**: Complete ORM and Core support with dedicated MongoDB dialect
2827
- **SQL Query Support**: SELECT statements with WHERE conditions, field selection, and aliases
29-
- **MongoDB Native Integration**: Direct `db.command()` execution for optimal performance
3028
- **Connection String Support**: MongoDB URI format for easy configuration
31-
- **Result Set Handling**: Support for `fetchone()`, `fetchmany()`, and `fetchall()` operations
32-
- **Field Aliasing**: SQL-style field aliases with automatic projection mapping
33-
- **Context Manager Support**: Automatic resource management with `with` statements
34-
- **Transaction Ready**: Architecture designed for future DML operation support (INSERT, UPDATE, DELETE)
3529

3630
## Requirements
3731

3832
- **Python**: 3.9, 3.10, 3.11, 3.12, 3.13+
39-
- **MongoDB**: 4.0+
33+
- **MongoDB**: 7.0+
4034

4135
## Dependencies
4236

@@ -46,6 +40,11 @@ PyMongoSQL implements the DB API 2.0 interfaces to provide SQL-like access to Mo
4640
- **ANTLR4** (SQL Parser Runtime)
4741
- antlr4-python3-runtime >= 4.13.0
4842

43+
### Optional Dependencies
44+
45+
- **SQLAlchemy** (for ORM/Core support)
46+
- sqlalchemy >= 1.4.0 (SQLAlchemy 1.4+ and 2.0+ supported)
47+
4948
## Installation
5049

5150
```bash
@@ -70,7 +69,7 @@ from pymongosql import connect
7069
# Connect to MongoDB
7170
connection = connect(
7271
host="mongodb://localhost:27017",
73-
database="test_db"
72+
database="database"
7473
)
7574

7675
cursor = connection.cursor()
@@ -100,44 +99,19 @@ for row in cursor:
10099
```python
101100
from pymongosql import connect
102101

103-
with connect(host="mongodb://localhost:27017", database="mydb") as conn:
102+
with connect(host="mongodb://localhost:27017/database") as conn:
104103
with conn.cursor() as cursor:
105104
cursor.execute('SELECT COUNT(*) as total FROM users')
106105
result = cursor.fetchone()
107106
print(f"Total users: {result['total']}")
108107
```
109108

110-
### Field Aliases and Projections
111-
112-
```python
113-
from pymongosql import connect
114-
115-
connection = connect(host="mongodb://localhost:27017", database="ecommerce")
116-
cursor = connection.cursor()
117-
118-
# Use field aliases for cleaner result sets
119-
cursor.execute('''
120-
SELECT
121-
name AS product_name,
122-
price AS cost,
123-
category AS product_type
124-
FROM products
125-
WHERE in_stock = true
126-
ORDER BY price DESC
127-
LIMIT 10
128-
''')
129-
130-
products = cursor.fetchall()
131-
for product in products:
132-
print(f"{product['product_name']}: ${product['cost']}")
133-
```
134-
135109
### Query with Parameters
136110

137111
```python
138112
from pymongosql import connect
139113

140-
connection = connect(host="mongodb://localhost:27017", database="blog")
114+
connection = connect(host="mongodb://localhost:27017/database")
141115
cursor = connection.cursor()
142116

143117
# Parameterized queries for security
@@ -162,7 +136,6 @@ while users:
162136
### SELECT Statements
163137
- Field selection: `SELECT name, age FROM users`
164138
- Wildcards: `SELECT * FROM products`
165-
- Field aliases: `SELECT name AS user_name, age AS user_age FROM users`
166139

167140
### WHERE Clauses
168141
- Equality: `WHERE name = 'John'`
@@ -174,15 +147,6 @@ while users:
174147
- LIMIT: `LIMIT 10`
175148
- Combined: `ORDER BY created_at DESC LIMIT 5`
176149

177-
## Architecture
178-
179-
PyMongoSQL uses a multi-layer architecture:
180-
181-
1. **SQL Parser**: Built with ANTLR4 for robust SQL parsing
182-
2. **Query Planner**: Converts SQL AST to MongoDB query plans
183-
3. **Command Executor**: Direct `db.command()` execution for performance
184-
4. **Result Processor**: Handles projection mapping and result set iteration
185-
186150
## Connection Options
187151

188152
```python
@@ -204,31 +168,6 @@ print(conn.database_name) # Database name
204168
print(conn.is_connected) # Connection status
205169
```
206170

207-
## Error Handling
208-
209-
```python
210-
from pymongosql import connect
211-
from pymongosql.error import ProgrammingError, SqlSyntaxError
212-
213-
try:
214-
connection = connect(host="mongodb://localhost:27017", database="test")
215-
cursor = connection.cursor()
216-
cursor.execute("INVALID SQL SYNTAX")
217-
except SqlSyntaxError as e:
218-
print(f"SQL syntax error: {e}")
219-
except ProgrammingError as e:
220-
print(f"Programming error: {e}")
221-
```
222-
223-
## Development Status
224-
225-
PyMongoSQL is currently focused on DQL (Data Query Language) operations. Future releases will include:
226-
227-
- **DML Operations**: INSERT, UPDATE, DELETE statements
228-
- **Advanced SQL Features**: JOINs, subqueries, aggregations
229-
- **Schema Operations**: CREATE/DROP collection commands
230-
- **Transaction Support**: Multi-document ACID transactions
231-
232171
## Contributing
233172

234173
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

0 commit comments

Comments
 (0)