Skip to content

Commit be53fa9

Browse files
committed
Add information about GRAPH_SPEC and DB_SPEC
1 parent 149a9ef commit be53fa9

File tree

2 files changed

+304
-0
lines changed

2 files changed

+304
-0
lines changed
Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
---
2+
title: Database Path Identifiers Reference
3+
nextjs:
4+
metadata:
5+
title: Database Path Identifiers - GRAPH_SPEC and DB_SPEC Reference
6+
description: Reference guide for GRAPH_SPEC, DB_SPEC, and path identifiers used in TerminusDB CLI, REST API, and client libraries to address databases, branches, commits, and graphs
7+
openGraph:
8+
images: https://assets.terminusdb.com/docs/technical-documentation-terminuscms-og.png
9+
alternates:
10+
canonical: https://terminusdb.org/docs/graph_spec-db_spec-database-path-identifiers/
11+
media: []
12+
---
13+
14+
Understanding how to address specific databases, branches, commits, and graphs is fundamental to working with TerminusDB. Whether you're using the CLI, REST API, or client libraries, you'll encounter **DB_SPEC** and **GRAPH_SPEC** identifiers. This reference guide explains these identifiers in plain language with practical examples.
15+
16+
## What is a DB_SPEC?
17+
18+
A **DB_SPEC** (Database Specification) is a path-based identifier that precisely locates a database, branch, or commit within TerminusDB. Think of it as an address that tells TerminusDB exactly which version of which database you want to access.
19+
20+
### Basic DB_SPEC Structure
21+
22+
The general format follows this pattern:
23+
24+
```
25+
<organization>/<database>/<repository>/<ref_type>/<ref_name>
26+
```
27+
28+
### DB_SPEC Components Explained
29+
30+
1. **Organization** - Your team or organization (e.g., `admin`, `my_team`)
31+
2. **Database** - The name of your data product or database
32+
3. **Repository** - Usually `local` (or a remote name if configured)
33+
4. **Reference Type** - Either `branch` or `commit`
34+
5. **Reference Name** - The branch name (e.g., `main`) or commit ID
35+
36+
### Common DB_SPEC Patterns
37+
38+
Here are the most frequently used DB_SPEC formats, and special ones:
39+
40+
#### Simple Database Reference (Default Branch)
41+
```
42+
<organization>/<database>
43+
```
44+
**Example:** `admin/my_database`
45+
46+
This is shorthand for `admin/my_database/local/branch/main` - it automatically points to the main branch of the local repository.
47+
48+
#### Specific Branch
49+
```
50+
<organization>/<database>/local/branch/<branch_name>
51+
```
52+
**Examples:**
53+
- `admin/employees/local/branch/main`
54+
- `my_team/products/local/branch/development`
55+
- `admin/customers/local/branch/feature-updates`
56+
57+
#### Specific Commit
58+
```
59+
<organization>/<database>/local/commit/<commit_id>
60+
```
61+
**Example:** `admin/employees/local/commit/9w8hk3y6rb8tjdy961ed3i536ntkqd8`
62+
63+
Use this for time-travel queries or to reference a specific point in history.
64+
65+
#### Repository Metadata
66+
```
67+
<organization>/<database>/_meta
68+
```
69+
**Example:** `admin/employees/_meta`
70+
71+
Access the repository graph containing information about the local repository and all known remotes.
72+
73+
#### Commit Graph
74+
```
75+
<organization>/<database>/<repository>/_commits
76+
```
77+
**Example:** `admin/employees/local/_commits`
78+
79+
Access the commit graph containing branch histories, commit objects, authorship, and timestamps.
80+
81+
#### Remote Repository
82+
```
83+
<organization>/<database>/<remote_name>/branch/<branch_name>
84+
```
85+
**Example:** `admin/employees/origin/branch/main`
86+
87+
Reference a branch on a configured remote repository.
88+
89+
#### System Database
90+
```
91+
_system
92+
```
93+
Access the system metadata containing user information, organization data, and database records (requires system administrator permissions).
94+
95+
## What is a GRAPH_SPEC?
96+
97+
A **GRAPH_SPEC** (Graph Specification) extends a DB_SPEC to point to a specific graph within a database. TerminusDB stores data in multiple graphs - primarily **instance** data and **schema** definitions.
98+
99+
### GRAPH_SPEC Structure
100+
101+
```
102+
<DB_SPEC>/<graph_type>
103+
```
104+
105+
Where `<graph_type>` is one of:
106+
- `instance` - Your actual data documents
107+
- `schema` - Your data model and type definitions
108+
109+
### GRAPH_SPEC Examples
110+
111+
#### Access Schema Graph
112+
```
113+
admin/employees/local/branch/main/schema
114+
```
115+
Read or modify the schema (data model) for the employees database.
116+
117+
#### Access Instance Graph
118+
```
119+
admin/employees/local/branch/main/instance
120+
```
121+
Query or update the actual data documents in the employees database.
122+
123+
#### Schema on Specific Commit
124+
```
125+
admin/products/local/commit/abc123def456/schema
126+
```
127+
View the schema as it existed at a specific commit.
128+
129+
## Practical Usage Examples
130+
131+
### CLI Usage
132+
133+
#### Query a Database
134+
```bash
135+
terminusdb query admin/my_database "select([X], t(X, rdf:type, Y))"
136+
```
137+
138+
#### Optimize a Specific Branch
139+
```bash
140+
terminusdb optimize admin/employees/local/branch/main
141+
```
142+
143+
#### Dump Triples from Schema
144+
```bash
145+
terminusdb triples dump admin/people/local/branch/main/schema
146+
```
147+
148+
#### Load Triples into Instance Graph
149+
```bash
150+
terminusdb triples load admin/people/local/branch/development/instance data.ttl
151+
```
152+
153+
### REST API Usage
154+
155+
In REST API endpoints, the DB_SPEC appears directly in the URL path structure:
156+
157+
#### Insert Document
158+
```bash
159+
POST http://localhost:6363/api/document/admin/PeopleReferenceData/local/branch/main
160+
```
161+
162+
The path structure breaks down as:
163+
- `admin` - organization
164+
- `PeopleReferenceData` - database
165+
- `local` - repository
166+
- `branch/main` - branch reference
167+
168+
#### Query Schema Graph
169+
```bash
170+
GET http://localhost:6363/api/document/admin/employees/local/branch/main?graph_type=schema
171+
```
172+
173+
### Client Library Usage
174+
175+
#### JavaScript Client
176+
```javascript
177+
const client = new TerminusClient.Client('http://localhost:6363', {
178+
organization: 'admin',
179+
db: 'employees',
180+
branch: 'main' // Optional, defaults to 'main'
181+
});
182+
183+
// The client constructs DB_SPEC internally as: admin/employees/local/branch/main
184+
```
185+
186+
#### Python Client
187+
```python
188+
client = Client("http://localhost:6363")
189+
client.connect(team="admin", db="employees", branch="main")
190+
191+
# The client uses: admin/employees/local/branch/main
192+
```
193+
194+
## Special Cases and Edge Scenarios
195+
196+
### Default Values
197+
198+
When components are omitted, TerminusDB applies these defaults:
199+
200+
- **No repository specified:** Defaults to `local`
201+
- **No branch specified:** Defaults to `branch/main`
202+
- **No graph_type specified:** Typically defaults to `instance` (context-dependent)
203+
204+
### Examples with Defaults
205+
206+
```
207+
admin/mydb
208+
↓ Expands to ↓
209+
admin/mydb/local/branch/main
210+
```
211+
212+
### Working with Remotes
213+
214+
After adding a remote:
215+
216+
```bash
217+
terminusdb remote add admin/mydb origin https://cloud.terminusdb.com/myorg/mydb
218+
```
219+
220+
You can reference the remote:
221+
222+
```bash
223+
terminusdb pull admin/mydb/origin/branch/main
224+
```
225+
226+
## Common Patterns and Use Cases
227+
228+
### Time Travel Queries
229+
230+
Access historical data by referencing a specific commit:
231+
232+
```bash
233+
terminusdb query admin/sales/local/commit/abc123 "select([X], t(X, rdf:type, Y))"
234+
```
235+
236+
### Multi-Branch Development
237+
238+
Work with feature branches:
239+
240+
```bash
241+
# Create feature branch
242+
terminusdb branch create admin/products/local/branch/feature-new-fields
243+
244+
# Query feature branch
245+
terminusdb query admin/products/local/branch/feature-new-fields "select([X], t(X, rdf:type, Y))"
246+
247+
# Push to remote
248+
terminusdb push admin/products/local/branch/feature-new-fields
249+
```
250+
251+
### Schema Evolution
252+
253+
View schema changes across commits:
254+
255+
```bash
256+
# Current schema
257+
terminusdb triples dump admin/inventory/local/branch/main/schema
258+
259+
# Schema at previous commit
260+
terminusdb triples dump admin/inventory/local/commit/previous123/schema
261+
```
262+
263+
## Use _system Carefully
264+
The `_system` database contains critical metadata:
265+
```bash
266+
# ⚠️ Be extremely careful with write operations
267+
terminusdb query _system "..."
268+
```
269+
270+
## Quick Reference Table
271+
272+
| Format | Example | Use Case |
273+
|--------|---------|----------|
274+
| `_system` | `_system` | Access system metadata |
275+
| `<org>/<db>` | `admin/employees` | Quick access to main branch |
276+
| `<org>/<db>/local/branch/<branch>` | `admin/emp/local/branch/dev` | Specific branch |
277+
| `<org>/<db>/local/commit/<hash>` | `admin/emp/local/commit/abc123` | Specific commit (time travel) |
278+
| `<org>/<db>/_meta` | `admin/employees/_meta` | Repository metadata |
279+
| `<org>/<db>/local/_commits` | `admin/emp/local/_commits` | Commit history graph |
280+
| `<DB_SPEC>/schema` | `admin/emp/local/branch/main/schema` | Schema graph |
281+
| `<DB_SPEC>/instance` | `admin/emp/local/branch/main/instance` | Instance data graph |
282+
283+
## Related Documentation
284+
285+
- [CLI Commands Reference](/docs/terminusdb-cli-commands/) - Complete CLI command documentation
286+
- [CLI Query Interface](/docs/terminusdb-db-cli-querying/) - WOQL syntax for CLI
287+
- [HTTP Documents API](/docs/http-documents-api/) - REST API examples with path identifiers
288+
- [JavaScript Client](/docs/javascript/) - Client library documentation
289+
- [Python Client](/docs/python/) - Python client documentation
290+
291+
## Getting Help
292+
293+
If you're struggling to construct the right DB_SPEC or GRAPH_SPEC:
294+
295+
1. **List your databases:** `terminusdb db list`
296+
2. **Check branches:** `terminusdb db list <org>/<db> --branches`
297+
3. **View commit history:** `terminusdb log <org>/<db>`
298+
4. **Test with simple queries:** Start with `_system` to verify syntax
299+
300+
For community support, visit the [TerminusDB Discord](https://discord.gg/terminusdb) or [GitHub Discussions](https://github.com/terminusdb/terminusdb/discussions).

src/lib/navigation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,10 @@ export const navigation: Navigation[] = [
636636
title: 'Python Client Reference',
637637
href: '/docs/python',
638638
},
639+
{
640+
title: 'Database Path Identifiers',
641+
href: '/docs/graph_spec-db_spec-database-path-identifiers',
642+
},
639643
{
640644
title: 'TerminusDB CLI Reference',
641645
href: '/docs/terminusdb-cli-commands',

0 commit comments

Comments
 (0)