All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.ditchoom.mqtt3.persistence.SocketConnectionQueries.kt Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
package com.ditchoom.mqtt3.persistence

import app.cash.sqldelight.Query
import app.cash.sqldelight.TransacterImpl
import app.cash.sqldelight.db.QueryResult
import app.cash.sqldelight.db.SqlCursor
import app.cash.sqldelight.db.SqlDriver
import kotlin.Any
import kotlin.Long
import kotlin.String
import kotlin.Unit

public class SocketConnectionQueries(
  driver: SqlDriver,
) : TransacterImpl(driver) {
  public fun  connectionsByBrokerId(brokerId: Long, mapper: (
    id: Long,
    broker_id: Long,
    type: String,
    host: String,
    port: Long,
    tls: Long,
    connection_timeout_ms: Long,
    read_timeout_ms: Long,
    write_timeout_ms: Long,
    websocket_endpoint: String?,
    websocket_protocols: String?,
  ) -> T): Query = ConnectionsByBrokerIdQuery(brokerId) { cursor ->
    mapper(
      cursor.getLong(0)!!,
      cursor.getLong(1)!!,
      cursor.getString(2)!!,
      cursor.getString(3)!!,
      cursor.getLong(4)!!,
      cursor.getLong(5)!!,
      cursor.getLong(6)!!,
      cursor.getLong(7)!!,
      cursor.getLong(8)!!,
      cursor.getString(9),
      cursor.getString(10)
    )
  }

  public fun connectionsByBrokerId(brokerId: Long): Query =
      connectionsByBrokerId(brokerId) { id, broker_id, type, host, port, tls, connection_timeout_ms,
      read_timeout_ms, write_timeout_ms, websocket_endpoint, websocket_protocols ->
    SocketConnection(
      id,
      broker_id,
      type,
      host,
      port,
      tls,
      connection_timeout_ms,
      read_timeout_ms,
      write_timeout_ms,
      websocket_endpoint,
      websocket_protocols
    )
  }

  public fun insertConnection(
    broker_id: Long,
    type: String,
    host: String,
    port: Long,
    tls: Long,
    connection_timeout_ms: Long,
    read_timeout_ms: Long,
    write_timeout_ms: Long,
    websocket_endpoint: String?,
    websocket_protocols: String?,
  ): Unit {
    driver.execute(607381560, """
        |INSERT INTO SocketConnection
        |(id,broker_id,type,host,port,tls,connection_timeout_ms,read_timeout_ms,write_timeout_ms,websocket_endpoint,websocket_protocols)
        | VALUES
        |  (NULL,?,?,?,?,?,?,?,?,?,?)
        """.trimMargin(), 10) {
          bindLong(0, broker_id)
          bindString(1, type)
          bindString(2, host)
          bindLong(3, port)
          bindLong(4, tls)
          bindLong(5, connection_timeout_ms)
          bindLong(6, read_timeout_ms)
          bindLong(7, write_timeout_ms)
          bindString(8, websocket_endpoint)
          bindString(9, websocket_protocols)
        }
    notifyQueries(607381560) { emit ->
      emit("SocketConnection")
    }
  }

  private inner class ConnectionsByBrokerIdQuery(
    public val brokerId: Long,
    mapper: (SqlCursor) -> T,
  ) : Query(mapper) {
    public override fun addListener(listener: Query.Listener): Unit {
      driver.addListener(listener, arrayOf("SocketConnection"))
    }

    public override fun removeListener(listener: Query.Listener): Unit {
      driver.removeListener(listener, arrayOf("SocketConnection"))
    }

    public override fun  execute(mapper: (SqlCursor) -> R): QueryResult =
        driver.executeQuery(1794293343, """SELECT * FROM SocketConnection WHERE broker_id = ?""",
        mapper, 1) {
      bindLong(0, brokerId)
    }

    public override fun toString(): String = "SocketConnection.sq:connectionsByBrokerId"
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy