Tips and Tricks - SurrealTools/Documentation GitHub Wiki
SurrealKv is append only so what If we need to remove data for compliance (with laws such as GDPR or PIPEDA)?
There is compaction which is being implemented on the append only log, which is similar to how it works in LSM engines. The deletes are written as tombstones in the log, and periodic compaction will delete these tombstones to be compliant
Configure argon2
There isn't a way to configure argon2. Currently it is Argon2i, Version13, with a 4096 memory cost, and a 3 time cost.
Cache CORS request
https://httptoolkit.tech/blog/cache-your-cors/
Request Header Content-Types
application/json, application/cbor, and application/pack
Backup to firebase storage
A Cron job setup on firebase that calls the export http endpoint to my fly.io instance and saves it to firebase storage.
import * as https from 'node:https';
https.get(
`[httpsAddressHere]/export',
{
headers: {
Authorization: 'Basic ' + btoa(`root:[yourpassword]`),
Accept: 'application/octet-stream',
NS: namespace,
DB: database
}
},
(res: any) => {
res.setEncoding('utf8');
let data = '';
res.on('data', function (d: any) {
data += d;
});
res.on('end', () => resolve(data));
}
)
.on('error', reject);
RocksDB Memory Issue
It could be related to RocksDB compaction or max_open_files. There has also been some talk over on rocksdb that the default options are bad and can lead to OOM https://github.com/facebook/rocksdb/issues/4112 But afaik Surrealdb does currently not currently expose rocksdb options, so idk if there's an easy fix. It may help to set the environment variable MALLOC_ARENA_MAX=2 according to that thread though.
https://docs.rs/rocksdb/latest/rocksdb/struct.Options.html#method.set_max_open_files
SurQL Client
If using the command-line SQL client, then each line (technically each block) is essentially a separate context and variables only persist for that duration.
So this works:
LET $friend = (CREATE person SET name = 'Jaime'); SELECT * FROM $friend;
But this doesn't if entered as separate lines:
LET $friend = (CREATE person SET name = 'Jaime');
SELECT * FROM $friend;
Note: if you paste multiple lines in one go they will be sent in a single context.
PARALLEL Keyword
https://discord.com/channels/902568124350599239/1027200888311386282
Format Date
When a value is defined in SurrealQL (and that value matches a date or time value according to the ISO-88601 format), then the value is stored as a full datetime in the system.
So therefore 2022-05-30 and 2022-05-30T12:30:00+00:00 will already be parsed as a datetime in SurrealDB.
CREATE date SET timestamp = string::join('-','2022','10','05');
-- Or format it as a string (nightly / 1.0.0-beta.9)
CREATE date SET timestamp = time::format('2022-10-05', '%Y-%m-%d');
Client Lib URL
The url needs to be the url of the instance/endpoint with /rpc at the end. So http://surrealdb.fly.dev/rpc You don't need to use ws:// at the moment as the JavaScript/Deno library converts http to ws automatically.
Reference Element
For CREATE you'd use * to reference the element. However, for SELECT you have to use the index or $ for last element.
BEGIN TRANSACTION;
LET $project = (create project);
CREATE account SET project = $project[*].id; // creates the account.project with the id of the project just created.
COMMIT TRANSACTION;
BEGIN TRANSACTION;
LET $projectList = (select * from project);
CREATE account SET project = $projectList[$].id; // creates the account.project with last project id in the select list.
COMMIT TRANSACTION;
Static content server into the standalone SurrealDB
Add the following code to src/net/mod.rs
use warp::Filter;
#[allow(opaque_hidden_inferred_bound)]
pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
warp::path("static").and(warp::get()).and(warp::fs::dir("static"))
}
Check whether a record is from a specific table
meta::tb($value) == 'table_name'
Q. Does SurrealDB REST API work over HTTP2?
A. Yes, it does. Note that it likely requires you to use the --web-crt and --web-key command line options (or an equivalent configuration for your web-facing load balancer/reverse proxy) to set a TLS certificate, as TLS ALPN is used to negotiate HTTP/2.