Tao
Nothing to see here. Just playing around.
Setup
The Tables
ActiveRecord::Base.establish_connection({
adapter: "postgresql",
database: "tao_test",
})
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS tao_objects")
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS tao_associations")
ActiveRecord::Base.connection.execute(<<-SQL)
CREATE TABLE tao_objects (
id BIGSERIAL NOT NULL,
type CHARACTER VARYING(255) NOT NULL,
value JSONB NOT NULL DEFAULT '{}'::jsonb,
PRIMARY KEY (id)
)
SQL
ActiveRecord::Base.connection.execute(<<-SQL)
CREATE TABLE tao_associations (
id1 BIGINT NOT NULL,
type CHARACTER VARYING(255) NOT NULL,
id2 BIGINT NOT NULL,
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
value JSONB NOT NULL DEFAULT '{}'::jsonb,
PRIMARY KEY (id1, type, id2)
)
SQL
ActiveRecord::Base.connection.execute(<<-SQL)
CREATE INDEX index_tao_associations_on_time ON tao_associations(id1, type, created_at)
SQLThe Code
require 'tao'
client = Tao::Client.new
john = client.objects.create("user", "name" => "John").value!
steve = client.objects.create("user", "name" => "Steve").value!
hoyt = client.objects.create("user", "name" => "Hoyt").value!
brandon = client.objects.create("user", "name" => "Brandon").value!
matt = client.objects.create("user", "name" => "Matt").value!
# make some friends
[steve, hoyt, brandon, matt].each do |user|
client.associations.create(john.id, "friend", user.id).value!
client.associations.create(user.id, "friend", john.id).value!
end
# count some friends
p client.associations.count(john.id, "friend").value! # => 4
p client.associations.count(steve.id, "friend").value! # => 1
# query some friends
p client.associations.range(john.id, "friend").value!
p client.associations.range(john.id, "friend", offset: 3, limit: 10).value!
Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
