A no fluff extension implementing the FairCom c-tree ctdb sdk.
$ gem install ctdb
A c-treeACE session can be started by creating an instace of CT::Session
and
calling #logon
:
session = CT::Session.new(CT::SESSION_CTREE)
session.logon("host", "user", "pass")
Once a session is active, you can begin to open tables.
table = CT::Table.new(session)
table.path = "/path/to/table"
table.open("table_name", CT::OPEN_NORMAL)
Now that we have a table open, lets locate a record based on a unique index.
record = CT::Record.new(table)
record.clear
record.set_default_index("foo_ndx")
record.set_field_as_unsigned('id', 123)
record.find(CT::FIND_EQ)
puts record.get_field_as_unsigned('id') # => 123
Record sets!
record = CT::Record.new(table)
record.clear
record.default_index = "foo_ndx"
record.set_field_as_string("foo", "bar")
bytes = 0
record.get_default_index.segments.each do |segment|
bytes += segment.field.length
bytes -= 1 if segment.absolute_byte_offset? # => Old school
end
record.set_on(bytes)
if record.first
begin
puts record.inspect
end while record.next
end
Be sure to close any tables and the session.
table.close
session.logout
require 'ctdb'
class Person < CT::Model
self.table_path = "/path/to"
self.table_name = :people
self.primary_key = :index_on_email
end
# Configure c-tree session
CT::Model.session = {
engine: "FAIRCOMS",
username: "",
password: "",
mode: CT::SESSION_CTREE
}
# Find a record by index
person = Person.find_by(:index_on_email, "[email protected]")
Simple interface to perform CT::Record
queries.
- find_mode
- index
- index_segments
- limit
- offset
- filter
- endif
- transformer
person = CT::Query.new(table)
.index(:email_ndx)
.index_segments(email: "[email protected]")
.eq
# Server side filtering. Find all people in the great state of Oklahoma
people = CT::Query.new(table)
.filter(%Q{strncmp(state, "OK", 2) == 0})
.set
- Fork the project
- Create a topic branch
- Hack away
- Submit a pull request