Skip to content

Commit 6cd6def

Browse files
Antony BaileyAntony Bailey
authored andcommitted
Init
0 parents  commit 6cd6def

16 files changed

+1496
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Standard Query Language
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Standard Query Language (SQLY)
2+
3+
**SQLY** is a YAML-based query language inspired by JQL, Kusto, and DQL. It is designed for querying structured and semi-structured data efficiently.
4+
5+
## 📖 Specification Overview
6+
7+
### 🔹 [Basics](basics.md)
8+
9+
Learn how to write simple SQLY queries, including `select`, `from`, `where`, `order_by`, and `group_by`.
10+
11+
### 🔹 [Advanced Features](advanced_features.md)
12+
13+
Explore complex filtering, logical operators, sorting, and aggregations.
14+
15+
### 🔹 [Subqueries](subqueries.md)
16+
17+
Use subqueries to fetch results dynamically within a query.
18+
19+
### 🔹 [Common Table Expressions (CTEs)](ctes.md)
20+
21+
Utilize CTEs to structure queries for better readability and performance.
22+
23+
### 🔹 [Window Functions](window_functions.md)
24+
25+
Perform ranking, running totals, and moving averages using window functions.
26+
27+
### 🔹 [Recursive Queries](recursive_queries.md)
28+
29+
Handle hierarchical data, such as employee relationships or category trees.
30+
31+
### 🔹 [Full-text Search](full_text_search.md)
32+
33+
Perform fuzzy searches and text matching in large datasets.
34+
35+
### 🔹 [Geospatial Queries](geospatial_queries.md)
36+
37+
Work with geospatial data to find points within a radius, bounding boxes, and distances.
38+
39+
### 🔹 [Machine Learning](machine_learning.md)
40+
41+
Integrate predictive models for forecasting and anomaly detection within queries.
42+
43+
## 🚀 Getting Started
44+
45+
To start using SQLY, check out the [Basics](basics.md) section and explore examples.
46+
47+
## 📌 Contributions
48+
49+
Contributions are welcome! Feel free to submit PRs or issues for improvements.
50+
51+
## 📜 License
52+
53+
This project is licensed under the MIT License.

advanced_features.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# SQLY Advanced Features
2+
3+
## 📖 Introduction
4+
5+
This section covers advanced SQLY features, including complex filtering, sorting, joins, pagination, and more.
6+
7+
---
8+
9+
## 🔎 Complex Filtering with Logical Operators
10+
11+
SQLY supports combining multiple conditions using `and`, `or`, and `not`.
12+
13+
### ✅ Example 1: Fetch Users with Multiple Conditions
14+
15+
```yaml
16+
query:
17+
select: [id, name, email]
18+
from: users
19+
where:
20+
and:
21+
- status: active
22+
- role: admin
23+
- last_login:
24+
gte: "2024-01-01"
25+
```
26+
27+
### ✅ Example 2: Fetch Orders Matching Multiple Statuses
28+
29+
```yaml
30+
query:
31+
select: [order_id, customer, total_price, status]
32+
from: orders
33+
where:
34+
or:
35+
- status: completed
36+
- status: shipped
37+
```
38+
39+
---
40+
41+
## 📊 Sorting & Pagination
42+
43+
Sorting results and limiting the number of returned rows.
44+
45+
### ✅ Example 3: Sort Users by Last Login Date (Descending)
46+
47+
```yaml
48+
query:
49+
select: [id, name, last_login]
50+
from: users
51+
order_by: last_login DESC
52+
limit: 20
53+
```
54+
55+
### ✅ Example 4: Paginate Results (Second Page, 10 Results per Page)
56+
57+
```yaml
58+
query:
59+
select: [id, name, created_at]
60+
from: users
61+
limit: 10
62+
offset: 10
63+
```
64+
65+
---
66+
67+
## 🔗 Joining Tables
68+
69+
SQLY supports joining multiple tables.
70+
71+
### ✅ Example 5: Fetch Orders with Customer Names
72+
73+
```yaml
74+
query:
75+
select: [orders.order_id, customers.name, orders.total_price]
76+
from: orders
77+
join:
78+
customers:
79+
on: orders.customer_id = customers.id
80+
```
81+
82+
---
83+
84+
## 🔍 Searching with `like` and `full_text_search`
85+
86+
Perform searches based on text patterns.
87+
88+
### ✅ Example 6: Find Products Containing "Wireless"
89+
90+
```yaml
91+
query:
92+
select: [id, name, description]
93+
from: products
94+
where:
95+
name:
96+
like: "%wireless%"
97+
```
98+
99+
### ✅ Example 7: Full-Text Search on Articles
100+
101+
```yaml
102+
query:
103+
select: [id, title, content]
104+
from: articles
105+
where:
106+
content:
107+
full_text_search: "machine learning"
108+
```
109+
110+
---
111+
112+
## 📌 Summary
113+
114+
- Use `and`, `or`, `not` for complex filtering.
115+
- `order_by` sorts results.
116+
- `limit` and `offset` enable pagination.
117+
- `join` allows querying across tables.
118+
- `like` and `full_text_search` support text searches.

basics.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# SQLY Basics
2+
3+
## 📖 Introduction
4+
5+
SQLY (Standard Query Language) is a YAML-based query language designed for structured and semi-structured data. It is inspired by JQL, Kusto, and DQL while offering a human-readable syntax.
6+
7+
---
8+
9+
## 🛠 Basic Query Structure
10+
11+
A simple SQLY query consists of the following components:
12+
13+
- `select`: Specifies the fields to retrieve.
14+
- `from`: Defines the data source.
15+
- `where`: Filters the results.
16+
- `order_by`: Sorts the results.
17+
- `limit`: Limits the number of returned rows.
18+
19+
### ✅ Example 1: Fetch Active Users
20+
21+
```yaml
22+
query:
23+
select: [id, name, email]
24+
from: users
25+
where:
26+
status: active
27+
order_by: name ASC
28+
limit: 50
29+
```
30+
31+
### ✅ Example 2: Fetch Orders Above a Certain Price
32+
33+
```yaml
34+
query:
35+
select: [order_id, customer, total_price]
36+
from: orders
37+
where:
38+
total_price:
39+
gt: 100
40+
order_by: total_price DESC
41+
```
42+
43+
---
44+
45+
## 🔍 Filtering & Logical Operators
46+
47+
SQLY supports multiple conditions using logical operators:
48+
49+
| Operator | Description |
50+
|----------|------------|
51+
| `gt` | Greater than |
52+
| `lt` | Less than |
53+
| `gte` | Greater than or equal |
54+
| `lte` | Less than or equal |
55+
| `in` | Matches any value in a list |
56+
| `not` | Negates a condition |
57+
58+
### ✅ Example 3: Fetch High-Value Orders from Specific Customers
59+
60+
```yaml
61+
query:
62+
select: [order_id, customer, total_price]
63+
from: orders
64+
where:
65+
total_price:
66+
gte: 500
67+
customer:
68+
in: ["Alice", "Bob", "Charlie"]
69+
```
70+
71+
### ✅ Example 4: Fetch Users Who Are Not Admins
72+
73+
```yaml
74+
query:
75+
select: [id, name]
76+
from: users
77+
where:
78+
role:
79+
not: admin
80+
```
81+
82+
---
83+
84+
## 📊 Aggregation & Grouping
85+
86+
SQLY allows aggregation functions with `group_by`.
87+
88+
### ✅ Example 5: Calculate Average Order Value per Customer
89+
90+
```yaml
91+
query:
92+
select:
93+
- customer_id
94+
- avg: total_price
95+
from: orders
96+
group_by: customer_id
97+
```
98+
99+
---
100+
101+
## 📌 Summary
102+
103+
- Use `select` to define fields.
104+
- `from` specifies the data source.
105+
- `where` applies filtering.
106+
- Use `order_by` for sorting results.
107+
- Apply `group_by` for aggregations.
108+
109+
Proceed to **[Advanced Features](advanced_features.md)** to explore more capabilities.

ctes.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# SQLY Common Table Expressions (CTEs)
2+
3+
## 📖 Introduction
4+
5+
Common Table Expressions (CTEs) provide a way to define temporary, reusable query structures within a single SQLY query. They improve readability and make complex queries more maintainable.
6+
7+
---
8+
9+
## 🔍 Defining a CTE
10+
11+
CTEs are defined using the `with` keyword, followed by a name and a subquery.
12+
13+
### ✅ Example 1: Using a CTE to Find High-Value Orders
14+
15+
```yaml
16+
query:
17+
with:
18+
high_value_orders:
19+
select: [order_id, customer_id, total_price]
20+
from: orders
21+
where:
22+
total_price:
23+
gt: 1000
24+
select: *
25+
from: high_value_orders
26+
```
27+
28+
---
29+
30+
## 🔗 Using Multiple CTEs
31+
32+
You can define multiple CTEs in a single query to modularize complex logic.
33+
34+
### ✅ Example 2: Using Two CTEs to Analyze Customer Spending
35+
36+
```yaml
37+
query:
38+
with:
39+
customer_totals:
40+
select: [customer_id, sum: total_price as total_spent]
41+
from: orders
42+
group_by: customer_id
43+
top_customers:
44+
select: *
45+
from: customer_totals
46+
where:
47+
total_spent:
48+
gt: 5000
49+
select: *
50+
from: top_customers
51+
```
52+
53+
---
54+
55+
## 🔁 Recursive CTEs
56+
57+
Recursive CTEs allow querying hierarchical data such as organizational structures or category trees.
58+
59+
### ✅ Example 3: Querying an Employee Hierarchy
60+
61+
```yaml
62+
query:
63+
with:
64+
employee_hierarchy:
65+
select: [id, name, manager_id]
66+
from: employees
67+
where:
68+
manager_id: null
69+
union_all:
70+
select: [e.id, e.name, e.manager_id]
71+
from: employees as e
72+
join: employee_hierarchy as eh
73+
on: e.manager_id = eh.id
74+
select: *
75+
from: employee_hierarchy
76+
```
77+
78+
---
79+
80+
## 📌 Summary
81+
82+
- CTEs allow defining temporary, reusable query structures.
83+
- Multiple CTEs can be combined to simplify complex queries.
84+
- Recursive CTEs enable hierarchical data processing.

0 commit comments

Comments
 (0)