surrealpatch/docs/STORAGE.md

151 lines
3 KiB
Markdown
Raw Normal View History

2016-02-26 22:28:02 +00:00
# Storage
Surreal can be used with any key-value storage which enables range scans. This document describes how the data is stored in the storage layer, so that it can be queried and manipulated quickly and efficiently.
**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.
**Data types**
Each data type is stored using a different symbol in the key:value pair.
```bash
! # Used to store Surreal config data
2016-03-18 16:20:36 +00:00
* # Used to store item data
~ # Used to store item diffs
¤ #
« # Used to store item edges
» # Used to store item edges
• # Used to store item events
# Used to store item links
# Used to store item links
∆ # Used to store index data
2016-02-26 22:28:02 +00:00
```
---
2016-03-10 02:04:06 +00:00
### Config
2016-02-26 22:28:02 +00:00
2016-03-10 02:04:06 +00:00
**Namespace**
2016-02-26 22:28:02 +00:00
```bash
2016-06-15 14:31:57 +00:00
/{$kv}/!/n/{$ns} ""
2016-02-26 22:28:02 +00:00
# e.g.
2016-06-15 14:31:57 +00:00
/{$kv}/!/n/acme ""
2016-02-26 22:28:02 +00:00
```
2016-03-10 02:04:06 +00:00
**Database**
```bash
2016-06-15 14:31:57 +00:00
/{$kv}/!/d/{$ns}/{$db} ""
2016-03-10 02:04:06 +00:00
# e.g.
2016-06-15 14:31:57 +00:00
/{$kv}/!/d/{$ns}/test ""
2016-03-10 02:04:06 +00:00
```
2016-02-26 22:28:02 +00:00
2016-03-10 02:04:06 +00:00
**Table**
2016-02-26 22:28:02 +00:00
```bash
2016-06-15 14:31:57 +00:00
/{$kv}/!/t/{$ns}/{$db}/{$tb} ""
2016-02-26 22:28:02 +00:00
# e.g.
2016-06-15 14:31:57 +00:00
/{$kv}/!/t/{$ns}/{$db}/people ""
2016-02-26 22:28:02 +00:00
```
2016-06-15 14:31:57 +00:00
**Field**
2016-03-10 02:04:06 +00:00
```bash
2016-06-15 14:31:57 +00:00
/{$kv}/!/f/{$ns}/{$db}/{$tb}/{$fld} "{}"
2016-03-10 02:04:06 +00:00
# e.g.
2016-06-15 14:31:57 +00:00
/{$kv}/!/f/{$ns}/{$db}/{$tb}/fullname `{
"name": "fullname",
"type": "string",
"code": "",
"min": "",
"max": "",
"default": "",
"notnull": false,
"readonly": false,
"mandatory": false,
}`
2016-03-10 02:04:06 +00:00
```
2016-06-15 14:31:57 +00:00
**Field**
2016-02-26 22:28:02 +00:00
```bash
2016-06-15 14:31:57 +00:00
/{$kv}/!/i/{$ns}/{$db}/{$tb}/{$idx} "{}"
2016-03-10 02:04:06 +00:00
# e.g.
2016-06-15 14:31:57 +00:00
/{$kv}/!/i/{$ns}/{$db}/{$tb}/fullname `{
"name": "fullname",
"code": "",
"cols": ["firstname", "middlename", "lastname"],
"uniq": false,
}`
2016-02-26 22:28:02 +00:00
```
2016-03-10 02:04:06 +00:00
---
### Items
2016-02-26 22:28:02 +00:00
```bash
2016-06-15 14:31:57 +00:00
/{$kv}/{$ns}/{$db}/{$tb}/{$id} "{}"
2016-02-26 22:28:02 +00:00
# e.g
2016-03-10 02:04:06 +00:00
/{$kv}/{$ns}/{$db}/{$tb}/UUID `{"name":"Tobie","age":18}`
2016-02-26 22:28:02 +00:00
```
2016-03-10 02:04:06 +00:00
*TRAIL*
2016-02-26 22:28:02 +00:00
```bash
2016-06-15 14:31:57 +00:00
/{$kv}/{$ns}/{$db}/{$tb}/•/{$id}/{$time} "{}"
2016-02-26 22:28:02 +00:00
# e.g
2016-06-15 14:31:57 +00:00
/{$kv}/{$ns}/{$db}/{$tb}/•/UUID/2016-01-29T22:42:56.478173947Z `{}`
2016-02-26 22:28:02 +00:00
```
2016-03-10 02:04:06 +00:00
*EVENT*
2016-02-26 22:28:02 +00:00
```bash
2016-06-15 14:31:57 +00:00
/{$kv}/{$ns}/{$db}/{$tb}/‡/{$id}/{$type}/{$time} "{}"
2016-03-10 02:04:06 +00:00
# e.g
2016-06-15 14:31:57 +00:00
/{$kv}/{$ns}/{$db}/{$tb}/‡/UUID/login/2016-01-29T22:42:56.478173947Z `{}`
2016-02-26 22:28:02 +00:00
```
2016-03-10 02:04:06 +00:00
*EDGES*
2016-02-26 22:28:02 +00:00
```bash
2016-03-10 02:04:06 +00:00
/{$kv}/{$ns}/{$db}/{$tableid}/»/{$id}/{$type}/{$edgeid} ""
2016-06-15 14:31:57 +00:00
/{$kv}/{$ns}/{$db}/{$typeid}/{$id} "{}"
2016-03-10 02:04:06 +00:00
/{$kv}/{$ns}/{$db}/{$tableid}/«/{$id}/{$type}/{$edgeid} ""
2016-02-26 22:28:02 +00:00
# e.g
2016-03-10 02:04:06 +00:00
/{$kv}/{$ns}/{$db}/{$tableid}/»/1537/follow/9563 ""
/{$kv}/{$ns}/{$db}/{$typeid}/9563 `{"in":"1537","out":"5295"}`
/{$kv}/{$ns}/{$db}/{$tableid}/«/5295/follow/9563 ""
2016-02-26 22:28:02 +00:00
```
2016-06-15 14:31:57 +00:00
---
2016-02-26 22:28:02 +00:00
2016-06-15 14:31:57 +00:00
### Index
2016-02-26 22:28:02 +00:00
**Unique index**
2016-02-26 22:28:02 +00:00
```bash
2016-06-15 14:31:57 +00:00
/{$kv}/{$ns}/{$db}/{$table}/¤/{$index}/[{$columns}] "{$id}"
# e.g
2016-06-15 14:31:57 +00:00
/{$kv}/{$ns}/{$db}/{$table}/¤/{$index}/[lastname,firstname] `@person:1342`
```
2016-06-15 14:31:57 +00:00
### Point
**Non-unique index**
```bash
2016-06-15 14:31:57 +00:00
/{$kv}/{$ns}/{$db}/{$table}/¤/{$index}/[{$columns}]/{$id} "{$id}"
2016-02-26 22:28:02 +00:00
# e.g
2016-06-15 14:31:57 +00:00
/{$kv}/{$ns}/{$db}/{$table}/¤/{$index}/[lastname,firstname]/{$id} `@person:1342`
2016-02-26 22:28:02 +00:00
```