Skip to content

Commit 72a5b3d

Browse files
committed
Docs site built and working, with homepage and pricing, and everything
1 parent 3538393 commit 72a5b3d

38 files changed

+5616
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Compiled output
22
/dist
33
/build
4+
/site
45

56
# Dependencies
67
/node_modules

README.md

Lines changed: 188 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,105 @@ QueryLeaf is a library that translates SQL queries into MongoDB commands. It par
2626
- GROUP BY with aggregation functions (COUNT, SUM, AVG, MIN, MAX)
2727
- JOINs between collections
2828

29+
## SQL to MongoDB Translation Examples
30+
31+
QueryLeaf translates SQL queries into MongoDB commands. Here are some examples of the translation:
32+
33+
### Basic SELECT with WHERE
34+
35+
**SQL:**
36+
```sql
37+
SELECT name, email FROM users WHERE age > 21
38+
```
39+
40+
**MongoDB:**
41+
```js
42+
db.collection('users').find(
43+
{ age: { $gt: 21 } },
44+
{ name: 1, email: 1 }
45+
)
46+
```
47+
48+
### Nested Field Access
49+
50+
**SQL:**
51+
```sql
52+
SELECT name, address.city, address.zip FROM users WHERE address.city = 'New York'
53+
```
54+
55+
**MongoDB:**
56+
```js
57+
db.collection('users').find(
58+
{ 'address.city': 'New York' },
59+
{ name: 1, 'address.city': 1, 'address.zip': 1 }
60+
)
61+
```
62+
63+
### Array Element Access
64+
65+
**SQL:**
66+
```sql
67+
SELECT _id, items[0].name, items[0].price FROM orders WHERE items[0].price > 1000
68+
```
69+
70+
**MongoDB:**
71+
```js
72+
db.collection('orders').find(
73+
{ 'items.0.price': { $gt: 1000 } },
74+
{ _id: 1, 'items.0.name': 1, 'items.0.price': 1 }
75+
)
76+
```
77+
78+
### GROUP BY with Aggregation
79+
80+
**SQL:**
81+
```sql
82+
SELECT status, COUNT(*) as count, SUM(total) as total_amount FROM orders GROUP BY status
83+
```
84+
85+
**MongoDB:**
86+
```js
87+
db.collection('orders').aggregate([
88+
{
89+
$group: {
90+
_id: "$status",
91+
status: { $first: "$status" },
92+
count: { $sum: 1 },
93+
total_amount: { $sum: "$total" }
94+
}
95+
}
96+
])
97+
```
98+
99+
### JOIN Between Collections
100+
101+
**SQL:**
102+
```sql
103+
SELECT u.name, o._id as order_id, o.total FROM users u JOIN orders o ON u._id = o.userId
104+
```
105+
106+
**MongoDB:**
107+
```js
108+
db.collection('users').aggregate([
109+
{
110+
$lookup: {
111+
from: "orders",
112+
localField: "_id",
113+
foreignField: "userId",
114+
as: "orders"
115+
}
116+
},
117+
{ $unwind: { path: "$orders", preserveNullAndEmptyArrays: true } },
118+
{
119+
$project: {
120+
name: 1,
121+
order_id: "$orders._id",
122+
total: "$orders.total"
123+
}
124+
}
125+
])
126+
```
127+
29128
## Installation
30129

31130
```bash
@@ -93,7 +192,59 @@ npm run example
93192
ts-node src/examples/dummy-client-demo.ts
94193
```
95194

