-
Notifications
You must be signed in to change notification settings - Fork 0
Activemodel7 couchbase ruby client #2
base: master
Are you sure you want to change the base?
Changes from all commits
4b0eebb
392ba90
11af7fc
c796875
75c6add
ba16943
ca2626f
2a27126
09d9901
1e548d2
ee308a7
91bb225
9e5a294
928cf19
5b1cfad
4a5415d
90567db
af0552b
f033491
281e61e
0ad15de
2302b06
e67dd2f
b9cc913
ba029bf
5758961
6267414
7c745da
a724cd5
b4f6638
c849592
4d0100d
74f40b1
1f07d68
797c018
9308902
73c320e
8575350
076c04d
6d44b85
6627060
cf5c88c
5bfb1b0
a82197e
75b1e2a
6c42d4d
8175236
60e2866
ef3ef32
8add1c0
fa065bd
2f254eb
2c52505
58a2dd9
a3e10f9
735b293
3f7de4c
6f9c767
b0cc946
c7f87d8
3788688
ff80f78
5e54254
67603d9
696e332
de0ef2e
eed7f40
922dbb8
b5701f6
684f1f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [master] | ||
| pull_request: | ||
| branches: [master] | ||
|
|
||
| jobs: | ||
| test: | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| - ruby: '3.0' | ||
| gemfile: '7.0.0' | ||
| couchbase: '6.6.5' | ||
| - ruby: '3.0' | ||
| gemfile: '7.0.0' | ||
| couchbase: '7.1.0' | ||
| - ruby: '2.7' | ||
| gemfile: '7.0.0' | ||
| couchbase: '7.1.0' | ||
| - ruby: '2.6' | ||
| gemfile: '5.1.7' | ||
| couchbase: '7.1.0' | ||
| fail-fast: false | ||
| runs-on: ubuntu-20.04 | ||
| name: ${{ matrix.ruby }} rails-${{ matrix.gemfile }} couchbase-${{ matrix.couchbase }} | ||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - run: sudo apt-get update && sudo apt-get install libevent-dev libev-dev python-httplib2 | ||
| - uses: ruby/setup-ruby@v1 | ||
| with: | ||
| ruby-version: ${{ matrix.ruby }} | ||
| bundler-cache: true | ||
| - run: sudo ./ci/run_couchbase.sh $COUCHBASE_VERSION $COUCHBASE_BUCKET $COUCHBASE_USER $COUCHBASE_PASSWORD | ||
| - run: bundle exec rspec | ||
| env: | ||
| ACTIVE_MODEL_VERSION: ${{ matrix.gemfile }} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should rename with active_model_version instead of gemfile |
||
| BUNDLE_JOBS: 4 | ||
| BUNDLE_PATH: vendor/bundle | ||
| COUCHBASE_BUCKET: default | ||
| COUCHBASE_USER: tester | ||
| COUCHBASE_PASSWORD: password123 | ||
| COUCHBASE_VERSION: ${{ matrix.couchbase }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| set -x | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should extract it as a ci service |
||
| set -e | ||
|
|
||
| VERSION=$1 | ||
| BUCKET=$2 | ||
| USER=$3 | ||
| PASSWORD=$4 | ||
|
|
||
|
|
||
| wget https://packages.couchbase.com/releases/$VERSION/couchbase-server-enterprise_$VERSION-ubuntu20.04_amd64.deb | ||
| dpkg -i couchbase-server-enterprise_$VERSION-ubuntu20.04_amd64.deb | ||
| sleep 8 | ||
| sudo service couchbase-server status | ||
| /opt/couchbase/bin/couchbase-cli cluster-init -c 127.0.0.1:8091 --cluster-username=admin --cluster-password=password --cluster-ramsize=320 --cluster-index-ramsize=256 --cluster-fts-ramsize=256 --services=data,index,query,fts | ||
| sleep 5 | ||
| /opt/couchbase/bin/couchbase-cli server-info -c 127.0.0.1:8091 -u admin -p password | ||
| /opt/couchbase/bin/couchbase-cli bucket-create -c 127.0.0.1:8091 -u admin -p password --bucket=$BUCKET --bucket-type=couchbase --bucket-ramsize=160 --bucket-replica=0 --wait | ||
| sleep 1 | ||
| /opt/couchbase/bin/couchbase-cli user-manage -c 127.0.0.1:8091 -u admin -p password --set --rbac-username $USER --rbac-password $PASSWORD --rbac-name "Auto Tester" --roles admin --auth-domain local | ||
| curl http://admin:password@localhost:8093/query/service -d "statement=CREATE INDEX \`default_type\` ON \`$BUCKET\`(\`type\`)" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,14 @@ | |
|
|
||
| require 'active_model' | ||
| require 'active_support/hash_with_indifferent_access' | ||
| require 'couchbase' | ||
| require 'couchbase-orm/error' | ||
| require 'couchbase-orm/views' | ||
| require 'couchbase-orm/n1ql' | ||
| require 'couchbase-orm/persistence' | ||
| require 'couchbase-orm/associations' | ||
| require 'couchbase-orm/proxies/bucket_proxy' | ||
| require 'couchbase-orm/proxies/collection_proxy' | ||
| require 'couchbase-orm/utilities/join' | ||
| require 'couchbase-orm/utilities/enum' | ||
| require 'couchbase-orm/utilities/index' | ||
|
|
@@ -55,6 +57,14 @@ def bucket | |
| @bucket ||= BucketProxy.new(Connection.bucket) | ||
| end | ||
|
|
||
| def cluster | ||
| Connection.cluster | ||
| end | ||
|
|
||
| def collection | ||
| CollectionProxy.new(bucket.default_collection) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a declarative helper to specify collection for the model |
||
| end | ||
|
|
||
| def uuid_generator | ||
| @uuid_generator ||= IdGenerator | ||
| end | ||
|
|
@@ -90,27 +100,20 @@ def attributes | |
| @attributes ||= {} | ||
| end | ||
|
|
||
| def find(*ids, **options) | ||
| options[:extended] = true | ||
| options[:quiet] ||= false | ||
| def find(*ids, quiet: false) | ||
| CouchbaseOrm.logger.debug { "Base.find(l##{ids.length}) #{ids}" } | ||
|
|
||
| ids = ids.flatten.select { |id| id.present? } | ||
| if ids.empty? | ||
| return nil if options[:quiet] | ||
| raise MTLibcouchbase::Error::EmptyKey, 'no id(s) provided' | ||
| raise CouchbaseOrm::Error::EmptyNotAllowed, 'no id(s) provided' | ||
| end | ||
|
|
||
| CouchbaseOrm.logger.debug "Data - Get #{ids}" | ||
| record = bucket.get(*ids, **options) | ||
| records = record.is_a?(Array) ? record : [record] | ||
| records.map! { |record| | ||
| if record | ||
| self.new(record) | ||
| else | ||
| false | ||
| end | ||
| records = quiet ? collection.get_multi(ids) : collection.get_multi!(ids) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should pass option to get_multi |
||
| CouchbaseOrm.logger.debug { "Base.find found(#{records})" } | ||
| records = records.zip(ids).map { |record, id| | ||
| self.new(record, id: id) if record | ||
| } | ||
| records.select! { |rec| rec } | ||
| records.compact! | ||
| ids.length > 1 ? records : records[0] | ||
| end | ||
|
|
||
|
|
@@ -121,12 +124,13 @@ def find_by_id(*ids, **options) | |
| alias_method :[], :find_by_id | ||
|
|
||
| def exists?(id) | ||
| CouchbaseOrm.logger.debug "Data - Get #{id}" | ||
| !bucket.get(id, quiet: true).nil? | ||
| CouchbaseOrm.logger.debug "Data - Exists? #{id}" | ||
| collection.exists(id).exists | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a exists? method in collection |
||
| end | ||
| alias_method :has_key?, :exists? | ||
| end | ||
|
|
||
| class MismatchTypeError < RuntimeError; end | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. surement à supprimer |
||
|
|
||
| # Add support for libcouchbase response objects | ||
| def initialize(model = nil, ignore_doc_type: false, **attributes) | ||
|
|
@@ -145,25 +149,28 @@ def initialize(model = nil, ignore_doc_type: false, **attributes) | |
|
|
||
| if model | ||
| case model | ||
| when ::MTLibcouchbase::Response | ||
| doc = model.value || raise('empty response provided') | ||
| type = doc.delete(:type) | ||
| when Couchbase::Collection::GetResult | ||
| CouchbaseOrm.logger.debug "Initialize with Couchbase::Collection::GetResult" | ||
| doc = model.content || raise('empty response provided') | ||
| type = doc.delete('type') | ||
| doc.delete(:id) | ||
|
|
||
| if type && !ignore_doc_type && type.to_s != self.class.design_document | ||
| raise "document type mismatch, #{type} != #{self.class.design_document}" | ||
| raise CouchbaseOrm::Error::TypeMismatchError.new("document type mismatch, #{type} != #{self.class.design_document}", self) | ||
| end | ||
|
|
||
| @__metadata__.key = model.key | ||
| @__metadata__.key = attributes[:id] | ||
| @__metadata__.cas = model.cas | ||
|
|
||
| # This ensures that defaults are applied | ||
| @__attributes__.merge! doc | ||
| clear_changes_information | ||
| when CouchbaseOrm::Base | ||
| CouchbaseOrm.logger.debug "Initialize with CouchbaseOrm::Base" | ||
|
|
||
| clear_changes_information | ||
| attributes = model.attributes | ||
| attributes.delete(:id) | ||
| attributes.delete('type') | ||
| super(attributes) | ||
| else | ||
| clear_changes_information | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couchbase 5.1 is not well supported on ubuntu 20.04 (missing libssl1.0.0)