DEFINE BUCKET statement
Note
The DEFINE BUCKET statement lets you create a bucket that can hold files.
Statement syntax
Example usage
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.
Memory backend
The simplest way to experiment with a bucket for files is by using the memory backend:
Once this is defined, my_bucket can be accessed by using a file pointer: a path prefixed by an f.
File backend
A file backend can be chosen for a bucket by typing "file:" and then the rest of the path, if necessary.
A check will then be made to see if the SURREAL_BUCKET_FOLDER_ALLOWLIST environment variable contains the path, without which the following error will be generated.
The following command can be used to start running an instance in which a bucket with a file backend can be defined.
Global backend
A global backend can also be selected, allowing all namespaces and databases access to the same file storage.
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.
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.
Setting permissions on buckets
By default, the permissions on a bucket will be set to FULL unless otherwise specified.
You can set permissions on buckets to control who can perform operations on the files stored in them using the PERMISSIONS clause. In the clause three additional variables are available:
$action: The action to be executed (put,get,head,delete,copy,rename,exists,list)$file: The file pointer of the file to be accessed$target: The target file pointer in copy/rename operations