lucid icon indicating copy to clipboard operation
lucid copied to clipboard

db.raw() in ColumnOptions.prepare works for insert but not for update

Open BluemediaDev opened this issue 11 months ago • 4 comments
trafficstars

Package version

@adonisjs/[email protected]

Describe the bug

Hi everyone,

I've encountered the same issue described in #939 while using the latest Lucid release. My use case and the resulting error closely mirror those in the original issue.

I attempted to create a test case to address this, but my understanding of Lucid's internals is limited. Instead, I put together a small reproduction repository to demonstrate the problem.

Feel free to let me know if additional details or adjustments are needed!

Reproduction repo

https://github.com/BluemediaDev/lucid-prepare-repro

BluemediaDev avatar Dec 17 '24 18:12 BluemediaDev

Hello @BluemediaDev

I think the root of the issue is how the prepare method works right now. Basically, the prepare method is not capable of returning different values for insert, update, or select.

I am afraid that there is no quick fix for this and this is something we will have to think a bit more and then add support for it. I will keep this issue opened until we work on that.

thetutlage avatar Dec 18 '24 17:12 thetutlage

Hi @thetutlage,

Thank you for looking into this!

I might be missing something about how Lucid works internally, but in my view, it doesn't seem necessary to return different values for different actions in this case. POINT() should work for INSERT, UPDATE, and SELECT operations without issue.

The error appears to be more about the RawBuilder not being properly converted into valid SQL and used in the query—it looks like it's just dumped as text instead. I enabled the debug mode on the reproduction repo; maybe that makes it clearer what I'm talking about.

BluemediaDev avatar Dec 18 '24 19:12 BluemediaDev

i'm facing the same issue any updates @thetutlage

MohammedElattar avatar Apr 17 '25 09:04 MohammedElattar

@MohammedElattar This will require a bit more planning since the column.prepare was build for simple use-cases. I do not have a solution at hand right now. However, in the next major release, I will address this shortcoming

thetutlage avatar May 06 '25 09:05 thetutlage

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 18 '25 23:07 stale[bot]