edgedb / edgedb-js

The official TypeScript/JS client library and query builder for EdgeDB
https://edgedb.com
Apache License 2.0
510 stars 65 forks source link

`e.json` does not handle strings with literal `$$`. #1097

Closed scotttrinh closed 2 weeks ago

scotttrinh commented 2 weeks ago

Creating a JSON literal with e.json wraps your string in $$ to handle multiline strings, as noted in the docs:

select $$one
two
three$$; # multiline raw string

Here's an example of a failing query:

    const data = [{ title: "Black Widow $$$*", genre: "Action", rating: 5 }];
    const q2 = e.for(e.json_array_unpack(e.json(data)), (j) =>
      e.insert(e.Movie, {
        title: e.cast(e.str, e.json_get(j, "title")),
        genre: e.cast(e.Genre, e.json_get(j, "genre")),
        rating: e.cast(e.int16, e.json_get(j, "rating")),
      }),
    );

Generates:

    FOR __forVar__0 IN {std::json_array_unpack(to_json($$[{"title":"Black Widow $$$*","genre":"Action","rating":5}]$$))}
    UNION (
      (INSERT default::Movie {
        title := (<std::str>std::json_get(__forVar__0, "title")),
        genre := (<default::Genre>std::json_get(__forVar__0, "genre")),
        rating := (<std::int16>std::json_get(__forVar__0, "rating"))
      })
    )

Gives you the following runtime error:

EdgeQLSyntaxError: bare $ is not allowed