Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ jobs:
strategy:
matrix:
include:
- ruby: '4.0'
active-model: '8.1.4'
couchbase: '8.0.4'
- ruby: '4.0'
active-model: '8.1.4'
couchbase: '7.6.13'
Expand Down
64 changes: 8 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ CouchbaseOrm::Connection.config = {
}
```

Views are generated on application load if they don't exist or mismatch.
This works fine in production however by default in development models are lazy loaded.

# config/environments/development.rb
config.eager_load = true

## Examples

```ruby
Expand Down Expand Up @@ -148,51 +142,7 @@ context of rails application. You can also enforce types using ruby
end
```

## Views (aka Map/Reduce indexes)

Views are defined in the model and typically just emit an attribute that
can then be used for filtering results or ordering.

```ruby
class Comment < CouchbaseOrm::Base
attribute :author :string
attribute :body, :string
view :all # => emits :id and will return all comments
view :by_author, emit_key: :author

# Generates two functions:
# * the by_author view above
# * def find_by_author(author); end
index_view :author

# You can make compound keys by passing an array to :emit_key
# this allow to query by read/unread comments
view :by_read, emit_key: [:user_id, :read]
# this allow to query by view_count
view :by_view_count, emit_key: [:user_id, :view_count]

validates_presence_of :author, :body
end
```

You can use `Comment.find_by_author('name')` to obtain all the comments by
a particular author. The same thing, using the view directly would be:
`Comment.by_author(key: 'name')`

When using a compound key, the usage is the same, you just give the full key :

```ruby
Comment.by_read(key: '["'+user_id+'",false]') # gives all unread comments for one particular user

# or even a range !

Comment.by_view_count(startkey: '["'+user_id+'",10]', endkey: '["'+user_id+'",20]')

# gives all comments that have been seen more than 10 times but less than 20
```
Check this couchbase help page to learn more on what's possible with compound keys : <https://developer.couchbase.com/documentation/server/3.x/admin/Views/views-translateSQL.html>

Ex : Compound keys allows to decide the order of the results, and you can reverse it by passing `descending: true`
## Ignored properties

```ruby
class Comment < CouchbaseOrm::Base
Expand Down Expand Up @@ -233,7 +183,10 @@ WARNING: If a document exists without a property, the query will failed! So you

## N1ql

Like views, it's possible to use N1QL to process some requests used for filtering results or ordering.
N1QL queries can be defined in the model to filter or order results.

> Couchbase Views (map/reduce, `view` / `index_view` / `ensure_design_document!`) are no longer supported:
> Couchbase Server 8.0 uses the Magma storage backend by default, which does not support Views. Use N1QL instead.

```ruby
class Comment < CouchbaseOrm::Base
Expand All @@ -242,7 +195,7 @@ Like views, it's possible to use N1QL to process some requests used for filterin
n1ql :by_author, emit_key: :author

# Generates two functions:
# * the by_author view above
# * a by_author N1QL query
# * def find_by_author(author); end
index_n1ql :author

Expand Down Expand Up @@ -346,16 +299,15 @@ There are common active record helpers available for use `belongs_to` and `has_m
end
```

By default, `has_many` uses a view for association,
but you can define a `type` option to specify an association using N1QL instead:
`has_many` associations are resolved with N1QL queries:

```ruby
class Comment < CouchbaseOrm::Base
belongs_to :author
end

class Author < CouchbaseOrm::Base
has_many :comments, type: :n1ql, dependent: :destroy
has_many :comments, dependent: :destroy
end
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ With Couchbase ORM, you can:
- Define your data models and their relationships
- Perform CRUD (Create, Read, Update, Delete) operations on your models
- Query your data using a flexible and expressive query language
- Use Couchbase-specific features like N1QL queries and views
- Use Couchbase-specific features like N1QL queries
- Implement advanced features such as data validation, callbacks, and associations

Couchbase ORM abstracts away the low-level details of interacting with Couchbase Server, enabling you to focus on writing business logic and building great applications.
Expand All @@ -36,9 +36,7 @@ Couchbase ORM offers a wide range of features to make working with Couchbase Ser

8. **N1QL Queries**: Execute N1QL queries directly from your Ruby code and map the results to your models.

9. **Views**: Create and query Couchbase views to efficiently retrieve data based on specific criteria.

10. **Nested Documents**: Embed related documents within a parent document for denormalized data modeling.
9. **Nested Documents**: Embed related documents within a parent document for denormalized data modeling.

These are just a few of the many features offered by Couchbase ORM. Throughout this documentation, we'll explore these features in-depth and provide examples of how to use them in your Ruby applications.

Expand Down
158 changes: 0 additions & 158 deletions docusaurus/docs/tutorial-ruby-couchbase-orm/08-views.md

This file was deleted.

2 changes: 0 additions & 2 deletions lib/couchbase-orm/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
require 'couchbase-orm/changeable'
require 'couchbase-orm/inspectable'
require 'couchbase-orm/error'
require 'couchbase-orm/views'
require 'couchbase-orm/n1ql'
require 'couchbase-orm/persistence'
require 'couchbase-orm/associations'
Expand Down Expand Up @@ -126,7 +125,6 @@ class Base < Document
include Persistence

include Associations
include Views
include QueryHelper
include N1ql
include Relation
Expand Down
9 changes: 0 additions & 9 deletions lib/couchbase-orm/proxies/bucket_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ def initialize(proxyfied)
self.class.define_method(:n1ql) do
N1qlProxy.new(@proxyfied.n1ql)
end

self.class.define_method(:view) do |design, view, **opts, &block|
@results = nil if @current_query != "#{design}_#{view}"
@current_query = "#{design}_#{view}"
return @results if @results

CouchbaseOrm.logger.debug "View - #{design} #{view}"
@results = ResultsProxy.new(@proxyfied.send(:view, design, view, **opts, &block))
end
end

def method_missing(name, *args, **options, &block)
Expand Down
14 changes: 0 additions & 14 deletions lib/couchbase-orm/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module Rails #:nodoc:
module Couchbase #:nodoc:
class Railtie < Rails::Railtie #:nodoc:
config.couchbase_orm = ActiveSupport::OrderedOptions.new
config.couchbase_orm.ensure_design_documents = true

# Maping of rescued exceptions to HTTP responses
#
Expand Down Expand Up @@ -69,19 +68,6 @@ def self.rescue_responses
end
end
end

# Check (and upgrade if needed) all design documents
config.after_initialize do |app|
if config.couchbase_orm.ensure_design_documents
begin
::CouchbaseOrm::Base.descendants.each do |model|
model.ensure_design_document!
end
rescue ::MTLibcouchbase::Error::Timedout, ::MTLibcouchbase::Error::ConnectError, ::MTLibcouchbase::Error::NetworkError
# skip connection errors for now
end
end
end
end
end
end
Loading
Loading