Skip to content

Commit

Permalink
Updates readme
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
danmcclain committed Dec 15, 2012
1 parent 67d68df commit 6a96542
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,10 @@ predicate for the `&&` operator.

```ruby
user_arel = User.arel_table
query = user_arel.where(user_arel[:tags].array_overlap(['one','two']))
.project(Arel.sql('*'))
query.to_sql
# => SELECT \"users\".* FROM \"users\" WHERE \"users\".\"tags\" && '{one,two}'

# Execute the query
User.find_by_sql(query.to_sql)
User.where(user_arel[:tags].array_overlap(['one','two']))
# => SELECT \"users\".* FROM \"users\" WHERE \"users\".\"tags\" && '{one,two}'
```

#### ANY or ALL functions
Expand Down Expand Up @@ -223,13 +220,10 @@ user_arel = User.arel_table

any_tags_function = Arel::Nodes::NamedFunction.new('ANY', [user_arel[:tags]])
predicate = Arel::Nodes::Equality.new('test', any_tags_function)
query = user_arel.where(predicate).project(Arel.sql('*'))

query.to_sql
#=> SELECT \"users\".* FROM \"users\" WHERE 'test' = ANY(\"users\".\"tags\")

# Execute the query
User.find_by_sql(query.to_sql)
User.where(predicate)
#=> SELECT \"users\".* FROM \"users\" WHERE 'test' = ANY(\"users\".\"tags\")
```

The ALL version of this same predicate can be generated by swap `'ANY'`
Expand All @@ -256,24 +250,22 @@ predicate for the `<<` operator.

```ruby
user_arel = User.arel_table
query = user_arel.where(user_arel[:ip_address].contained_witin('127.0.0.1/24'))
.project(Arel.sql('*'))

query.to_sql
# => SELECT \"users\".* FROM \"users\" WHERE \"users\".\"ip_address\" << '127.0.0.1/24'

# Execute the query
User.find_by_sql(query.to_sql)
User.where(user_arel[:ip_address].contained_witin('127.0.0.1/24'))
# => SELECT \"users\".* FROM \"users\" WHERE \"users\".\"ip_address\" << '127.0.0.1/24'
```

## Indexes

### Index types

Postgres\_ext allows you to specify an index type at index creation.
Postgres\_ext allows you to specify index type and index operator
class at index creation.

```ruby
add_index :table_name, :column, :index_type => :gin
add_index :table_name, :column, :index_type => :gin, :index_opclass => :gin_trgm_ops
```

### Where clauses
Expand Down

0 comments on commit 6a96542

Please sign in to comment.