Re: INSERT ... RETURNING when doing CRUD with Record objects

Mon, 01 Apr 2019 00:23:19 -0700

Thanks for the suggestion. Indeed, we should add this link to the section
about storing, in particular this bullet:

   - When store() performs an INSERT statement
   
<https://www.jooq.org/doc/3.11/manual/sql-building/sql-statements/insert-statement/>,
   jOOQ attempts to load any generated keys from the database back into the
   record. For more details, see the manual's section about IDENTITY values
   
<https://www.jooq.org/doc/3.11/manual/sql-execution/crud-with-updatablerecords/identity-values/>
   .

I've created an issue for this:
https://github.com/jOOQ/jOOQ/issues/8471

Thanks,
Lukas

On Sun, Mar 31, 2019 at 7:50 PM Marshall Pierce <[email protected]>
wrote:

> That works great, thanks! Might not hurt to throw a link to that from the
> updatable records section of the manual. :)
>
> https://www.jooq.org/doc/3.11/manual/sql-execution/crud-with-updatablerecords/simple-crud/
> in the Storing, or maybe Refreshing, section seems plausible to me.
>
> On Sunday, March 31, 2019 at 7:36:05 AM UTC-6, Lukas Eder wrote:
>>
>> Hi  Marshall  ,
>>
>> Maybe this helps:
>>
>> https://www.jooq.org/doc/latest/manual/sql-building/dsl-context/custom-settings/settings-return-all-on-store
>>
>> The default value for the returnAllOnUpdatableRecord is false, as this is
>> usually not needed, and it causes an extra query on some RDBMS that do not
>> support the functionality natively (i.e. an implicit refresh() call)
>>
>> Thanks,
>> Lukas
>>
>> On Sat, Mar 30, 2019 at 4:45 AM Marshall Pierce <[email protected]>
>> wrote:
>>
>>> I might be missing something obvious in the UpdatableRecord API, but I
>>> didn't find a way to emulate INSERT ... RETURNING. Is there a way to do
>>> that?
>>>
>>> As an example, I'd like to mimic this behavior (inserting into a simple
>>> table that only needs `name` specified):
>>>
>>> txnContext.insertInto(WIDGETS, WIDGETS.NAME)
>>>      .values(name)
>>>      .returning()
>>>      .fetchOne()
>>>
>>> with this:
>>>
>>> txnContext.newRecord(WIDGETS).apply {
>>>      this.name = name
>>>      store() // INSERT
>>>      refresh() // SELECT -- ideally not needed
>>> }
>>>
>>> Without that `refresh()`, the new `WidgetsRecord` doesn't have, for
>>> instance, its db-populated `createdAt`.
>>>
>>> Thanks,
>>> Marshall
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "jOOQ User Group" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to