Skip to content

Instantly share code, notes, and snippets.

@yukithm
Created November 20, 2019 09:52
Show Gist options
  • Save yukithm/79846495cd286f93bf95c6b7500c17da to your computer and use it in GitHub Desktop.
Save yukithm/79846495cd286f93bf95c6b7500c17da to your computer and use it in GitHub Desktop.
[kotlin] jOOQ: PostgreSQL's setval() for DSLContext
package com.example.jooqext
import org.jooq.DSLContext
import org.jooq.Sequence
import org.jooq.impl.DSL
fun <T : Number> DSLContext.setval(sequence: Sequence<T>, value: T, isCalled: Boolean = true) =
select(
DSL.field(
"setval({0}, {1}, {2})",
Long::class.java,
sequence.qualifiedName.unquotedName().toString(),
value,
isCalled
)
).fetchOne(0)
@yukithm
Copy link
Author

yukithm commented Nov 20, 2019

Example:

dslContext.setval(FOO_TABLE_FOO_ID_SEQ, 1, false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment