Module: OrientdbBinary::DatabaseOperations::Record
- Included in:
- OrientdbBinary::Database
- Defined in:
- lib/orientdb_binary/database_operations/record.rb
Instance Method Summary collapse
- #count_records ⇒ Object
-
#create_record(args) ⇒ Object
Create record cluster_id: int or cluster_name: string record_content: string -> it’s serialized document; use create_record_from_object which serialize hash into string accepted by Orientdb Usage: db.create_record(cluster_id: 5, record_content: “Post@title="Post title"”).
-
#create_record_from_object(record) ⇒ Object
Create record from object Usage: record = { :@class => “Posts”, :@type => “d”, :@cluster => “posts” name: “some name” param: “some param” } Usage: db.create_record_from_object(record).
- #delete_record(args) ⇒ Object
-
#load_record(args) ⇒ Object
rid: #id:position / id:position or cluster_id: int cluster:position: int optional fetch_plan: string (by default used “*:0”) ignore_cache: int (0-1, by default 1) load_tombstones: int (0-1, by default 0) Usage: db.load_record(“#5:2”) db.load_record(“#5:2”, fetch_plan: “*:-1”) db.load_record(5, 2, fetch_plan: “*:-1”, ignore_cache: 0, load_tombstones: 1).
- #update_record(args) ⇒ Object
Instance Method Details
#count_records ⇒ Object
100 101 102 |
# File 'lib/orientdb_binary/database_operations/record.rb', line 100 def count_records OrientdbBinary::Protocols::DbCountRecords.new(params).process(socket) end |
#create_record(args) ⇒ Object
Create record cluster_id: int or cluster_name: string record_content: string -> it’s serialized document; use create_record_from_object which serialize hash into string accepted by Orientdb Usage: db.create_record(cluster_id: 5, record_content: “Post@title="Post title"”)
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/orientdb_binary/database_operations/record.rb', line 76 def create_record(args) if args[:cluster_name] and not args[:cluster_id] args[:cluster_id] = (cluster = find_datacluster_by(cluster_name: args[:cluster_name])) ? cluster_id : nil end defaults = { datasegment_id: -1, record_type: "d".ord, mode: 0 } = defaults.merge(args) answer = OrientdbBinary::Protocols::RecordCreate.new(params(args)).process(socket) answer.process() end |
#create_record_from_object(record) ⇒ Object
Create record from object Usage: record =
:@class => "Posts",
:@type => "d",
:@cluster => "posts"
name: "some name"
param: "some param"
Usage: db.create_record_from_object(record)
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/orientdb_binary/database_operations/record.rb', line 52 def create_record_from_object(record) record_type = record[:@type] ? record[:@type].ord : "d".ord cluster_id = (cluster = find_datacluster_by(cluster_name: 'default')) ? cluster[:cluster_id] : nil if record[:@cluster] if record[:@cluster].is_a? Integer cluster_id = record[:@cluster] else cluster_id = (cluster = find_datacluster_by(cluster_name: record[:@cluster])) ? cluster[:cluster_id] : cluster_id end elsif record[:@class] cluster_id = (cluster = find_datacluster_by(cluster_name: record[:@class])) ? cluster[:cluster_id] : cluster_id end record_content = OrientdbBinary::Parser::Serializer.new.serialize_document(record) create_record(record_type: record_type, cluster_id: cluster_id, record_content: record_content) end |
#delete_record(args) ⇒ Object
96 97 98 |
# File 'lib/orientdb_binary/database_operations/record.rb', line 96 def delete_record(args) OrientdbBinary::Protocols::RecordDelete.new(params(args)).process(socket) end |
#load_record(args) ⇒ Object
rid: #id:position / id:position or cluster_id: int cluster:position: int optional fetch_plan: string (by default used “*:0”) ignore_cache: int (0-1, by default 1) load_tombstones: int (0-1, by default 0) Usage: db.load_record(“#5:2”) db.load_record(“#5:2”, fetch_plan: “*:-1”) db.load_record(5, 2, fetch_plan: “*:-1”, ignore_cache: 0, load_tombstones: 1)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/orientdb_binary/database_operations/record.rb', line 24 def load_record(args) if args[:rid] match = args[:rid].match(/#*(?<id>\d+):(?<position>\d+)/) args[:cluster_id] = match[:id].to_i args[:cluster_position] = match[:position].to_i end defaults = { fetch_plan: "*:0", ignore_cache: 1, load_tombstones: 0 } = defaults.merge(args) answer = OrientdbBinary::Protocols::RecordLoad.new(params()).process(socket) answer.process() end |
#update_record(args) ⇒ Object
92 93 94 |
# File 'lib/orientdb_binary/database_operations/record.rb', line 92 def update_record(args) OrientdbBinary::Protocols::RecordUpdate.new(params(args)).process(socket) end |