amco / dolly

Not an ORM for CouchDB in rails.
8 stars 3 forks source link

Feature/mango indexing #144

Closed ErickFabian closed 5 years ago

ErickFabian commented 5 years ago

Adds public api to create indexes for querys and adds check for methods find_by and where to verify an index exists for the given query properties

Example

User.find_by(username: 'username')
=> Dolly::IndexNotFoundError (Dolly::IndexNotFoundError)

Dolly::MangoIndex.create('username-json-index', ['username'])
=> {:result=>"created", :id=>"_design/4fd61cc70e6ddc6a4f416938008165c5609f49e9", :name=>"username-json-index"}

User.find_by(username: 'username')
# index takes around 4 minutes to build on the av database with 2575233 documents you can see the progress in http://127.0.0.1:5984/_utils/#/activetasks
=> #<User:0x00007fb5fbe0ac00 @doc={:_id=>"user/+04diego@gmail.com", :username=>"ErickFabian", :email=>"+04diego@gmail.com", :first_name=>"Diego", :last_name=>"Torres"}, @username="ErickFabian", @email="+04diego@gmail.com", @first_name="Diego", @last_name="Torres">

Public Api

Dolly::MangoIndex.create(index_name: String, fields: Array, type: String(default: 'json'))
=> Creates an index given for the fields passed

Dolly::MangoIndex.all
=> Returns an array of all the indexes

Dolly::MangoIndex.find_by_fields(fields: Array(symbols))
=> Tries to find an index for the given array of symbols

Dolly::MangoIndex.delete_all
=> Deletes all the indexes created but skips the special index for id's that is created by default

Dolly::MangoIndex.delete(index_doc)
=> Deletes the given index document