data
Semantic data patterns using $.Subject.predicate.Object triples with GraphDL
data
Semantic data modeling using RDF-style triples ($.Subject.predicate.Object) with optional prepositional phrases for expressing relationships, queries, and business logic.
Overview
The data primitive defines how all data is modeled and accessed in the .do platform using semantic triples inspired by RDF (Resource Description Framework) and based on parts of speech from natural language.
Core Principle: All data operations use the pattern $.Subject.predicate.Object where:
- Subject - The entity (Noun)
- predicate - The relationship or action (Verb)
- Object - The related entity or value (Noun)
This makes code self-documenting and intuitive by mirroring natural language structure.
Semantic Triple: $.Subject.predicate.Object
The foundation of all data operations in .do:
import { $ } from 'sdk.do'
// Basic triple: Subject.predicate.Object
await $.User.assign.Role({ userId: 'user-123', roleId: 'admin' })
await $.Order.contains.Items({ orderId: 'order-456' })
await $.Team.has.Members({ teamId: 'team-789' })
// Reading data (queries)
const orders = await $.User.has.Orders({ userId: 'user-123' })
const members = await $.Team.has.Members({ teamId: 'team-789' })
const items = await $.Order.contains.Items({ orderId: 'order-456' })
// Writing data (mutations)
await $.User.update.Profile({ userId: 'user-123', name: 'John Doe' })
await $.Order.add.Item({ orderId: 'order-456', itemId: 'item-999' })
await $.Team.remove.Member({ teamId: 'team-789', userId: 'user-321' })Prepositional Phrases: $.Subject.predicate.Object.in.Thing
Extend triples with prepositional phrases for contextual relationships:
// With prepositional phrase: Subject.predicate.Object.in.Thing
await $.User.assign.Role.in.Organization({
userId: 'user-123',
roleId: 'admin',
orgId: 'org-456',
})
await $.Task.assign.User.in.Project({
taskId: 'task-789',
userId: 'user-123',
projectId: 'project-999',
})
await $.Product.add.Category.in.Catalog({
productId: 'prod-111',
categoryId: 'cat-222',
catalogId: 'catalog-333',
})
// Multiple prepositional phrases
await $.User.assign.Role.in.Organization.on.Team({
userId: 'user-123',
roleId: 'admin',
orgId: 'org-456',
teamId: 'team-789',
})
// Common prepositions: in, on, at, with, for, by, from, to
await $.Message.send.to.User({ messageId, userId })
await $.Report.generate.for.Team({ reportType, teamId })
await $.Payment.process.with.Method({ paymentId, methodId })
await $.Task.complete.by.Agent({ taskId, agentId })
await $.Data.import.from.Source({ dataId, sourceId })Parts of Speech Patterns
Data operations follow natural language parts of speech:
Nouns - Entities (Subjects and Objects)
// Entities are capitalized nouns
const user = await $.User.get('user-123')
const order = await $.Order.get('order-456')
const product = await $.Product.get('prod-789')
const team = await $.Team.get('team-999')Verbs - Actions and Relationships
// Verbs describe actions or relationships
await $.User.create({ name: 'John', email: '[email protected]' })
await $.Order.update({ orderId: 'order-123', status: 'shipped' })
await $.Team.add.Member({ teamId: 'team-456', userId: 'user-789' })
await $.Product.assign.Category({ productId: 'prod-999', categoryId: 'cat-111' })
// Common verbs:
// - create, read, update, delete (CRUD)
// - add, remove, assign, unassign (relationships)
// - has, contains, includes (queries)
// - send, receive, process (operations)Adjectives - Properties and Filters
// Adjectives describe properties
const activeUsers = await $.User.where.active.equals(true)
const expensiveProducts = await $.Product.where.price.greaterThan(1000)
const urgentTasks = await $.Task.where.priority.equals('urgent')
// Chained filters
const results = await $.Order.where.status.equals('pending').where.total.greaterThan(100).where.createdAt.after(yesterday)Adverbs - Query Modifiers
// Adverbs modify how queries execute
const users = await $.User.where.active.equals(true).orderBy.createdAt.desc.limit(10)
const orders = await $.Order.where.status.equals('shipped').groupBy.customer.count
const products = await $.Product.where.inStock.equals(true).sortBy.price.asc.paginate({ page: 1, perPage: 20 })GraphDL Integration
Data patterns integrate with GraphDL for graph-based queries:
import { $, graph } from 'sdk.do'
// Graph traversal
const userOrders = await graph.from($.User.get('user-123')).traverse($.User.has.Orders).traverse($.Order.contains.Items).traverse($.Item.belongs.Product)
// Multi-hop relationships
const teamProjects = await graph.from($.Team.get('team-456')).hop($.Team.has.Members).hop($.User.works.Projects).hop($.Project.has.Repositories)
// Semantic queries
const relatedUsers = await graph
.from($.User.get('user-123'))
.related($.User.works.Organization)
.related($.Organization.has.Teams)
.related($.Team.has.Members)
.unique()SDK Object Mapping
Data operations integrate with the db SDK object (1 of 8 core):
import { db, $ } from 'sdk.do'
// DB - Direct database access (db is 1 of 8 core SDK objects)
const user = await db.get('users', 'user-123')
const users = await db.list('users', { where: { active: true } })
await db.create('users', { name: 'John', email: '[email protected]' })
await db.update('users', 'user-123', { name: 'John Doe' })
await db.delete('users', 'user-123')
// $ - Semantic triple access (preferred)
const user = await $.User.get('user-123')
const users = await $.User.where.active.equals(true)
await $.User.create({ name: 'John', email: '[email protected]' })
await $.User.update({ userId: 'user-123', name: 'John Doe' })
await $.User.delete('user-123')
// Relationship queries via semantic triples
const orders = await $.User.has.Orders({ userId: 'user-123' })
const items = await $.Order.contains.Items({ orderId: 'order-456' })
const members = await $.Team.has.Members({ teamId: 'team-789' })
// $ provides semantic layer over db
// - Self-documenting code
// - Type-safe relationships
// - Natural language syntaxQuery Patterns
Common data query patterns using semantic triples:
Has Relationship (One-to-Many)
// Entity has many related entities
const userOrders = await $.User.has.Orders({ userId: 'user-123' })
const teamMembers = await $.Team.has.Members({ teamId: 'team-456' })
const projectTasks = await $.Project.has.Tasks({ projectId: 'proj-789' })Belongs To (Many-to-One)
// Entity belongs to parent entity
const orderUser = await $.Order.belongs.User({ orderId: 'order-123' })
const taskProject = await $.Task.belongs.Project({ taskId: 'task-456' })
const memberTeam = await $.Member.belongs.Team({ memberId: 'member-789' })Contains (Composition)
// Entity contains other entities
const orderItems = await $.Order.contains.Items({ orderId: 'order-123' })
const cartProducts = await $.Cart.contains.Products({ cartId: 'cart-456' })
const projectFiles = await $.Project.contains.Files({ projectId: 'proj-789' })References (Associations)
// Entity references other entities
const productCategories = await $.Product.references.Categories({ productId: 'prod-123' })
const userPreferences = await $.User.references.Preferences({ userId: 'user-456' })
const taskDependencies = await $.Task.references.Dependencies({ taskId: 'task-789' })Data Types and Validation
Semantic triples support type-safe data:
import { $, type } from 'sdk.do'
// Define entity schema
const User = type.entity('User', {
id: type.string().uuid(),
name: type.string().required(),
email: type.string().email().required(),
age: type.number().min(0).max(150),
roles: type.array(type.string()),
createdAt: type.datetime().default('now'),
metadata: type.json(),
})
// Type-safe operations
const user = await $.User.create({
name: 'John Doe',
email: '[email protected]',
age: 30,
}) // TypeScript knows the shape
// Validation errors
await $.User.create({
name: 'Jane',
email: 'invalid-email', // Error: Invalid email format
age: 200, // Error: Age must be max 150
})
// Relationships are type-safe
const orders = await $.User.has.Orders({ userId: user.id })
// TypeScript knows orders is Order[]Mutation Patterns
Data mutations using semantic triples:
Create
const user = await $.User.create({
name: 'John Doe',
email: '[email protected]',
})
const order = await $.Order.create({
userId: user.id,
items: ['item-1', 'item-2'],
total: 99.99,
})Update
await $.User.update({
userId: 'user-123',
name: 'Jane Doe',
email: '[email protected]',
})
await $.Order.update.status({
orderId: 'order-456',
status: 'shipped',
})Delete
await $.User.delete('user-123')
await $.Order.delete('order-456')
// Soft delete
await $.User.archive('user-123')
await $.Order.archive('order-456')Relationship Mutations
// Add relationships
await $.User.add.Role({ userId: 'user-123', roleId: 'admin' })
await $.Team.add.Member({ teamId: 'team-456', userId: 'user-123' })
await $.Order.add.Item({ orderId: 'order-789', itemId: 'item-999' })
// Remove relationships
await $.User.remove.Role({ userId: 'user-123', roleId: 'admin' })
await $.Team.remove.Member({ teamId: 'team-456', userId: 'user-123' })
await $.Order.remove.Item({ orderId: 'order-789', itemId: 'item-999' })
// Replace relationships
await $.User.set.Roles({ userId: 'user-123', roleIds: ['admin', 'editor'] })
await $.Team.set.Members({ teamId: 'team-456', userIds: ['user-1', 'user-2'] })Transactional Operations
Semantic triples support transactions:
import { $, transaction } from 'sdk.do'
// Transaction with semantic triples
await transaction(async (tx) => {
// Create user
const user = await tx.$.User.create({
name: 'John Doe',
email: '[email protected]',
})
// Create order
const order = await tx.$.Order.create({
userId: user.id,
total: 99.99,
})
// Add items
await tx.$.Order.add.Items({
orderId: order.id,
items: ['item-1', 'item-2'],
})
// Process payment
await tx.$.Payment.process({
orderId: order.id,
amount: order.total,
})
// All or nothing
})Real-Time Subscriptions
Subscribe to data changes using semantic triples:
import { $, on } from 'sdk.do'
// Subscribe to entity events
on($.User.created, async ({ user }) => {
console.log('New user:', user)
})
on($.Order.updated, async ({ order, changes }) => {
console.log('Order updated:', order.id, changes)
})
// Subscribe to relationship events
on($.Team.added.Member, async ({ team, member }) => {
console.log(`${member.name} joined ${team.name}`)
})
on($.Order.added.Item, async ({ order, item }) => {
console.log(`Item added to order ${order.id}`)
})
// Subscribe with filters
on($.Order.where.status.equals('shipped'), async ({ order }) => {
await sendShippingNotification(order)
})Core Capabilities
- Semantic Triples - $.Subject.predicate.Object pattern
- Prepositional Phrases - $.Subject.predicate.Object.in.Thing
- Parts of Speech - Nouns, Verbs, Adjectives, Adverbs
- GraphDL Integration - Graph traversal and queries
- Type Safety - Full TypeScript support
- Relationships - has, belongs, contains, references
- Transactions - ACID guarantees
- Real-Time - Subscribe to data changes
Access Methods
SDK
TypeScript/JavaScript library for semantic data operations
await $.User.has.Orders({ userId: 'user-123' })CLI
Command-line tool for data operations
do data query "$.User.has.Orders" --userId user-123API
REST/RPC endpoints for data access
curl -X POST https://api.do/v1/data/query -d '{"triple":"$.User.has.Orders","params":{"userId":"user-123"}}'MCP
Model Context Protocol for AI-driven data operations
Query all orders for user user-123 using semantic triple $.User.has.OrdersRelated Primitives
Parent Concept
- database - Physical data storage layer
SDK Object Mapping
- db - Database operations (SDK object - 1 of 8 core)