Giter Site home page Giter Site logo

Comments (4)

SquareMesh avatar SquareMesh commented on May 10, 2024 1

Correct. LookupCodes.find() has returned a class object (representing our model) but when calling the Update() method of our model object we could instead get an object representing outcome i.e. rowsAffected.

Code wise I would approach use as follows :

const code = await LookupCodes.find(1);
const {rowsAffected} = await code.update({ code: 'xxx' });
if (rowsAffected===1) { ....}

The above reflect one change, but related to this is minor issue (and this might be a non-issue and considered working as intended) relating to the return value when directly using class methods for update(), delete()

LookupCodes.where("id", 1).update({code_id: "X"})
LookupCodes.where("id", 1).delete();

These do return rowsAffected but they do so as a class object
LookupCodes { affectedRows: 1, lastInsertId: 0 }

Ideally it would be good if results were return as object { affectedRows: 1, lastInsertId: 0 }
allowing use case

const {rowsAffected} = await LookupCodes.where("id", 1).update({code_id: "X"})

Prior to finding "denodb" I was using "mysql" directly and using its return values in this way.

At the moment when class methods directly I require the following ..

const updateResult = await LookupCodeModel.editLookupCode(id,data);
const affectedRows = updateResult["affectedRows"]
if (rowsAffected===1) { ....}

Part of this was my own learning when understanding the return value. It's workable but little more involved. I guess also that return value of class object LookupCode when using this methods directly is misaligned as they don't represent structure of the model.

Hope this makes sense. Happy to clarify further if needed.

edit: wording

from denodb.

eveningkid avatar eveningkid commented on May 10, 2024

Hey,

Thanks for raising this question, it's interesting.

So let me quickly explain my first way of thinking. Initially, I expected this:

const code = await LookupCodes.find(1);
const updatedCode = await code.update({ code: 'xxx' });

But, from what I understand, you would need the following:

const resultsFromUpdate = await code.update({ code: 'xxx' });
// resultsFromUpdate would then have "rowAffected" etc.

I think your approach is better and more in sync with classes behaviour i.e. Model.update, Model.delete which won't return the model itself but the results from the query.

Just to make sure, you wish to use things the way I wrote it with resultsFromUpdate right?

from denodb.

eveningkid avatar eveningkid commented on May 10, 2024

Thanks for confirming, I hope this little change will make things easier for you!

It should now be working with #59. Just remember to reload, deno run --reload ... and you should be good to go.

If not, just reopen the issue okay?

See you around :)

from denodb.

SquareMesh avatar SquareMesh commented on May 10, 2024

Hi @eveningkid ,

Thanks again for this change. The fix provides a better result. One follow up question is whether it should return Model Class object type or just plain object type. This is minor really.

Currently value is returned as LookupCodes { affectedRows: 1, lastInsertId: 0 }

Which makes it seem likes it a class object of LookupCodes but it's not really. Do you think it's possible or worthwhile to return as base object so data elements can be referenced directly.

const {rowsAffected} = await resultFind.delete();

PS. I can't re-open, not that I wanted to before asking question. Let me know if you want a new issue if you want to track change - if worthwhile doing.

from denodb.

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.