Skip to content

Commit 5e9f5b2

Browse files
author
Peng Ren
committed
Update README to reflect new changes
1 parent 95dabb2 commit 5e9f5b2

File tree

1 file changed

+91
-5
lines changed

1 file changed

+91
-5
lines changed

README.md

Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ PyMongoSQL implements the DB API 2.0 interfaces to provide SQL-like access to Mo
2828
- **Nested Structure Support**: Query and filter deeply nested fields and arrays within MongoDB documents using standard SQL syntax
2929
- **SQLAlchemy Integration**: Complete ORM and Core support with dedicated MongoDB dialect
3030
- **SQL Query Support**: SELECT statements with WHERE conditions, field selection, and aliases
31-
- **DML Support (INSERT)**: Insert single or multiple documents using PartiQL object and bag syntax
31+
- **DML Support**: Full support for INSERT, UPDATE, and DELETE operations using PartiQL syntax
3232
- **Connection String Support**: MongoDB URI format for easy configuration
3333

3434
## Requirements
@@ -234,13 +234,97 @@ cursor.execute(
234234
```python
235235
# Positional parameters using ? placeholders
236236
cursor.execute(
237-
"INSERT INTO Music {'title': '?', 'artist': '?', 'year': '?'}",
237+
"INSERT INTO Music {'title': ?, 'artist': ?, 'year': ?}",
238238
["Song D", "Diana", 2020]
239239
)
240240
```
241241

242242
> Note: For INSERT, use positional parameters (`?`). Named placeholders (`:name`) are supported for SELECT queries; INSERT currently recommends `?` style.
243243
244+
### UPDATE Statements
245+
246+
PyMongoSQL supports updating documents in MongoDB collections using standard SQL UPDATE syntax.
247+
248+
- **Update All Documents**
249+
250+
```python
251+
cursor.execute("UPDATE Music SET available = false")
252+
```
253+
254+
- **Update Multiple Fields**
255+
256+
```python
257+
cursor.execute(
258+
"UPDATE Music SET price = 19.99, available = true WHERE artist = 'Alice'"
259+
)
260+
```
261+
262+
- **Update with Comparisons and Logical Operators**
263+
264+
```python
265+
cursor.execute(
266+
"UPDATE Music SET price = 9.99 WHERE year = 2020 AND stock > 5"
267+
)
268+
```
269+
270+
- **Parameterized UPDATE**
271+
272+
```python
273+
# Positional parameters using ? placeholders
274+
cursor.execute(
275+
"UPDATE Music SET price = ?, stock = ? WHERE artist = ?",
276+
[24.99, 50, "Bob"]
277+
)
278+
```
279+
280+
- **Update Nested Fields**
281+
282+
```python
283+
cursor.execute("UPDATE Music SET details.publisher = 'XYZ Records' WHERE title = 'Song A'")
284+
```
285+
286+
- **Check Updated Row Count**
287+
288+
```python
289+
cursor.execute("UPDATE Music SET available = false WHERE year = 2020")
290+
print(f"Updated {cursor.rowcount} documents")
291+
```
292+
293+
### DELETE Statements
294+
295+
PyMongoSQL supports deleting documents from MongoDB collections using standard SQL DELETE syntax.
296+
297+
- **Delete All Documents**
298+
299+
```python
300+
cursor.execute("DELETE FROM Music")
301+
```
302+
303+
- **Delete with Logical Operators**
304+
305+
```python
306+
cursor.execute(
307+
"DELETE FROM Music WHERE year = 2019 AND available = false"
308+
)
309+
```
310+
311+
- **Parameterized DELETE**
312+
313+
```python
314+
# Positional parameters using ? placeholders
315+
cursor.execute(
316+
"DELETE FROM Music WHERE artist = ? AND year < ?",
317+
["Charlie", 2021]
318+
)
319+
```
320+
321+
- **Check Deleted Row Count**
322+
323+
```python
324+
cursor.execute("DELETE FROM Music WHERE available = false")
325+
print(f"Deleted {cursor.rowcount} documents")
326+
```
327+
244328
## Apache Superset Integration
245329

246330
PyMongoSQL can be used as a database driver in Apache Superset for querying and visualizing MongoDB data:
@@ -264,14 +348,16 @@ This allows seamless integration between MongoDB data and Superset's BI capabili
264348

265349
<h2 style="color: red;">Limitations & Roadmap</h2>
266350

267-
**Note**: PyMongoSQL focuses on Data Query Language (DQL) operations and selective DML support. The following SQL features are **not yet supported** but are planned for future releases:
351+
**Note**: PyMongoSQL currently supports DQL (Data Query Language) and DML (Data Manipulation Language) operations. The following SQL features are **not yet supported** but are planned for future releases:
268352

269-
- **DML Operations** (Data Manipulation Language)
270-
- `UPDATE`, `DELETE`
271353
- **DDL Operations** (Data Definition Language)
272354
- `CREATE TABLE/COLLECTION`, `DROP TABLE/COLLECTION`
273355
- `CREATE INDEX`, `DROP INDEX`
274356
- `LIST TABLES/COLLECTIONS`
357+
- `ALTER TABLE/COLLECTION`
358+
- **Advanced DML Operations**
359+
- `MERGE`, `UPSERT`
360+
- Transactions and multi-document operations
275361

276362
These features are on our development roadmap and contributions are welcome!
277363

0 commit comments

Comments
 (0)