Facts and Triples

2 min read Original article ↗

Understanding LinkedRecords' triplestore foundation

LinkedRecords uses a triplestore pattern as its data foundation. Every relationship in the system is expressed as a fact consisting of three parts:

For example:

  • (document123, isA, Report) - A document is classified as a Report
  • (user456, $isMemberOf, team789) - A user belongs to a team
  • (task001, belongsTo, project002) - A task belongs to a project

This simple structure provides powerful flexibility for modeling any domain.

When creating attributes with associated facts, use $it as a placeholder that refers to the attribute being created:

The $it placeholder is replaced with the actual attribute ID after creation.

With Attribute Creation

The most common way to create facts is when creating an attribute:

Standalone Facts

You can also create facts independently using Fact.createAll():

Fact.createAll() returns an array of the facts that were successfully created. If a fact creation fails due to authorization, it will be silently excluded from the result. Always check the return value if you need to confirm fact creation.

Finding Attributes by Facts

Use Attribute.findAll() to query attributes based on their associated facts:

Finding Facts Directly

Use Fact.findAll() to query facts themselves:

Remove facts using Fact.deleteAll():

Fact deletion requires appropriate authorization. You can only delete facts that you created or have permission to modify.

Custom Facts

Custom facts use predicates without a $ prefix. You can define any predicate that makes sense for your domain:

System Facts (Reserved Predicates)

Predicates starting with $ are reserved for system use and have special authorization semantics. See the Authorization Model for details on predicates like $isAccountableFor, $isMemberOf, $canAccess, etc.

Here's a complete example showing facts in action:

  1. Use meaningful predicates - Choose predicates that clearly express the relationship (e.g., belongsTo, createdBy, stateIs)

  2. Declare terms first - Before using a term as an object in isA facts, declare it using $isATermFor. See Terms for details.

  3. Keep facts atomic - Each fact should represent one relationship. Avoid encoding multiple pieces of information in a single fact.

  4. Use system predicates correctly - Reserved predicates (starting with $) have specific authorization implications. Review the Authorization Model before using them.

  • Query Language - Complete reference for querying facts and attributes
  • Terms - Declaring terms before using them in facts