surrealdb

SurrealDB - How to use Record ID as LET defined variable


I want to give the record id as a LET defined variable like this:

LET $item_id = 1;

SELECT ->Contain->Ingredient as ingredients FROM Product:$barcode;

But it doesn't work.

I also tried where clause but it didn't work either:

SELECT ->Contain->Ingredient as ingredients FROM Product WHERE Product.id = $barcode

How to use table:id format with LET defined variables?


Solution

  • I found this:

    LET $id = 1;
    LET $product_thing = type::thing("Product", $id);
    

    Then I used it like this:

    // Get ingredients of a product:
    SELECT ->Contain->Ingredient as ingredients FROM $product_thing;