Comments (6)
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.
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.
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.
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.
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.
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)
- how do i exec multiple queries as a single query? HOT 2
- regression: models with nested embedded structs not handled properly HOT 1
- inconsistent behavior for ModelTableExpr (select <--> create/insert/update/delete)
- race detected in ```schema.Field.Clone()``` HOT 2
- Issue with BeforeAppendModel when selecting columns to update HOT 1
- Go migrations are not discovered
- Custom sum column on a relation
- In v1.2, about 'unique' tag option in embedded structures HOT 1
- Call BeforeAppendModel on embedded types
- incorrect CTE generation
- Is []int64 supported for Arrays
- Support for DuckDB dialect
- Ambiguous Column Reference Id
- Scan error on column: bun: Scan(unsupported [32]uint8)"
- m2m relations with composite keys
- can't scan 1 (float32) into float32 HOT 2
- Issue: Panic on Bulk Upsert with Pointer Fields in Slice of Interfaces HOT 1
- Documentation Pgx section update HOT 2
- Is it possible to insert a comment before or after a sql query?
- how can i tag index in struct filed?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bun.