|
| 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. |
0 commit comments