Skip to content

Commit 3175bcb

Browse files
committed
Add section on file storage
1 parent 185f011 commit 3175bcb

File tree

1 file changed

+36
-2
lines changed
  • src/content/doc-surrealql/statements/define

1 file changed

+36
-2
lines changed

src/content/doc-surrealql/statements/define/bucket.mdx

+36-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ PERMISSIONS @expression [ COMMENT @string ]
2222

2323
## Example usage
2424

25+
A bucket backend can be set as "memory" for non-persistent in-memory storage, or as "file:/", followed by the path, for storage on disk.
26+
27+
### Memory backend
28+
2529
The simplest way to experiment with a bucket for files is by using the memory backend:
2630

2731
```surql
@@ -51,13 +55,43 @@ encoding::base64::decode("T25jZSB0aGVyZSB3ZXJlIGZvdXIgY2hpbGRyZW4gd2hvc2UgbmFtZX
5155
'Once there were four children whose names were Peter, Susan, Edmund, and Lucy.'
5256
```
5357

54-
If no backend is selected, the database will search for the environment variable `SURREAL_GLOBAL_BUCKET` and assign this as the global bucket. In this case, files will have a `namespace/database` prefix added (e.g. `my_global_bucket:/test_ns/test_db/somefile.txt`). A second `SURREAL_GLOBAL_BUCKET_ENFORCED` environment variable can also be used, which when set to `true` will enforce usage of the global bucket.
58+
### File backend
59+
60+
A file backend can be chosen for a bucket by typing `"file:"` and then the rest of the path, if necessary.
5561

5662
```surql
57-
DEFINE BUCKET my_bucket;
63+
DEFINE BUCKET my_bucket BACKEND "file:/some_directory";
64+
DEFINE BUCKET my_bucket BACKEND "file:/some_directory";
65+
```
66+
67+
A check will then be made to see if the `SURREAL_FILE_ALLOWLIST` environment variable contains the path, without which the following error will be generated.
68+
69+
```surql
70+
'Bucket backend not supported: Path not allowed'
71+
```
72+
73+
The following command can be used to start running an instance in which a bucket with a file backend can be defined.
74+
75+
```bash
76+
# Unix
77+
SURREAL_FILE_ALLOWLIST="/" surreal start --user root --pass root --allow-experimental files
78+
79+
# Windows (PowerShell)
80+
$env:SURREAL_FILE_ALLOWLIST = "/"
81+
surreal start --user root --pass root --allow-experimental files
5882
```
5983

84+
### Global backend
85+
86+
A global backend can also be selected, allowing all namespaces and databases access to the same file storage.
87+
88+
If no backend is selected, the database will search for the environment variable `SURREAL_GLOBAL_BUCKET` and assign this as the global bucket. In this case, files will have a `namespace/database` prefix added (e.g. `my_global_bucket:/test_ns/test_db/somefile.txt`). A second `SURREAL_GLOBAL_BUCKET_ENFORCED` environment variable can also be used, which when set to `true` will enforce usage of the global bucket.
89+
90+
If a global backend is set, then a `DEFINE BUCKET` statement can be as short as `DEFINE BUCKET` plus its local name, as the rest of the logic is done via environment variables.
91+
6092
```surql
93+
DEFINE BUCKET my_bucket;
94+
6195
-- Writes to e.g. `my_global_bucket:/test_ns/test_db/my_bucket/my_book.txt`
6296
f"my_bucket:/my_book.txt".put("Once there were four children whose names were Peter, Susan, Edmund, and Lucy.");
6397
```

0 commit comments

Comments
 (0)