Tie Triple Store (Headless)
Headless (no GUI) example demonstrating the tie triple store module using the core package.
ℹ️
Requires a running tie-daemon listening on
http://localhost:1161. Start one from the tie repository (go run ./cmd/tie-daemon) before running this example.Features
- Triple store - Store
(key, relation, value)triples withdb.add() - Sync writes - Commit pending writes with
db.sync() - Forward lookup - Read a key’s attributes with
db.get(key) - Reverse queries - Find keys by value with
db.query({terms, reverse: true}) - Batch operations - Group writes with
db.batch()/batch.run() - Existence & updates -
db.exists(key)anddb.update(key, relation, old, new)
Code
require(["v0.7", "@tie", "@strings"])
// Connect to tie daemon
let db = tie.connect("http://localhost:1161", {
username: "defaultuser",
password: "defaultpassword"
})
// Add documents with tags
db.add("rust-guide", "tag", "rust")
db.add("rust-guide", "tag", "programming")
db.add("rust-guide", "author", "Alex Chen")
db.add("go-concurrency", "tag", "golang")
db.add("go-concurrency", "tag", "programming")
// Sync to ensure writes are committed
db.sync()
// Get a single document
let rustGuide = db.get("rust-guide")
// Reverse query: which keys have the "programming" tag?
// (works because 'tag' is in the daemon's default ReverseRelations list)
let result = db.query({
terms: ["programming"],
reverse: true
})
print("Total count:", result.total_count)
// Batch operations
let batch = db.batch()
batch.add("python-async", "tag", "python")
batch.add("python-async", "tag", "programming")
batch.set("python-async", "author", ["Pat Wilson"])
batch.run()
// Existence check and update
print("rust-guide exists:", db.exists("rust-guide"))
db.update("rust-guide", "tag", "tutorial", "beginner")The Go host enables the module with core.WithTie() and runs the script through core.NewContext(...).Eval().
Data Model
Tie stores triples: (key, relation, value) — e.g. rust-guide | tag | programming means “rust-guide has tag programming”. Reverse queries only work for relations in the daemon’s ReverseRelations config; tag is in the default list.
Running
cd examples/36-tie-headless
go run main.go