Serialization of Records

2018-11-01 Thread alamothe
Hi Lukas,
First of all, thank you for a great library, as well as answering all my 
previous questions :-) 

I have a question about serialization. When a record is serialized, what 
exactly does the serialized data include?
Is it only row-level data such as field values? Or also table schema? Or 
even more?

My use case is that I'd like to serialize query result (a list of records) 
to Memcache. Ideally, I only want row-level data to be serialized, as 
Memcache will be read by the same binary.
Should I instead go a different route, perhaps work with POJOs instead of 
Records?

Thanks,
Nikola

-- 
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 jooq-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: JOOQ for TypeScript

2018-05-23 Thread alamothe
No ORM please

On Wednesday, May 23, 2018 at 6:07:35 PM UTC-7, Nikola Mihajlović wrote:
>
> Hello,
> Sorry if it is a bit off topic, but this group might be able to help :-)
>
> JOOQ is awesome, however for the new project we decided to try JavaScript 
> (TypeScript) for server-side
>
> What is the best JOOQ-like library for TypeScript?
>
> Thanks!
>

-- 
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 jooq-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


JOOQ for TypeScript

2018-05-23 Thread alamothe
Hello,
Sorry if it is a bit off topic, but this group might be able to help :-)

JOOQ is awesome, however for the new project we decided to try JavaScript 
(TypeScript) for server-side

What is the best JOOQ-like library for TypeScript?

Thanks!

-- 
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 jooq-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Idiomatic way to "upsert" while returning ID

2018-04-20 Thread alamothe
Hi Lukas,
Thanks so much for the explanation!

This is likely not JOOQ related but...

What I'm doing now is:

val p = TestOnDuplicateKeyUpdateRow()
p.a = "a0"
p.b = "b2"
val r = TaskContext.get().jooq
 .insertInto(Tables.TEST_ON_DUPLICATE_KEY_UPDATE)
 .set(p)
 .onDuplicateKeyUpdate()
 .set(p)
 .returning(Tables.TEST_ON_DUPLICATE_KEY_UPDATE.ID)
 .fetch()


What's happening is:
- If the key didn't exist, one row with a new ID is returned correctly
- If the key existed, two rows are returned... why? Looks like the first 
one has the key of the updated row... Can I actually rely on this?

I wish there was a simple upsert method on the Record :-)

Thanks!


On Monday, April 16, 2018 at 12:35:25 AM UTC-7, Lukas Eder wrote:
>
> Hello,
>
> Thanks for your message. For the record (as this feature has been 
> requested a few times), there is no 
> UpdatableRecord.insertOnDuplicateKeyUpdate() method because the "on 
> duplicate key" semantics is different depending on the database. In MySQL, 
> all unique keys and indexes are considered for duplicate keys. In other 
> databases, only the primary key is considered, and in other databases, the 
> key has to be specified explicitly. It would be difficult to make the right 
> API choice here.
>
> Regarding your attempted workaround: it would be unexpected for a 
> statement to modify the passed record just because it happens to be a 
> record and because a call on the record itself does update the record. You 
> could even pass different records to the insert / update clauses, or 
> several records to the insert clause, when the update clause is always a 
> bulk update.
>
> Think of passing a record to a jOOQ statement in the same way as of 
> passing a map or individual values to a jOOQ statement. So, your statement 
> is akin to:
>
> jooq
>  .insertInto(Tables.TEST_ON_DUPLICATE_KEY_UPDATE)
>  .set(p.intoMap())
>  .onDuplicateKeyUpdate()
>  .set(p.intoMap())
>  .execute()
>
>
> You can use the returning clause on the INSERT statement, to be explicit 
> about this:
>
> jooq
>  .insertInto(Tables.TEST_ON_DUPLICATE_KEY_UPDATE)
>  .set(p.intoMap())
>  .onDuplicateKeyUpdate()
>  .set(p.intoMap())
>  .returning()
>
>  .fetch()
>
>
> I hope this helps,
> Lukas
>
> 2018-04-15 4:39 GMT+02:00 :
>
>> Hello,
>> Thanks for the great product!
>>
>> I am trying to do "upsert" (insert on duplicate key update) while still 
>> returning ID for the row.
>>
>> This is my table:
>>
>> create table test_on_duplicate_key_update (
>>   id bigint not null primary key auto_increment,
>>
>>   a varchar(255) not null,
>>   unique(a),
>>
>>   b varchar(255)
>> );
>>
>> This is how I perform regular insert (Kotlin):
>>
>> val p = jooq.newRecord(Tables.TEST_ON_DUPLICATE_KEY_UPDATE)
>> p.a = "a0"
>> p.b = "b0"
>> p.store()
>> // p.id is available here
>>
>>
>> Now for "upsert", what I do is:
>>
>> val p = TestOnDuplicateKeyUpdateRow()
>> p.a = "a1"
>> p.b = "b1"
>> jooq
>>  .insertInto(Tables.TEST_ON_DUPLICATE_KEY_UPDATE)
>>  .set(p)
>>  .onDuplicateKeyUpdate()
>>  .set(p)
>>  .execute()
>> // p.id is null :-(
>>
>>
>> What is the idiomatic way to do this? 
>>
>>
>> I am using:
>>
>> - Jooq 3.10.6
>>
>> - MySQL
>>
>>
>> Thanks!
>>
>> -- 
>> 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 jooq-user+...@googlegroups.com .
>> 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 jooq-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Idiomatic way to "upsert" while returning ID

