Giter Site home page Giter Site logo

Comments (6)

vmihailenco avatar vmihailenco commented on August 18, 2024 3

I'm curious, what do you mean?

You could try to implement insert-or-update/cache/validation using BeforeInsert/AfterInsert model hook. Assuming that hooks are powerful enough.

from bun.

vmihailenco avatar vmihailenco commented on August 18, 2024 1

Such feature requires you to structure API in a certain way. Specifically, you need to add Player.Games field and make sure to populate it properly (accept data in a certain way). That is the additional code you need to write in order to use cascading inserts.

But eventually you will want to customize the insert logic, for example, use insert-or-update. Or cache. Or add some validation. Bun can't support any of that.

So you will throw away cascading inserts and all the efforts you've made to support them. And replace it with 20-30 lines of code that just calls a couple of inserts. The last thing to do is to write a blog post / comment saying "ORMs are evil".

PS Another popular alternative is to fix the problem with hooks. I guess we will discuss that in hooks-related thread :)

from bun.

GamerGirlandCo avatar GamerGirlandCo commented on August 18, 2024 1

You could try to implement insert-or-update/cache/validation using BeforeInsert/AfterInsert model hook. Assuming that hooks are powerful enough.

How would you access the bun.DB instance from within a hook function to create a new query though?

from bun.

vmihailenco avatar vmihailenco commented on August 18, 2024

No, that is not supported. I will accept a PR that contributes something like that, but I personally don't find such feature useful so don't expect it from me :)

from bun.

frederikhors avatar frederikhors commented on August 18, 2024

I will accept a PR that contributes something like that

I wish I was able to do it!

I understand that you see this problem with this perspective, this is not a criticism.

I just want you to understand how maybe another person (me) sees it.

The convenience of writing a model composed of has-many or has-one and being able to save and update it automatically is priceless to me!

Something like:

type Player struct {
  Name string

  Games []Game
}

type Game struct {
  World string
  Score int
}

with this command

_, err := db.NewInsert().Model(player).Exec(ctx)

which generates one SQL statement both for Player and all it's Games. The same for UPDATE and DELETE.

This convenience is invaluable (especially if there are many tables related).

But I understand that it is not in your priorities and I RESPECT your opinion!

Maybe someone will help us sooner or later!

Thank you!

from bun.

frederikhors avatar frederikhors commented on August 18, 2024

So you will throw away cascading inserts and all the efforts you've made to support them. And replace it with 20-30 lines of code that just calls a couple of inserts. The last thing to do is to write a blog post / comment saying "ORMs are evil".

LOLOLOLOLOLOLOLOL!!!!!!

You got me!

PS Another popular alternative is to fix the problem with hooks.

I'm curious, what do you mean?

from bun.

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.