96-
This example demonstrates:
195+
## SQL Query Examples
196+
197+
Here are some practical SQL queries you can use with QueryLeaf:
198+
199+
### Working with Nested Fields
200+
201+
```sql
202+
-- Query users by nested address field
203+
SELECT name, email, address.city FROM users WHERE address.zip = '10001'
204+
205+
-- Insert with nested document structure
206+
INSERT INTO users (name, age, email, address) VALUES
207+
('Jane Smith', 28, 'jane@example.com', {
208+
"street": "456 Park Ave",
209+
"city": "Chicago",
210+
"state": "IL",
211+
"zip": "60601"
212+
})
213+
214+
-- Update a nested field
215+
UPDATE users SET address.city = 'San Francisco', address.state = 'CA' WHERE _id = '123'
216+
```
217+
218+
### Working with Array Fields
219+
220+
```sql
221+
-- Query by array element property
222+
SELECT userId, total FROM orders WHERE items[0].name = 'Laptop'
223+
224+
-- Filter by array element condition
225+
SELECT * FROM orders WHERE items[1].price < 50
226+
227+
-- Insert document with array field
228+
INSERT INTO orders (userId, items, status) VALUES
229+
('user123', [
230+
{ "id": "prod1", "name": "Monitor", "price": 300 },
231+
{ "id": "prod2", "name": "Keyboard", "price": 75 }
232+
], 'pending')
233+
```
234+
235+
### Advanced Queries
236+
237+
```sql
238+
-- Using GROUP BY with aggregation functions
239+
SELECT category, COUNT(*) as count, AVG(price) as avg_price FROM products GROUP BY category
240+
241+
-- JOIN between users and orders
242+
SELECT u.name, o.total, o.status FROM users u JOIN orders o ON u._id = o.userId WHERE o.total > 100
243+
```
244+
245+
Check out the [examples folder](src/examples/) for more complete examples, including how to set up the QueryLeaf instance and execute these queries.
246+
247+
This library demonstrates:
97248
- Basic SELECT queries
98249
- Filtering with WHERE clauses
99250
- Sorting with ORDER BY
@@ -105,7 +256,7 @@ This example demonstrates:
105256

106257
## Architecture
107258

108-
Squongo follows a modular architecture:
259+
QueryLeaf follows a modular architecture:
109260

110261
1. **SqlParser**: Converts SQL text into an abstract syntax tree (AST) using node-sql-parser
111262
2. **SqlCompiler**: Transforms the AST into MongoDB commands
@@ -122,9 +273,11 @@ The project includes both unit tests and integration tests:
122273
Run unit tests with:
123274

124275
```bash
125-
npm test
276+
npm run test:unit
126277
```
127278

279+
Unit tests are located in the `tests/unit` directory and focus on testing the parsing and compilation of SQL statements without requiring a database connection.
280+
128281
#### Integration Tests
129282