2018-04-14 Thread alamothe
Hello,
Thanks for the great product!

I am trying to do "upsert" (insert on duplicate key update) while still 
returning ID for the row.

This is my table:

create table test_on_duplicate_key_update (
  id bigint not null primary key auto_increment,

  a varchar(255) not null,
  unique(a),

  b varchar(255)
);

This is how I perform regular insert (Kotlin):

val p = jooq.newRecord(Tables.TEST_ON_DUPLICATE_KEY_UPDATE)
p.a = "a0"
p.b = "b0"
p.store()
// p.id is available here


Now for "upsert", what I do is:

val p = TestOnDuplicateKeyUpdateRow()
p.a = "a1"
p.b = "b1"
jooq
 .insertInto(Tables.TEST_ON_DUPLICATE_KEY_UPDATE)
 .set(p)
 .onDuplicateKeyUpdate()
 .set(p)
 .execute()
// p.id is null :-(


What is the idiomatic way to do this? 


I am using:

- Jooq 3.10.6

- MySQL


Thanks!

-- 
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 jooq-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [REQUEST FOR FEEDBACK]: What small but incredibly useful utility are you missing the most in jOOQ?

2017-10-18 Thread alamothe
Super small request

Can you please add *isFetched()* convenience method to a Record? Currently 
this field is private and cannot be read

Thanks for the great work!

On Wednesday, July 6, 2016 at 5:16:44 AM UTC-7, Lukas Eder wrote:
>
> Dear group,
>
> Part of jOOQ's success is its incredible amount of convenience methods 
> that help reduce the boiler plate code at your side. We do this with 
> massive overloading of API, for instance, when you work with fetch(), you 
> may have noticed how many different types of fetch() there are in jOOQ.
>
> Just now, I have added yet another convenience method. A Converter 
> constructor:
> https://github.com/jOOQ/jOOQ/issues/5398
>
> It looks like this:
>
> static  Converter of(
> Class fromType,
> Class toType,
> Function from,
> Function to
> ) { ... }
>
> And also:
>
> static  Converter ofNullable(
> Class fromType,
> Class toType,
> Function from,
> Function to
> ) {
> return of(
> fromType,
> toType,
> t -> t == null ? null : from.apply(t),
> u -> u == null ? null : to.apply(u)
> );
> }
>
>
> The above allows for creating simple ad-hoc, one-liner converters, such as:
>
> Converter converter =
> Converter.ofNullable(String.class, Integer.class, Integer::parseInt, 
> Object::toString);
>
> What's your biggest "itch" in the jOOQ API, which jOOQ could "scratch", or 
> rather, make go away by adding new convenience API?
>
> All ideas welcome!
> Lukas
>

-- 
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 jooq-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Update only when modified

2017-10-18 Thread alamothe
Hi,
I am updating a bunch of records in the DB like this:

  // fetch a bunch of records
  records = ...

  for (Record r : records) {
// update logic

r.store();
  }


I hoped the UPDATE statement would be issued only if the record is 
modified. However, it is issued every time a record is touched.

I 
read: 
https://blog.jooq.org/2017/06/28/orms-should-update-changed-values-not-just-modified-ones/
 
and that was pretty helpful to explain the difference.

Is it possible to get modified semantics with JOOQ? I could fix my code to 
replace every setXYZ with if ... setXYZ but it will generate too much 
boilerplate

Would doing something like:

  if (!r.original.equals(r)) {
r.store();
  }

at the end work in general case?

Thanks!

-- 
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 jooq-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Type-safe IDs

2017-09-07 Thread alamothe
Hi all,
Has anyone tried to build type-safe IDs with jOOQ? 

Something like described e.g. here:
https://dysphoria.net/2013/04/12/id-type-safety-in-database-code/
https://www.wix.engineering/single-post/on-identifier-types-type-safety-and-guids
(there are probably better articles about it - it is an age-old idea)

It looks to me it would not be that hard to do, given jOOQ already 
generates a bunch of useful code (for example a class for each table) and 
supports custom converters. Then the types would just propagate from 
records to the whole codebase easily

The only boilerplate could be in XML specifying all the converters.

Am I missing any roadblocks?

Thanks,
Nikola

-- 
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 jooq-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.