DEV Community

Romans Malinovskis
Romans Malinovskis

Posted on

SurrealDB test case for SaaS

I have added a test database for SurrealDB, that looks at the scenario of a SaaS product. It's important to apply the core limitation where an authenticated user can only see records, belonging to that user. An developer-error (or even vibe-coder error) in Graph database can leak data and one of the requirements for vantage is the ability to enforce fundamental entity conditions.

If I want to query "client->placed->order" relation, I need both order and client to belong to my bakery:

SELECT
    name AS product_name,
    inventory.stock AS current_inventory,
    array::first((SELECT count() FROM order WHERE bakery = bakery:hill_valley GROUP ALL)).count AS total_orders
FROM product
WHERE bakery = bakery:hill_valley AND is_deleted = false;
Enter fullscreen mode Exit fullscreen mode

In my latest PR to I have established a use-case that is designed specifically with "production" scenario like this:

https://github.com/romaninsh/vantage/pull/63

The model already existed for PostgreSQL, but next I'm going to extend support into SurrealDB query builder.

Top comments (0)