commonMain.com.ditchoom.mqtt3.persistence.PublishMessageQueries.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mqtt-4-models Show documentation
Show all versions of mqtt-4-models Show documentation
Defines the MQTT 3 and 4 control packets
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.ByteArray
import kotlin.Long
import kotlin.String
import kotlin.Unit
public class PublishMessageQueries(
driver: SqlDriver,
) : TransacterImpl(driver) {
public fun queuedPubMessages(brokerId: Long, mapper: (
broker_id: Long,
incoming: Long,
dup: Long,
qos: Long,
retain: Long,
topic_name: String,
packet_id: Long,
payload: ByteArray?,
) -> T): Query = QueuedPubMessagesQuery(brokerId) { cursor ->
mapper(
cursor.getLong(0)!!,
cursor.getLong(1)!!,
cursor.getLong(2)!!,
cursor.getLong(3)!!,
cursor.getLong(4)!!,
cursor.getString(5)!!,
cursor.getLong(6)!!,
cursor.getBytes(7)
)
}
public fun queuedPubMessages(brokerId: Long): Query =
queuedPubMessages(brokerId) { broker_id, incoming, dup, qos, retain, topic_name, packet_id,
payload ->
PublishMessage(
broker_id,
incoming,
dup,
qos,
retain,
topic_name,
packet_id,
payload
)
}
public fun publishMessageCount(brokerId: Long): Query = PublishMessageCountQuery(brokerId) {
cursor ->
cursor.getLong(0)!!
}
public fun allMessages(brokerId: Long, mapper: (
broker_id: Long,
incoming: Long,
dup: Long,
qos: Long,
retain: Long,
topic_name: String,
packet_id: Long,
payload: ByteArray?,
) -> T): Query = AllMessagesQuery(brokerId) { cursor ->
mapper(
cursor.getLong(0)!!,
cursor.getLong(1)!!,
cursor.getLong(2)!!,
cursor.getLong(3)!!,
cursor.getLong(4)!!,
cursor.getString(5)!!,
cursor.getLong(6)!!,
cursor.getBytes(7)
)
}
public fun allMessages(brokerId: Long): Query = allMessages(brokerId) { broker_id,
incoming, dup, qos, retain, topic_name, packet_id, payload ->
PublishMessage(
broker_id,
incoming,
dup,
qos,
retain,
topic_name,
packet_id,
payload
)
}
public fun messageWithId(
brokerId: Long,
incoming: Long,
packetId: Long,
mapper: (
broker_id: Long,
incoming: Long,
dup: Long,
qos: Long,
retain: Long,
topic_name: String,
packet_id: Long,
payload: ByteArray?,
) -> T,
): Query = MessageWithIdQuery(brokerId, incoming, packetId) { cursor ->
mapper(
cursor.getLong(0)!!,
cursor.getLong(1)!!,
cursor.getLong(2)!!,
cursor.getLong(3)!!,
cursor.getLong(4)!!,
cursor.getString(5)!!,
cursor.getLong(6)!!,
cursor.getBytes(7)
)
}
public fun messageWithId(
brokerId: Long,
incoming: Long,
packetId: Long,
): Query = messageWithId(brokerId, incoming, packetId) { broker_id, incoming_,
dup, qos, retain, topic_name, packet_id, payload ->
PublishMessage(
broker_id,
incoming_,
dup,
qos,
retain,
topic_name,
packet_id,
payload
)
}
public fun insertPublishMessage(
broker_id: Long,
incoming: Long,
dup: Long,
qos: Long,
retain: Long,
topic_name: String,
packet_id: Long,
payload: ByteArray?,
): Unit {
driver.execute(1431275801, """
|INSERT INTO PublishMessage
|(broker_id, incoming, dup, qos, retain, topic_name, packet_id, payload)
|VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""".trimMargin(), 8) {
bindLong(0, broker_id)
bindLong(1, incoming)
bindLong(2, dup)
bindLong(3, qos)
bindLong(4, retain)
bindString(5, topic_name)
bindLong(6, packet_id)
bindBytes(7, payload)
}
notifyQueries(1431275801) { emit ->
emit("PublishMessage")
}
}
public fun deletePublishMessage(
brokerId: Long,
incoming: Long,
packetId: Long,
): Unit {
driver.execute(-1284227957,
"""DELETE FROM PublishMessage WHERE broker_id = ? AND incoming = ? AND packet_id = ?""", 3)
{
bindLong(0, brokerId)
bindLong(1, incoming)
bindLong(2, packetId)
}
notifyQueries(-1284227957) { emit ->
emit("PublishMessage")
}
}
public fun deleteAll(brokerId: Long): Unit {
driver.execute(-1041115410, """DELETE FROM PublishMessage WHERE broker_id = ?""", 1) {
bindLong(0, brokerId)
}
notifyQueries(-1041115410) { emit ->
emit("PublishMessage")
}
}
private inner class QueuedPubMessagesQuery(
public val brokerId: Long,
mapper: (SqlCursor) -> T,
) : Query(mapper) {
public override fun addListener(listener: Query.Listener): Unit {
driver.addListener(listener, arrayOf("PublishMessage"))
}
public override fun removeListener(listener: Query.Listener): Unit {
driver.removeListener(listener, arrayOf("PublishMessage"))
}
public override fun execute(mapper: (SqlCursor) -> R): QueryResult =
driver.executeQuery(-1808442642,
"""SELECT * FROM PublishMessage WHERE broker_id = ? AND incoming = 0""", mapper, 1) {
bindLong(0, brokerId)
}
public override fun toString(): String = "PublishMessage.sq:queuedPubMessages"
}
private inner class PublishMessageCountQuery(
public val brokerId: Long,
mapper: (SqlCursor) -> T,
) : Query(mapper) {
public override fun addListener(listener: Query.Listener): Unit {
driver.addListener(listener, arrayOf("PublishMessage"))
}
public override fun removeListener(listener: Query.Listener): Unit {
driver.removeListener(listener, arrayOf("PublishMessage"))
}
public override fun execute(mapper: (SqlCursor) -> R): QueryResult =
driver.executeQuery(-737900305,
"""SELECT COUNT(broker_id) FROM PublishMessage WHERE broker_id = ?""", mapper, 1) {
bindLong(0, brokerId)
}
public override fun toString(): String = "PublishMessage.sq:publishMessageCount"
}
private inner class AllMessagesQuery(
public val brokerId: Long,
mapper: (SqlCursor) -> T,
) : Query(mapper) {
public override fun addListener(listener: Query.Listener): Unit {
driver.addListener(listener, arrayOf("PublishMessage"))
}
public override fun removeListener(listener: Query.Listener): Unit {
driver.removeListener(listener, arrayOf("PublishMessage"))
}
public override fun execute(mapper: (SqlCursor) -> R): QueryResult =
driver.executeQuery(1076989701, """SELECT * FROM PublishMessage WHERE broker_id = ?""",
mapper, 1) {
bindLong(0, brokerId)
}
public override fun toString(): String = "PublishMessage.sq:allMessages"
}
private inner class MessageWithIdQuery(
public val brokerId: Long,
public val incoming: Long,
public val packetId: Long,
mapper: (SqlCursor) -> T,
) : Query(mapper) {
public override fun addListener(listener: Query.Listener): Unit {
driver.addListener(listener, arrayOf("PublishMessage"))
}
public override fun removeListener(listener: Query.Listener): Unit {
driver.removeListener(listener, arrayOf("PublishMessage"))
}
public override fun execute(mapper: (SqlCursor) -> R): QueryResult =
driver.executeQuery(576040544,
"""SELECT * FROM PublishMessage WHERE broker_id = ? AND incoming = ? AND packet_id = ? LIMIT 1""",
mapper, 3) {
bindLong(0, brokerId)
bindLong(1, incoming)
bindLong(2, packetId)
}
public override fun toString(): String = "PublishMessage.sq:messageWithId"
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy