Giter VIP home page Giter VIP logo

Comments (2)

tywalch avatar tywalch commented on September 28, 2024

Hi @raryanpur 👋

Thanks for submitting this! Ultimately the reason this validation exists on the attribute name (as opposed to the field) is because the attribute name is what's used when performing a collection query. The validation prevents ambiguity around which attributes must be provided to perform the query, and keeps the api simple. For example, if the entities you included were not validated this way, which query would be correct?

service.collections.patrons({ restaurantId: 'wendys' }).go();  
service.collections.patrons({ id: 'wendys' }).go();  
service.collections.patrons({ id: 'wendys', restaurantId: 'wendys' }).go();  

Going a step further, if the "customer" entity was defined with an id field as well (which I think would be likely with this pattern, then id it gains additional ambiguity:

{
    model: {
        entity: "customer",
        service: "app",
        version: "1"
    },
    attributes: {
        id: {
            type: "string"
        },
        restaurantId: {
            type: "string"
        },
        name: {
            type: "string"
        }
    },
    indexes: {
        record: {
            collection: "patrons"
            pk: {
                field: "pk",
                composite: ["restaurantId"],
            },
            sk: {
                field: "sk",
                composite: ["id"],
            },
        }
    }
}

These are just a few examples to illustrate why the library optimizes a bit more for simplicity here. The typing system also benefits from this approach, which is a top priority for the library. Definitely share any thoughts you have about the above however, the more brains on this topic the better because it has come up before!

from electrodb.

raryanpur avatar raryanpur commented on September 28, 2024

Thanks for the info! Need some time to digest but makes sense on first pass 👍🏼

from electrodb.

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.