Module: KyotoCabinet::Db

Included in:
PolymorphicDb
Defined in:
lib/kyotocabinet_ffi/db/db.rb,
lib/kyotocabinet_ffi/db/file_hash_db.rb,
lib/kyotocabinet_ffi/db/memory_hash_db.rb,
lib/kyotocabinet_ffi/db/polymorphic_db.rb

Defined Under Namespace

Classes: FileHash, MemoryHash, PolymorphicDb

Instance Method Summary collapse

Instance Method Details

#clearObject



98
99
100
# File 'lib/kyotocabinet_ffi/db/db.rb', line 98

def clear
  bool_return(LibKyotoCabinet::kcdbclear(@kc_db_pointer))
end

#clear!Object



102
103
104
# File 'lib/kyotocabinet_ffi/db/db.rb', line 102

def clear!
  fail last_error if not clear
end

#closeObject



106
107
108
# File 'lib/kyotocabinet_ffi/db/db.rb', line 106

def close
  bool_return(LibKyotoCabinet::kcdbclose(@kc_db_pointer))
end

#close!Object



110
111
112
# File 'lib/kyotocabinet_ffi/db/db.rb', line 110

def close!
  fail last_error if not close
end

#get(key) ⇒ Object



82
83
84
85
86
# File 'lib/kyotocabinet_ffi/db/db.rb', line 82

def get(key)
  key_string = key.to_s
  value_size_ptr = LibKyotoCabinet::FFI::MemoryPointer.new :pointer
  LibKyotoCabinet::kcdbget(@kc_db_pointer, key_string, key_string.length, value_size_ptr)
end

#last_errorObject



63
64
65
# File 'lib/kyotocabinet_ffi/db/db.rb', line 63

def last_error
  SystemCallError.new(last_error_message, last_error_code)
end

#last_error_codeObject



55
56
57
# File 'lib/kyotocabinet_ffi/db/db.rb', line 55

def last_error_code
  LibKyotoCabinet::kcdbecode(@kc_db_pointer)
end

#last_error_messageObject



59
60
61
# File 'lib/kyotocabinet_ffi/db/db.rb', line 59

def last_error_message
  LibKyotoCabinet::kcdbemsg(@kc_db_pointer)
end

#newObject



51
52
53
# File 'lib/kyotocabinet_ffi/db/db.rb', line 51

def new
  @kc_db_pointer = LibKyotoCabinet::kcdbnew
end

#open(path, *options) ⇒ Object



67
68
69
70
71
72
# File 'lib/kyotocabinet_ffi/db/db.rb', line 67

def open(path, *options)
  mode = (options & LibKyotoCabinet::MODES.keys).map { |k|
    LibKyotoCabinet::MODES[k]
  }.reduce(0, :|)
  bool_return(LibKyotoCabinet::kcdbopen(@kc_db_pointer, path.to_s, mode))
end

#open!(path, *options) ⇒ Object



74
75
76
# File 'lib/kyotocabinet_ffi/db/db.rb', line 74

def open!(path, *options)
  fail last_error if not open(path, *options)
end

#set(key, value) ⇒ Object



88
89
90
91
92
# File 'lib/kyotocabinet_ffi/db/db.rb', line 88

def set(key, value)
  key_string = key.to_s
  value_string = value.to_s
  bool_return(LibKyotoCabinet::kcdbset(@kc_db_pointer, key_string, key_string.length, value_string, value_string.length))
end

#set!(key, value) ⇒ Object



94
95
96
# File 'lib/kyotocabinet_ffi/db/db.rb', line 94

def set!(key, value)
  fail last_error if not set(key, value)
end

#sizeObject



78
79
80
# File 'lib/kyotocabinet_ffi/db/db.rb', line 78

def size
  LibKyotoCabinet::kcdbcount(@kc_db_pointer)
end