130283
Integration tests use [testcontainers](https://github.com/testcontainers/testcontainers-node) to spin up a MongoDB instance in Docker. Make sure you have Docker installed and running before executing these tests.
@@ -135,13 +288,21 @@ Run integration tests with:
135288
npm run test:integration
136289
```
137290

291+
Integration tests are located in the `tests/integration` directory and test the complete functionality with a real MongoDB database.
292+
138293
These tests will:
139294
1. Start a MongoDB container
140295
2. Load fixture data
141296
3. Run a series of SQL queries against the database
142297
4. Verify the results
143298
5. Clean up the container when done
144299

300+
To run all tests:
301+
302+
```bash
303+
npm run test:all
304+
```
305+
145306
### Continuous Integration
146307

147308
This project uses GitHub Actions for continuous integration. The CI workflow automatically runs on:
@@ -151,12 +312,33 @@ This project uses GitHub Actions for continuous integration. The CI workflow aut
151312
The CI workflow:
152313
1. Sets up Node.js (versions 16.x, 18.x, and 20.x)
153314
2. Installs dependencies
154-
3. Runs all tests (including integration tests with MongoDB in a Docker container)
155-
4. Performs type checking
156-
5. Builds the package
315+
3. Runs unit tests
316+
4. Runs integration tests with MongoDB in a Docker container
317+
5. Performs type checking
318+
6. Builds the package
157319

158320
You can see the workflow configuration in `.github/workflows/test.yml`.
159321

322+
## Documentation
323+
324+
Comprehensive documentation is available at [queryleaf.com/docs](https://queryleaf.com/docs), including:
325+
326+
- Detailed installation and setup guides
327+
- In-depth explanation of supported SQL syntax
328+
- Usage examples and best practices
329+
- Troubleshooting and debugging guides
330+
- Performance optimization tips
331+
332+
For local development, you can run the documentation site with:
333+
334+
```bash
335+
# Install required packages
336+
pip install -r requirements.txt
337+
338+
# Serve the documentation locally
339+
npm run docs:serve
340+
```
341+
160342
## License
161343

162344
QueryLeaf is dual-licensed:

docs/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# QueryLeaf Documentation
2+
3+
This directory contains the source files for the QueryLeaf documentation site. The documentation is built using [MkDocs](https://www.mkdocs.org/) with the [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) theme.
4+
5+
## Viewing the Documentation
6+
7+
You can view the documentation in several ways:
8+
9+
1. **Online**: Visit the published documentation at [queryleaf.com/docs](https://queryleaf.com/docs)
10+
11+
2. **Locally**: Run the documentation server locally with:
12+
```bash
13+
npm run docs:serve
14+
```
15+
Then open your browser to [http://localhost:8000](http://localhost:8000)
16+
17+
## Documentation Structure
18+
19+
The documentation is organized as follows:
20+
21+
- `index.md`: Home page
22+
- `getting-started/`: Installation and quickstart guides
23+
- `usage/`: Core concepts and usage examples
24+
- `sql-syntax/`: Detailed SQL syntax reference
25+
- `debugging/`: Troubleshooting and limitations
26+
- `licenses/`: License information
27+
- `assets/`: Images and other static assets
28+
- `stylesheets/`: Custom CSS styles
29+
30+
## Contributing to the Documentation
31+
32+
We welcome contributions to improve the documentation. Follow these steps:
33+
34+
1. Make your changes to the Markdown files in this directory
35+
2. Run `npm run docs:serve` to preview your changes locally
36+
3. Once you're satisfied, submit a pull request with your changes
37+
38+
## Building the Documentation
39+
40+
To build a static version of the documentation:
41+
42+
```bash
43+
npm run docs:build
44+
```
45+
46+
This will generate a `site` directory containing the static HTML, CSS, and JavaScript files.
47+
48+
## Deploying the Documentation
49+
50+
To deploy the documentation to GitHub Pages:
51+
52+
```bash
53+
npm run docs:deploy
54+
```
55+
56+
This will build the documentation and deploy it to the `gh-pages` branch of the repository.
57+
58+
## Documentation Technology
59+
60+
- [MkDocs](https://www.mkdocs.org/): The documentation site generator
61+
- [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/): The theme for the documentation
62+
- [Python-Markdown](https://python-markdown.github.io/): The Markdown parser
63+
- [PyMdown Extensions](https://facelessuser.github.io/pymdown-extensions/): Extensions for Python-Markdown
64+
65+
## Local Development Setup
66+
67+
To set up the documentation development environment:
68+
69+
1. Install Python 3.x
70+
2. Install MkDocs and all required packages using the requirements.txt file:
71+
```bash
72+
pip install -r ../requirements.txt
73+
```
74+
75+
## Documentation Guidelines
76+
77+
When contributing to the documentation, please follow these guidelines:
78+
79+
1. Use clear, concise language
80+
2. Include code examples where appropriate
81+
3. Follow the existing structure and formatting
82+
4. Test your changes locally before submitting
83+
5. Use proper Markdown syntax and formatting
84+
6. Include screenshots or diagrams for complex concepts when helpful
85+
86+
## License
87+
88+
The documentation is licensed under the same terms as the QueryLeaf project.

docs/assets/favicon.ico

3.4 KB
Binary file not shown.
3.4 KB
Loading

docs/assets/logo-white.svg

Lines changed: 9 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)