surrealdb / docs.surrealdb.com

The documentation for SurrealDB, powered by Docusaurus
https://surrealdb.com/docs/
70 stars 112 forks source link

Documentation: Invalid example query for Surreal Deal Store demo data #679

Open Xkonti opened 1 month ago

Xkonti commented 1 month ago

Description

The query 2 from the examples (in the embedded Surrealist instance) for the Surreal Deal Store demo data looks like this:

-- Query 2: Using graph relations to select from the person and product table
SELECT
    order_date,
    product_name,
    <-person.name as person_name,
    ->product.description
FROM order LIMIT 4;

which returns:

[
    {
        "->product": {
            description: [
                NONE
            ]
        },
        order_date: NONE,
        person_name: [
            'Stephan Knight'
        ],
        product_name: "Men's Speeder Hoodie"
    },
    ...
]

Problems:

Proposed fix:

SELECT
  time.created_at,
  product_name,
  (<-person.name)[0] as person_name,
  (->product.name)[0] as product_name
FROM order LIMIT 4;

The relation queries are also wrapped in parenthesis with [0] at the end to extract the first (and only) element to reduce unnecessary array wrappers. This produces:

[
    {
        person_name: 'Stephan Knight',
        product_name: "Men's Speeder Hoodie",
        time: {
            created_at: '2022-11-08T12:32:21Z'
        }
    },
    ...
]

⚠️ There might be more problematic query examples there, but I didn't have time to check it.

Is there an existing issue for this?

Code of Conduct