This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Table definition | |
object Cities : Table() { | |
val id = integer("id").autoIncrement().primaryKey() | |
val name = varchar("name", 50) | |
} | |
// Entity definition | |
data class City( | |
val id: Int, | |
val name: String | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun execute(cities: List<City>) { | |
transaction { | |
Cities.batchInsertOnDuplicateKeyUpdate( cities, listOf(id, name) ) { batch, city -> | |
batch[Cities.id] = city.id | |
batch[Cities.name] = city.name | |
} | |
} | |
} | |
// The below code is just a copy-paste that should actually be in the lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage | |
transaction { | |
logger.addLogger(KotlinLoggingSqlLogger) | |
... | |
} | |
// Declaration | |
object KotlinLoggingSqlLogger : SqlLogger { | |
private val logger = KotlinLogging.logger { } | |
override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object StarWarsFilms : IntIdTable() { | |
val sequelId: Column<Int> = integer("sequel_id").uniqueIndex() | |
val name: Column<String> = varchar("name", 50) | |
val director: Column<String> = varchar("director", 50) | |
} | |
data class StarWarsFilm(val sequelId: Int, | |
val name: String, | |
val director: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver") | |
transaction { | |
// insert new city. SQL: INSERT INTO Cities (name) VALUES ('St. Petersburg') | |
val stPeteId = Cities.insert { | |
it[name] = "St. Petersburg" | |
} get Cities.id | |
// 'select *' SQL: SELECT Cities.id, Cities.name FROM Cities |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Table definition | |
object Cities : Table() { | |
val id = integer("id").autoIncrement().primaryKey() | |
val name = varchar("name", 50) | |
val create_date = datetime(name = "create_date") | |
} | |
// Entity definition | |
data class City( | |
val id: Int, | |
val name: String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env kscript | |
import java.io.File | |
// usage - one argument a .kt file (Scala file that was only renamed) | |
// or a directory | |
try { | |
main(args) | |
} catch (e: Exception) { | |
e.printStackTrace() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.github.jasync.sql.db.Configuration | |
import com.github.jasync.sql.db.Connection | |
import com.github.jasync.sql.db.QueryResult | |
import com.github.jasync.sql.db.RowData | |
import com.github.jasync.sql.db.mysql.MySQLConnection | |
import com.github.jasync.sql.db.mysql.util.URLParser | |
import com.github.jasync.sql.db.util.head | |
import com.github.jasync.sql.db.util.map | |
import java.util.concurrent.CompletableFuture |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments | |
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer | |
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector | |
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler | |
import org.jetbrains.kotlin.config.Services | |
import java.io.File | |
import java.io.FileNotFoundException | |
import java.io.IOException | |
import java.io.PrintWriter | |
import java.net.URLClassLoader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `"Simple query with 1 nanosec timeout"`() { | |
withConfigurablePool(shortTimeoutConfiguration()) { pool -> | |
{ | |
val connection = pool.take().get(10, TimeUnit.SECONDS) | |
assertThat(connection.isTimeout()).isEqualTo(false) | |
assertThat(connection.isConnected()).isEqualTo(true) | |
val queryResultFuture = connection.sendQuery("select sleep(1)") | |
verifyException(TimeoutException::class.java) { | |
queryResultFuture.get(10, TimeUnit.SECONDS) |
OlderNewer