Skip to content

No fluff c extension implementing the FairCom ctdb sdk if you just made it out of the legacy ISAM layer

License

Notifications You must be signed in to change notification settings

drfeelngood/ctdb-rb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ctdb-rb

A no fluff extension implementing the FairCom c-tree ctdb sdk.

Install

$ gem install ctdb

Session

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")

Table

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)

Record

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

Cleanup

Be sure to close any tables and the session.

table.close
session.logout

CT::Model

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]")

CT::Query

Simple interface to perform CT::Record queries.

Options

  • 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

Contributing

  • Fork the project
  • Create a topic branch
  • Hack away
  • Submit a pull request

About

No fluff c extension implementing the FairCom ctdb sdk if you just made it out of the legacy ISAM layer

Resources

License

Stars

Watchers

Forks

Packages

No packages published