surrealpatch/doc/STORAGE.md

94 lines
2.9 KiB
Markdown
Raw Normal View History

2016-02-26 22:28:02 +00:00
# Storage
2017-02-10 12:55:45 +00:00
This document describes how the database data is stored in the key-value storage layer;
2016-02-26 22:28:02 +00:00
**Base keys**
```bash
2016-03-10 02:04:06 +00:00
{$kv} = "surreal" # This is the base key
2016-02-26 22:28:02 +00:00
```
The base key is used to separate the data used in SurrealDB from data used by other databases using the same key:value store.
```bash
2016-03-10 02:04:06 +00:00
{$ns} = "acme" # This is the name of the namespace
2016-02-26 22:28:02 +00:00
```
2016-03-10 02:04:06 +00:00
The namespace key is used to enable separation of data and multi-tenancy of databases on SurrealDB.
2016-02-26 22:28:02 +00:00
```bash
2016-03-10 02:04:06 +00:00
{$db} = "test" # This is the name of the database
2016-02-26 22:28:02 +00:00
```
The database key is used to separate data into multiple different databases under each multi-tenant installation.
2017-02-10 12:55:45 +00:00
#### Chars
2016-02-26 22:28:02 +00:00
2017-02-10 12:55:45 +00:00
Each data type is stored using a different symbol in the key-value pair.
2016-02-26 22:28:02 +00:00
```bash
2017-02-10 12:55:45 +00:00
! # Used to store config data
2016-03-18 16:20:36 +00:00
* # Used to store item data
~ # Used to store item diffs
2017-02-10 12:55:45 +00:00
• # Used to store item trail
2016-03-18 16:20:36 +00:00
« # Used to store item edges
» # Used to store item edges
2017-02-10 12:55:45 +00:00
¤ # Used to store index data
2016-02-26 22:28:02 +00:00
```
2017-02-10 12:55:45 +00:00
#### Keys
2016-02-26 22:28:02 +00:00
2017-02-10 12:55:45 +00:00
The keys for the data in the key-value store use the template below.
2016-02-26 22:28:02 +00:00
```bash
2017-02-10 12:55:45 +00:00
KV /{$kv}
NS /{$kv}/{$ns}
NT /{$kv}/{$ns}/!/t/{$tk}
NU /{$kv}/{$ns}/!/u/{$us}
DB /{$kv}/{$ns}/*/{$db}
LV /{$kv}/{$ns}/*/{$db}/!/l/{$lv}
SC /{$kv}/{$ns}/*/{$db}/!/s/{$sc}
ST /{$kv}/{$ns}/*/{$db}/!/s/{$sc}/!/t/{$tk}
DT /{$kv}/{$ns}/*/{$db}/!/t/{$tk}
DU /{$kv}/{$ns}/*/{$db}/!/u/{$us}
VW /{$kv}/{$ns}/*/{$db}/!/v/{$vw}
TB /{$kv}/{$ns}/*/{$db}/*/{$tb}
EV /{$kv}/{$ns}/*/{$db}/*/{$tb}/!/e/{$ev}
FD /{$kv}/{$ns}/*/{$db}/*/{$tb}/!/f/{$fd}
IX /{$kv}/{$ns}/*/{$db}/*/{$tb}/!/i/{$ix}
Table /{$kv}/{$ns}/*/{$db}/*/{$tb}/*
Thing /{$kv}/{$ns}/*/{$db}/*/{$tb}/*/{$id}
Field /{$kv}/{$ns}/*/{$db}/*/{$tb}/*/{$id}/*/{$fd}
Edge /{$kv}/{$ns}/*/{$db}/*/{$tb}/*/{$id}/»/{$tp}/{$ft}/{$fk}
Patch /{$kv}/{$ns}/*/{$db}/*/{$tb}/~/{$id}/{$at}
Index /{$kv}/{$ns}/*/{$db}/*/{$tb}/¤/{$ix}/{$fd}
Point /{$kv}/{$ns}/*/{$db}/*/{$tb}/¤/{$ix}/{$fd}/{$id}
2016-02-26 22:28:02 +00:00
```
2017-02-10 12:55:45 +00:00
The specific keys listed above are displayed with example data below.
2016-02-26 22:28:02 +00:00
```bash
2017-02-10 12:55:45 +00:00
KV /surreal
NS /surreal/abcum
NT /surreal/abcum/!/t/default
NU /surreal/abcum/!/u/tobie@abcum.com
DB /surreal/abcum/*/acreon
LV /surreal/abcum/*/acreon/!/l/name
SC /surreal/abcum/*/acreon/!/s/admin
ST /surreal/abcum/*/acreon/!/s/admin/!/t/default
DT /surreal/abcum/*/acreon/!/t/default
DU /surreal/abcum/*/acreon/!/u/tobie@abcum.com
VW /surreal/abcum/*/acreon/!/v/ages
TB /surreal/abcum/*/acreon/*/person
EV /surreal/abcum/*/acreon/*/person/!/e/activity
FD /surreal/abcum/*/acreon/*/person/!/f/name.first
IX /surreal/abcum/*/acreon/*/person/!/i/names
Table /surreal/abcum/*/acreon/*/person/*
Thing /surreal/abcum/*/acreon/*/person/*/tobie
Field /surreal/abcum/*/acreon/*/person/*/tobie/*/name.first
Edge /surreal/abcum/*/acreon/*/person/*/tobie/»/like/entity/apple
Patch /surreal/abcum/*/acreon/*/person/~/tobie/2016-01-29T22:42:56.478173947Z
Index /surreal/abcum/*/acreon/*/person/¤/names/[col1,col2,col3]
Point /surreal/abcum/*/acreon/*/person/¤/names/[col1,col2,col3]/tobie
2016-02-26 22:28:02 +00:00
```