Giter Club home page Giter Club logo

Comments (4)

nathanschwarz avatar nathanschwarz commented on June 8, 2024

I think this is proper behavior of the parser, since you defined a specific sub property of the flexible object in the schema it should at least contains a test property.
Using CREATE test SET obj = { test: "hello world" }; or CREATE test SET obj = { test: "hello world", a: "don't mind me", b: 10 }; should work.
You could make the test property optional using option<string> for what you want to achieve (thus enforcing a specific type for this specific property), but that is currently failing too (which in this case is a bug).

also not that your schema is incorrect it should be DEFINE FIELD and not DEFINE FILED

from surrealdb.

jquesada2016 avatar jquesada2016 commented on June 8, 2024

I believe whenever there's a * in the path, it should be optional, as it currently is for sub-array types. You can't assume if they key will be present or not.

In the case of * for objects, I don't think it would make sense to restrict objects to require at least 1 key to be present, you can use ASSERT if you need this. It really should be optional, so empty objects should be allowed.

from surrealdb.

jquesada2016 avatar jquesada2016 commented on June 8, 2024

I suppose to emphasize my last point, if you currently write

DEFINE FIELD test.* ON TABLE test TYPE string;

If you run INFO FOR TABLE test, you'll notice that it rewrote the field definition to:

DEFINE FIELD test[*] ...

insinuating that whildcard parts of a type path really should be optional as they are for arrays.

from surrealdb.

nathanschwarz avatar nathanschwarz commented on June 8, 2024

In my eyes it makes more sense to rely on the subfield definition using the option keyword :

  • it's more readable
  • it's more practical for the parser implementation (avoiding the need to go back to the parent definition when parsing objects recursively)

Furthermore :

  • the ASSERT keyword is supposed to check logical constraints not types constraints (that's why we have SCHEMAFULL definitions)
  • the FLEXIBLE keyword is only there to allow extra values not specified in a SCHEMAFULL context, as per the documentation says :

Flexible types allow you to have SCHEMALESS functionality on a SCHEMAFULL table. This is necessary for working with nested object types, which by nature do not have defined fields.

from surrealdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.