is it thread-safe to request multiple transactions...
# squarelibraries
m
is it thread-safe to request multiple transactions from different threads on JVM with sqlite? Using the provided
JdbcSqliteDriver
Copy code
val database: Database = ...
val queries: MyQueries = database.myQueries

// request for transaction in thread A
queries.insertPerson("Joseph")

// request for transaction in thread B
queries.insertPerson("Martina")
a
Generally not with sqlite
e
I'm pretty sure it's thread safe
m
I'm gonna assume it is because this is part of its implementation.
Copy code
private class ThreadedConnectionManager(
  private val url: String,
  private val properties: Properties,
) : JdbcSqliteDriverConnectionManager() {
  private val transactions = ThreadLocal<Transaction>()
  private val connections = ThreadLocal<Connection>()

  override var transaction: Transaction?
    get() = transactions.get()
    set(value) { transactions.set(value) }

  override fun getConnection() = connections.getOrSet {
    DriverManager.getConnection(url, properties)
  }
if they clean up the `ThreadLocal`s later (notice I'm talking about NEW transactions that stay in the same thread, not a transaction that jumps onto another thread when it's already started. My question was about starting multiple transactions concurrently)