@@ -66,7 +66,7 @@ pip install pymongosql
6666Or install from source:
6767
6868``` bash
69- git clone https://github.com/your-username /PyMongoSQL.git
69+ git clone https://github.com/passren /PyMongoSQL.git
7070cd PyMongoSQL
7171pip install -e .
7272```
@@ -90,6 +90,7 @@ pip install -e .
9090 - [ UPDATE Statements] ( #update-statements )
9191 - [ DELETE Statements] ( #delete-statements )
9292 - [ Transaction Support] ( #transaction-support )
93+ - [ SQL to MongoDB Mapping] ( #sql-to-mongodb-mapping )
9394- [ Apache Superset Integration] ( #apache-superset-integration )
9495- [ Limitations & Roadmap] ( #limitations--roadmap )
9596- [ Contributing] ( #contributing )
@@ -534,6 +535,76 @@ finally:
534535
535536** Note:** MongoDB requires a replica set or sharded cluster for transaction support. Standalone MongoDB servers do not support ACID transactions at the server level.
536537
538+ ## SQL to MongoDB Mapping
539+
540+ The table below shows how PyMongoSQL translates SQL operations into MongoDB commands.
541+
542+ ### SQL Operations to MongoDB Commands
543+
544+ | SQL Operation | MongoDB Command | Equivalent PyMongo Method |
545+ | ---| ---| ---|
546+ | ` SELECT ... FROM col ` | ` {find: col, projection: {...}} ` | ` db.command("find", ...) ` |
547+ | ` SELECT ... FROM col WHERE ... ` | ` {find: col, filter: {...}} ` | ` db.command("find", ...) ` |
548+ | ` SELECT ... ORDER BY col ASC/DESC ` | ` {find: ..., sort: {col: 1/-1}} ` | ` db.command("find", ...) ` |
549+ | ` SELECT ... LIMIT n ` | ` {find: ..., limit: n} ` | ` db.command("find", ...) ` |
550+ | ` SELECT ... OFFSET n ` | ` {find: ..., skip: n} ` | ` db.command("find", ...) ` |
551+ | ` SELECT * FROM col.aggregate(...) ` | ` collection.aggregate(pipeline) ` | ` collection.aggregate() ` |
552+ | ` INSERT INTO col ... ` | ` {insert: col, documents: [...]} ` | ` db.command("insert", ...) ` |
553+ | ` UPDATE col SET ... WHERE ... ` | ` {update: col, updates: [{q: filter, u: {$set: {...}}, multi: true}]} ` | ` db.command("update", ...) ` |
554+ | ` DELETE FROM col WHERE ... ` | ` {delete: col, deletes: [{q: filter, limit: 0}]} ` | ` db.command("delete", ...) ` |
555+
556+ ### SQL Clauses to MongoDB Query Components
557+
558+ | SQL Clause | MongoDB Equivalent | Example |
559+ | ---| ---| ---|
560+ | ` SELECT col1, col2 ` | ` projection: {col1: 1, col2: 1} ` | Fields to include |
561+ | ` SELECT * ` | _ (no projection)_ | Returns all fields |
562+ | ` SELECT col AS alias ` | Column alias applied in result set | Post-processing rename |
563+ | ` FROM collection ` | ` find: "collection" ` | Target collection |
564+ | ` ORDER BY col ASC ` | ` sort: {col: 1} ` | Ascending sort |
565+ | ` ORDER BY col DESC ` | ` sort: {col: -1} ` | Descending sort |
566+ | ` LIMIT n ` | ` limit: n ` | Restrict result count |
567+ | ` OFFSET n ` | ` skip: n ` | Skip first n results |
568+
569+ ### WHERE Operators to MongoDB Filter Operators
570+
571+ | SQL WHERE Clause | MongoDB Filter | Notes |
572+ | ---| ---| ---|
573+ | ` field = value ` | ` {field: value} ` | Equality shorthand |
574+ | ` field != value ` | ` {field: {$ne: value}} ` | Not equal |
575+ | ` field > value ` | ` {field: {$gt: value}} ` | Greater than |
576+ | ` field >= value ` | ` {field: {$gte: value}} ` | Greater than or equal |
577+ | ` field < value ` | ` {field: {$lt: value}} ` | Less than |
578+ | ` field <= value ` | ` {field: {$lte: value}} ` | Less than or equal |
579+ | ` field LIKE 'pat%' ` | ` {field: {$regex: "pat.*"}} ` | ` % ` → ` .* ` , ` _ ` → ` . ` |
580+ | ` field IN (a, b, c) ` | ` {field: {$in: [a, b, c]}} ` | Match any value in list |
581+ | ` field NOT IN (a, b) ` | ` {field: {$nin: [a, b]}} ` | Exclude values in list |
582+ | ` field BETWEEN a AND b ` | ` {$and: [{field: {$gte: a}}, {field: {$lte: b}}]} ` | Range filter |
583+ | ` field IS NULL ` | ` {field: {$eq: null}} ` | Null check |
584+ | ` field IS NOT NULL ` | ` {field: {$ne: null}} ` | Not null check |
585+ | ` cond1 AND cond2 ` | ` {$and: [filter1, filter2]} ` | Logical AND |
586+ | ` cond1 OR cond2 ` | ` {$or: [filter1, filter2]} ` | Logical OR |
587+ | ` NOT cond ` | ` {$not: filter} ` | Logical NOT |
588+
589+ ### Nested Field and Array Access
590+
591+ | SQL Syntax | MongoDB Dot Notation | Example |
592+ | ---| ---| ---|
593+ | ` profile.name ` | ` profile.name ` | Single-level nesting |
594+ | ` account.profile.name ` | ` account.profile.name ` | Multi-level nesting |
595+ | ` items[0].name ` | ` items.0.name ` | Array index access |
596+
597+ ### DML Mapping Details
598+
599+ | SQL DML | MongoDB Behavior | Notes |
600+ | ---| ---| ---|
601+ | ` INSERT INTO col VALUE {...} ` | Single document insert | PartiQL object literal |
602+ | ` INSERT INTO col VALUE << {...}, {...} >> ` | Multi-document insert | PartiQL bag syntax |
603+ | ` INSERT INTO col (c1, c2) VALUES (v1, v2) ` | Columns and values zipped into document | Standard SQL syntax |
604+ | ` UPDATE col SET f1 = v1 ` | ` {$set: {f1: v1}} ` with ` multi: true ` | Updates all matching docs |
605+ | ` DELETE FROM col ` | ` {q: {}, limit: 0} ` | Deletes all documents |
606+ | ` DELETE FROM col WHERE ... ` | ` {q: filter, limit: 0} ` | Deletes all matching docs |
607+
537608## Apache Superset Integration
538609
539610PyMongoSQL can be used as a database driver in Apache Superset for querying and visualizing MongoDB data:
0 commit comments