Skip to content

Commit 333b5cc

Browse files
author
Peng Ren
committed
Update readme
1 parent 468df54 commit 333b5cc

File tree

2 files changed

+44
-32
lines changed

2 files changed

+44
-32
lines changed

README.md

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -109,32 +109,42 @@ with connect(host="mongodb://localhost:27017/database") as conn:
109109
with conn.cursor() as cursor:
110110
cursor.execute('SELECT COUNT(*) as total FROM users')
111111
result = cursor.fetchone()
112-
print(f"Total users: {result['total']}")
112+
print(f"Total users: {result[0]}")
113113
```
114114

115-
### Query with Parameters
115+
### Using DictCursor for Dictionary Results
116116

117117
```python
118118
from pymongosql import connect
119+
from pymongosql.cursor import DictCursor
120+
121+
with connect(host="mongodb://localhost:27017/database") as conn:
122+
with conn.cursor(DictCursor) as cursor:
123+
cursor.execute('SELECT COUNT(*) as total FROM users')
124+
result = cursor.fetchone()
125+
print(f"Total users: {result['total']}")
126+
```
127+
128+
### Cursor vs DictCursor
119129

120-
connection = connect(host="mongodb://localhost:27017/database")
130+
PyMongoSQL provides two cursor types for different result formats:
131+
132+
**Cursor** (default) - Returns results as tuples:
133+
```python
121134
cursor = connection.cursor()
135+
cursor.execute('SELECT name, email FROM users')
136+
row = cursor.fetchone()
137+
print(row[0]) # Access by index
138+
```
139+
140+
**DictCursor** - Returns results as dict:
141+
```python
142+
from pymongosql.cursor import DictCursor
122143

123-
# Parameterized queries for security
124-
min_age = 18
125-
status = 'active'
126-
127-
cursor.execute('''
128-
SELECT name, email, created_at
129-
FROM users
130-
WHERE age >= ? AND status = ?
131-
''', [min_age, status])
132-
133-
users = cursor.fetchmany(5) # Fetch first 5 results
134-
while users:
135-
for user in users:
136-
print(f"User: {user['name']} ({user['email']})")
137-
users = cursor.fetchmany(5) # Fetch next 5
144+
cursor = connection.cursor(DictCursor)
145+
cursor.execute('SELECT name, email FROM users')
146+
row = cursor.fetchone()
147+
print(row['name']) # Access by column name
138148
```
139149

140150
## Supported SQL Features
@@ -166,19 +176,6 @@ while users:
166176
- LIMIT: `LIMIT 10`
167177
- Combined: `ORDER BY created_at DESC LIMIT 5`
168178

169-
## Limitations & Roadmap
170-
171-
**Note**: Currently PyMongoSQL focuses on Data Query Language (DQL) operations. The following SQL features are **not yet supported** but are planned for future releases:
172-
173-
- **DML Operations** (Data Manipulation Language)
174-
- `INSERT`, `UPDATE`, `DELETE`
175-
- **DDL Operations** (Data Definition Language)
176-
- `CREATE TABLE/COLLECTION`, `DROP TABLE/COLLECTION`
177-
- `CREATE INDEX`, `DROP INDEX`
178-
- `LIST TABLES/COLLECTIONS`
179-
180-
These features are on our development roadmap and contributions are welcome!
181-
182179
## Apache Superset Integration
183180

184181
PyMongoSQL can be used as a database driver in Apache Superset for querying and visualizing MongoDB data:
@@ -200,6 +197,21 @@ PyMongoSQL can be used as a database driver in Apache Superset for querying and
200197

201198
This allows seamless integration between MongoDB data and Superset's BI capabilities without requiring data migration to traditional SQL databases.
202199

200+
<h2 style="color: red;">Limitations & Roadmap</h2>
201+
202+
**Note**: Currently PyMongoSQL focuses on Data Query Language (DQL) operations. The following SQL features are **not yet supported** but are planned for future releases:
203+
204+
- **Parameterized Queries**
205+
- Parameter substitution support (?, :pram, etc.)
206+
- **DML Operations** (Data Manipulation Language)
207+
- `INSERT`, `UPDATE`, `DELETE`
208+
- **DDL Operations** (Data Definition Language)
209+
- `CREATE TABLE/COLLECTION`, `DROP TABLE/COLLECTION`
210+
- `CREATE INDEX`, `DROP INDEX`
211+
- `LIST TABLES/COLLECTIONS`
212+
213+
These features are on our development roadmap and contributions are welcome!
214+
203215
## Contributing
204216

205217
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.

pymongosql/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
if TYPE_CHECKING:
77
from .connection import Connection
88

9-
__version__: str = "0.2.4"
9+
__version__: str = "0.2.5"
1010

1111
# Globals https://www.python.org/dev/peps/pep-0249/#globals
1212
apilevel: str = "2.0"

0 commit comments

Comments
 (0)