Skip to content

Documentation: 8 things I struggled with while learning surrealQL #559

@lveillard

Description

@lveillard

Description

THings that are missing, aha moments or concepts without proper examples:

    • FROM can be from multiple tables FROM a,b,c
    • Aha moment: There is no array::map function but we can do SELECT VALUE {function} (array)
    • The difference between default and value when defining a field
    • <future> can be used as well in FIELD VALUE to generate onRead computed values. In the doc appears to work only on CREATE queries
    • FROM can be used with edges relative to the $parent, like this: SELECT *, (SELECT * FROM ->installed->property) FROM tableName
    • How to filter by id in a FROM when it has the edge structure as the point 5) here 👆 . This for instance does not work SELECT *, (SELECT * FROM (->installed->property):recordId) FROM tableName while this does SELECT *, (SELECT * FROM tableName2:recordId) FROM tableName
    • While virtual fields can be done with FIELD VALUE , I cant find any place to do virtual edges (infered edges computed onRead)
  1. Polymorphism:

I think it deserves a full page, is polymorphism. For instance edges can point to multiple tables:

DEFINE TABLE SpaceObj_space TYPE RELATION IN SpaceObj|SpaceDef|Kind|Self OUT Space SCHEMAFULL PERMISSIONS FULL;

Also we can fetch polymorphic edges with this structure:

  SELECT
      meta::id(id) as `$id`,
      (
        SELECT
          meta::id(id) as `$id`,
        FROM <-`SpaceObj_space`<-(`SpaceObj`,`Kind`,`Self`)   --This is the interesting part
      ) AS `objects`,
      meta::id(id) AS id
    FROM Space:`space-2`

And a last thing around polymorphism not explained that Im not even sure is doable. This works

FROM <-`SpaceObj_space`<-(`SpaceObj`,`Kind`,`Self`)

But afaik there is no equivalent shortcut for tables:

`FROM (User, SuperUser):user7 --throws error

and requires doing the combinations:

`FROM User:user7, SuperUser:user7

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions