Code Monkey home page Code Monkey logo

Comments (7)

rickmak avatar rickmak commented on July 24, 2024 1

I believe query.equalTo("id", "note/d5a02b77-cc7a-4f93-8cb9-4806b3762767"); should be a valid query.

Let add a logic to translate it at SDK Query. The logic will make query.equalTo("id", "note/d5a02b77-cc7a-4f93-8cb9-4806b3762767"); become save result as query.equalTo("_id", "d5a02b77-cc7a-4f93-8cb9-4806b3762767");

Any concern? @cheungpat @ben181231

from skygear-sdk-js.

ben181231 avatar ben181231 commented on July 24, 2024 1

Should we have something like query.equalToID("note/d5a02b77-cc7a-4f93-8cb9-4806b3762767") ?

from skygear-sdk-js.

cheungpat avatar cheungpat commented on July 24, 2024

You don’t need to put an emphasis on the word “confusing” to convince me that this is confusing.

The intended usage for your illustrated scenario should be this:

let query = new skygear.Query(Note);
query.equalTo('_id', '123456...');

// for update
skygear.publicDB.query(query)
.then((records) => {
  let note = records[0]; // assuming there are more than one records, ditto for below
  note['content'] = 'Hello New World';
  return skygear.publicDB.save(note);
}).then(...);

// for delete
skygear.publicDB.query(query)
.then((records) => {
  let note = records[0];
  return skygear.publicDB.delete(note);
}).then(...);

To bring feature parity among SDKs, I think JS need a function to fetch a record by ID, if such function exists:

skygear.publicDB.fetchByIds(["note/123456..."])
.then((records) => {
  // do work here
})

This way, the user does not need to know the subtlety between _id (which is a field in the record dictionary) and id (which is a property in the JavaScript object).

We also need a deleteByIds function so that the developer does not need to create an Object just to delete a Record if the RecordID is known already, as in your delete example.

If you encounter a 500 error, please open a new issue with the way you access the server (sample code), and the details of the error you got from the server.

We might also want to consider warning the user if the passed in object in delete and save function is not of the expected type, but admittedly I am not familiar with JavaScript convention in this particular scenario.

from skygear-sdk-js.

TakLee96 avatar TakLee96 commented on July 24, 2024

fetchByIds and deleteByIds sound like a good solution.

const Note = skygear.Record.extend("note");
var query = new skygear.Query(Note);
query.equalTo("id", "note/d5a02b77-cc7a-4f93-8cb9-4806b3762767");
skygear.publicDB.query(query).then(...);

This code would produce the following error message.

{
    status: 500,
    error: {
        code: 10000,
        message: "pq: column note.id does not exist",
        name: "UnexpectedError"
    }
}

I guess it is not a big problem and it is related to this current issue of id vs _id, so I'm not sure if I should create a separate issue for this. Maybe we can change it to a 400 error and provide a better error message to inform the user that he is querying with a non-existing column/attribute.

from skygear-sdk-js.

rickmak avatar rickmak commented on July 24, 2024

@ben181231 does your suggestion include reject all equal with "id" or "_id"? I doubt it will too rigid. And tempted to add another equalToOtherMeta or createBefore methods.

from skygear-sdk-js.

cheungpat avatar cheungpat commented on July 24, 2024

@rickmak is it possible to create a record field called id?

from skygear-sdk-js.

rickmak avatar rickmak commented on July 24, 2024

No. skygear-server will return following at the moment:

{
    "error": {
        "code": 107, 
        "message": "fails to decode the request payload", 
        "name": "BadRequest"
    }
}

from skygear-sdk-js.

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.