RangeError: Maximum call stack size exceeded on update and delete for small number of rows (10s)
I have the following two calls that return the same RangeError:
The number of rows in question is around 10. I am successfully using .where with update in another query.
30 Replies
Is it exactly how your delete is written?
.returning({ address })
is invalid, you need to .returning({ address: schema.accounts.address })
or an other column
you are assigning address
to .returning
looks the same for update
maybe it is not clear but returnin is {aName: theTableColumn}
thank you! that solved the first and led to another issue for the latter (deletion).
so I get the following:
PostgresError: missing FROM-clause entry for table "accounts"
Which I suppose makes sense; there is a one-to-many relation from accounts -> cards, I would like to delete all cards that belong to the specific account based on an address of that account, but the reference in cards is to the accounts idoh you want a subquery in your where
accounts.address is unique, would one way of addressing this being making the relation reference the address in the card relation?
Oh I like that option much more. I will have a look at the docs for that ❤️
Relations are only for
select
.
https://orm.drizzle.team/docs/operators#exists
I am thinking about exists
but it depends on the query you need
I would like to delete all cards that belong to the specific account based on an address of that accountif there is a way to match a card and account it could be possible
you can try to reproduce a light version of your schema and share it with https://drizzle.run
Drizzle Run
Drizzle Run
woops, forgot a field, changes pushed
the playground is 🤌 btw
and maybe to be a bit clearer with the query I am after:
Delete all cards
- that match a given
contractAddress
and
- that reference the account given by the account.address
.
So cards that match the contractAddress but reference another account are not deletedOk, I'm forking it and come back in few minutes. If you try on your own we could compare :p
I will try 🙂
can a
cards
have no accountId
?strictly, yes, because there is no
notNull
. This isn't the case in my application howeverok because we could add a reference from
accountId
to accounts.id
but I was just asking :pfor this POC I am making for tomorrow I won't include the
notNull
but it should be there I suppose as all cards should be related to an account
wait, isn't that what there is already?Relations are "runtime" link between tables but not "real" link like references (foreign key)
ah so you're saying I could add a database-level relation with foreign keys?
yes, only if you need to prevent errors
If that is my only option I will have to but I'm trying to avoid changes to the schema if possible atm 😉
With a ref, you have the guarantee that it will be an existing accountId
Right, I see
ok
hmm, with the following I delete all cards but for every user. Will keep trying.
Which I guess makes sense, as
exists(query)
I expect to always be true with how I have defined it.I did the same query
It seems to delete the expected cards
If you add the card value, in your playground:
This will also get deleted though no?
i.e. it is deleting cards that match the contractAddress but for every user.
ah yes 🤦♂️
I have updated
now the check is also checking the accountId
ahhh this makes good sense. Thanks for all the help! its greatly appreciated
Curious, how big is the team working on drizzle?
I think they are 4 developers (I am not a core member, just an early adopter contributing lol)
awesome, well, thanks again ❤️