aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md13
1 files changed, 11 insertions, 2 deletions
diff --git a/README.md b/README.md
index af768361ab..3214dc16b3 100644
--- a/README.md
+++ b/README.md
@@ -150,7 +150,13 @@ The `OR` operator works like this:
users.where(users[:name].eq('bob').or(users[:age].lt(25)))
```
-The `AND` operator behaves similarly. Here is an example of the `DISTINCT` operator:
+The `AND` operator behaves similarly (same exact behaviour as chained calls to `.where`):
+
+```ruby
+users.where(users[:name].eq('bob').and(users[:age].lt(25)))
+```
+
+Here is an example of the `DISTINCT` operator:
```ruby
posts = Arel::Table.new(:posts)
@@ -188,7 +194,7 @@ users.project(users[:age].average.as("mean_age"))
# => SELECT AVG(users.age) AS mean_age FROM users
```
-### The Crazy Features
+### The Advanced Features
The examples above are fairly simple and other libraries match or come close to matching the expressiveness of Arel (e.g. `Sequel` in Ruby).
@@ -215,6 +221,7 @@ products.
#### Complex Joins
+##### Alias
Where Arel really shines is in its ability to handle complex joins and aggregations. As a first example, let's consider an "adjacency list", a tree represented in a table. Suppose we have a table `comments`, representing a threaded discussion:
```ruby
@@ -240,6 +247,7 @@ comments_with_replies = \
This will return the reply for the first comment.
+##### CTE
[Common Table Expressions (CTE)](https://en.wikipedia.org/wiki/Common_table_expressions#Common_table_expression) support via:
Create a `CTE`
@@ -262,6 +270,7 @@ users.
# FROM users INNER JOIN cte_table ON users.id = cte_table.user_id
```
+#### Write SQL strings
When your query is too complex for `Arel`, you can use `Arel::SqlLiteral`:
```ruby