dhia chemingui
10/03/2023, 4:57 PMhttps://kotlinlang.slack.com/files/U05R0A2T24B/F05UCA4NDKN/image.png▾
https://kotlinlang.slack.com/files/U05R0A2T24B/F05U9PS50M9/image.png▾
https://kotlinlang.slack.com/files/U05R0A2T24B/F05U37YPS4W/image.png▾
griffio
10/04/2023, 11:29 AMsq
files and generated queries as well? - just in case the notify
call is not being generated. Currently sql that returns rows after insert or update, then notify is not generated.dhia chemingui
10/04/2023, 8:22 PMimport com.softylines.pdfproject.common.core.models.LayoutConfig;
import com.softylines.pdfproject.common.database.data.tab.ZoomMode;
CREATE TABLE IF NOT EXISTS tabEntity (
id TEXT NOT NULL PRIMARY KEY,
windowId TEXT NOT NULL,
title TEXT NOT NULL,
filePath TEXT,
position INTEGER NOT NULL,
linkedTabId TEXT,
zoom REAL NOT NULL,
widthPercentage REAL NOT NULL,
zoomMode TEXT AS ZoomMode,
openedLayoutConfigPanel TEXT AS LayoutConfig.Panel,
pageLayout TEXT AS LayoutConfig.PageLayout,
splitView TEXT AS LayoutConfig.SplitView,
configPanelWidth REAL NOT NULL,
styleConfigPanelWidth REAL NOT NULL,
isSaved INTEGER NOT NULL
);
selectOne:
SELECT *
FROM tabEntity
WHERE id = :id;
selectAll:
SELECT *
FROM tabEntity;
selectAllByWindowId:
SELECT *
FROM tabEntity
WHERE windowId = :windowId;
insert:
INSERT OR REPLACE INTO tabEntity(id, windowId, title, filePath, position, linkedTabId, zoom, widthPercentage,
zoomMode, configPanelWidth , styleConfigPanelWidth , isSaved )
VALUES ?;
updatePosition:
UPDATE tabEntity
SET position = :position
WHERE id = :id;
updateTitle:
UPDATE tabEntity
SET title = :title
WHERE id = :id;
updateZoom:
UPDATE tabEntity
SET zoom = :zoom
WHERE id = :id;
updateZoomMode:
UPDATE tabEntity
SET zoomMode = :zoomMode
WHERE id = :id;
updateFilePath:
UPDATE tabEntity
SET filePath = :filePath
WHERE id = :id;
updateLinkedTabId:
UPDATE tabEntity
SET linkedTabId = :linkedTabId
WHERE id = :id;
updateWidthPercentage:
UPDATE tabEntity
SET widthPercentage = :widthPercentage
WHERE id = :id;
updatePanelsWidthPercentage:
UPDATE tabEntity
SET configPanelWidth = :configPanelWidth,
styleConfigPanelWidth = :styleConfigPanelWidth
;
updateOpenedLayoutConfigPanel:
UPDATE tabEntity
SET openedLayoutConfigPanel = :layoutConfigPanel
WHERE id = :id;
updatePageLayout:
UPDATE tabEntity
SET pageLayout = :pageLayout
WHERE id = :id;
updateSplitView:
UPDATE tabEntity
SET splitView = :splitView
WHERE id = :id;
updateIsSaved:
UPDATE tabEntity
SET isSaved = :isSaved
WHERE id = :id;
delete:
DELETE FROM tabEntity
WHERE id = :id;
deleteAll:
DELETE FROM tabEntity;
package com.softylines.pdfproject.database.database
import app.cash.sqldelight.TransacterImpl
import app.cash.sqldelight.db.AfterVersion
import app.cash.sqldelight.db.QueryResult
import app.cash.sqldelight.db.SqlDriver
import app.cash.sqldelight.db.SqlSchema
import com.softylines.pdfproject.database.PdfDatabase
import comsoftylinespdfprojectcommondatabase.RecentPdfQueries
import comsoftylinespdfprojectcommondatabase.TabEntity
import comsoftylinespdfprojectcommondatabase.TabEntityQueries
import comsoftylinespdfprojectcommondatabase.WindowEntityQueries
import kotlin.Long
import kotlin.Unit
import kotlin.reflect.KClass
internal val KClass<PdfDatabase>.schema: SqlSchema<QueryResult.Value<Unit>>
get() = PdfDatabaseImpl.Schema
internal fun KClass<PdfDatabase>.newInstance(driver: SqlDriver,
tabEntityAdapter: TabEntity.Adapter): PdfDatabase = PdfDatabaseImpl(driver, tabEntityAdapter)
private class PdfDatabaseImpl(
driver: SqlDriver,
tabEntityAdapter: TabEntity.Adapter,
) : TransacterImpl(driver), PdfDatabase {
override val recentPdfQueries: RecentPdfQueries = RecentPdfQueries(driver)
override val tabEntityQueries: TabEntityQueries = TabEntityQueries(driver, tabEntityAdapter)
override val windowEntityQueries: WindowEntityQueries = WindowEntityQueries(driver)
public object Schema : SqlSchema<QueryResult.Value<Unit>> {
override val version: Long
get() = 1
override fun create(driver: SqlDriver): QueryResult.Value<Unit> {
driver.execute(null, """
|CREATE TABLE IF NOT EXISTS recentPdf (
| fileName TEXT NOT NULL,
| filePath TEXT NOT NULL PRIMARY KEY
|)
""".trimMargin(), 0)
driver.execute(null, """
|CREATE TABLE IF NOT EXISTS tabEntity (
| id TEXT NOT NULL PRIMARY KEY,
| windowId TEXT NOT NULL,
| title TEXT NOT NULL,
| filePath TEXT,
| position INTEGER NOT NULL,
| linkedTabId TEXT,
| zoom REAL NOT NULL,
| widthPercentage REAL NOT NULL,
| zoomMode TEXT,
| openedLayoutConfigPanel TEXT,
| pageLayout TEXT,
| splitView TEXT,
| configPanelWidth REAL NOT NULL,
| styleConfigPanelWidth REAL NOT NULL,
| isSaved INTEGER NOT NULL
| )
""".trimMargin(), 0)
driver.execute(null, """
|CREATE TABLE IF NOT EXISTS windowEntity (
| id TEXT NOT NULL PRIMARY KEY,
| title TEXT NOT NULL,
| selectedTabId TEXT
|)
""".trimMargin(), 0)
return QueryResult.Unit
}
override fun migrate(
driver: SqlDriver,
oldVersion: Long,
newVersion: Long,
vararg callbacks: AfterVersion,
): QueryResult.Value<Unit> = QueryResult.Unit
}
}
package comsoftylinespdfprojectcommondatabase
import app.cash.sqldelight.ColumnAdapter
import com.softylines.pdfproject.common.core.models.LayoutConfig
import com.softylines.pdfproject.common.database.`data`.tab.ZoomMode
import kotlin.Double
import kotlin.Long
import kotlin.String
public data class TabEntity(
public val id: String,
public val windowId: String,
public val title: String,
public val filePath: String?,
public val position: Long,
public val linkedTabId: String?,
public val zoom: Double,
public val widthPercentage: Double,
public val zoomMode: ZoomMode?,
public val openedLayoutConfigPanel: LayoutConfig.Panel?,
public val pageLayout: LayoutConfig.PageLayout?,
public val splitView: LayoutConfig.SplitView?,
public val configPanelWidth: Double,
public val styleConfigPanelWidth: Double,
public val isSaved: Long,
) {
public class Adapter(
public val zoomModeAdapter: ColumnAdapter<ZoomMode, String>,
public val openedLayoutConfigPanelAdapter: ColumnAdapter<LayoutConfig.Panel, String>,
public val pageLayoutAdapter: ColumnAdapter<LayoutConfig.PageLayout, String>,
public val splitViewAdapter: ColumnAdapter<LayoutConfig.SplitView, String>,
)
}
package comsoftylinespdfprojectcommondatabase
public class TabEntityQueries(
driver: SqlDriver,
private val tabEntityAdapter: TabEntity.Adapter,
) : TransacterImpl(driver) {
public fun <T : Any> selectOne(id: String, mapper: (
id: String,
windowId: String,
title: String,
filePath: String?,
position: Long,
linkedTabId: String?,
zoom: Double,
widthPercentage: Double,
zoomMode: ZoomMode?,
openedLayoutConfigPanel: LayoutConfig.Panel?,
pageLayout: LayoutConfig.PageLayout?,
splitView: LayoutConfig.SplitView?,
configPanelWidth: Double,
styleConfigPanelWidth: Double,
isSaved: Long,
) -> T): Query<T> = SelectOneQuery(id) { cursor ->
mapper(
cursor.getString(0)!!,
cursor.getString(1)!!,
cursor.getString(2)!!,
cursor.getString(3),
cursor.getLong(4)!!,
cursor.getString(5),
cursor.getDouble(6)!!,
cursor.getDouble(7)!!,
cursor.getString(8)?.let { tabEntityAdapter.zoomModeAdapter.decode(it) },
cursor.getString(9)?.let { tabEntityAdapter.openedLayoutConfigPanelAdapter.decode(it) },
cursor.getString(10)?.let { tabEntityAdapter.pageLayoutAdapter.decode(it) },
cursor.getString(11)?.let { tabEntityAdapter.splitViewAdapter.decode(it) },
cursor.getDouble(12)!!,
cursor.getDouble(13)!!,
cursor.getLong(14)!!
)
}
public fun selectOne(id: String): Query<TabEntity> = selectOne(id) { id_, windowId, title,
filePath, position, linkedTabId, zoom, widthPercentage, zoomMode, openedLayoutConfigPanel,
pageLayout, splitView, configPanelWidth, styleConfigPanelWidth, isSaved ->
TabEntity(
id_,
windowId,
title,
filePath,
position,
linkedTabId,
zoom,
widthPercentage,
zoomMode,
openedLayoutConfigPanel,
pageLayout,
splitView,
configPanelWidth,
styleConfigPanelWidth,
isSaved
)
}
public fun <T : Any> selectAll(mapper: (
id: String,
windowId: String,
title: String,
filePath: String?,
position: Long,
linkedTabId: String?,
zoom: Double,
widthPercentage: Double,
zoomMode: ZoomMode?,
openedLayoutConfigPanel: LayoutConfig.Panel?,
pageLayout: LayoutConfig.PageLayout?,
splitView: LayoutConfig.SplitView?,
configPanelWidth: Double,
styleConfigPanelWidth: Double,
isSaved: Long,
) -> T): Query<T> = Query(-1_232_775_109, arrayOf("tabEntity"), driver, "TabEntity.sq",
"selectAll", """
|SELECT *
|FROM tabEntity
""".trimMargin()) { cursor ->
mapper(
cursor.getString(0)!!,
cursor.getString(1)!!,
cursor.getString(2)!!,
cursor.getString(3),
cursor.getLong(4)!!,
cursor.getString(5),
cursor.getDouble(6)!!,
cursor.getDouble(7)!!,
cursor.getString(8)?.let { tabEntityAdapter.zoomModeAdapter.decode(it) },
cursor.getString(9)?.let { tabEntityAdapter.openedLayoutConfigPanelAdapter.decode(it) },
cursor.getString(10)?.let { tabEntityAdapter.pageLayoutAdapter.decode(it) },
cursor.getString(11)?.let { tabEntityAdapter.splitViewAdapter.decode(it) },
cursor.getDouble(12)!!,
cursor.getDouble(13)!!,
cursor.getLong(14)!!
)
}
public fun selectAll(): Query<TabEntity> = selectAll { id, windowId, title, filePath, position,
linkedTabId, zoom, widthPercentage, zoomMode, openedLayoutConfigPanel, pageLayout, splitView,
configPanelWidth, styleConfigPanelWidth, isSaved ->
TabEntity(
id,
windowId,
title,
filePath,
position,
linkedTabId,
zoom,
widthPercentage,
zoomMode,
openedLayoutConfigPanel,
pageLayout,
splitView,
configPanelWidth,
styleConfigPanelWidth,
isSaved
)
}
public fun <T : Any> selectAllByWindowId(windowId: String, mapper: (
id: String,
windowId: String,
title: String,
filePath: String?,
position: Long,
linkedTabId: String?,
zoom: Double,
widthPercentage: Double,
zoomMode: ZoomMode?,
openedLayoutConfigPanel: LayoutConfig.Panel?,
pageLayout: LayoutConfig.PageLayout?,
splitView: LayoutConfig.SplitView?,
configPanelWidth: Double,
styleConfigPanelWidth: Double,
isSaved: Long,
) -> T): Query<T> = SelectAllByWindowIdQuery(windowId) { cursor ->
mapper(
cursor.getString(0)!!,
cursor.getString(1)!!,
cursor.getString(2)!!,
cursor.getString(3),
cursor.getLong(4)!!,
cursor.getString(5),
cursor.getDouble(6)!!,
cursor.getDouble(7)!!,
cursor.getString(8)?.let { tabEntityAdapter.zoomModeAdapter.decode(it) },
cursor.getString(9)?.let { tabEntityAdapter.openedLayoutConfigPanelAdapter.decode(it) },
cursor.getString(10)?.let { tabEntityAdapter.pageLayoutAdapter.decode(it) },
cursor.getString(11)?.let { tabEntityAdapter.splitViewAdapter.decode(it) },
cursor.getDouble(12)!!,
cursor.getDouble(13)!!,
cursor.getLong(14)!!
)
}
public fun selectAllByWindowId(windowId: String): Query<TabEntity> =
selectAllByWindowId(windowId) { id, windowId_, title, filePath, position, linkedTabId, zoom,
widthPercentage, zoomMode, openedLayoutConfigPanel, pageLayout, splitView, configPanelWidth,
styleConfigPanelWidth, isSaved ->
TabEntity(
id,
windowId_,
title,
filePath,
position,
linkedTabId,
zoom,
widthPercentage,
zoomMode,
openedLayoutConfigPanel,
pageLayout,
splitView,
configPanelWidth,
styleConfigPanelWidth,
isSaved
)
}
public fun insert(tabEntity: TabEntity) {
driver.execute(-618_053_309, """
|INSERT OR REPLACE INTO tabEntity(id, windowId, title, filePath, position, linkedTabId, zoom, widthPercentage,
|zoomMode, configPanelWidth , styleConfigPanelWidth , isSaved )
|VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""".trimMargin(), 12) {
bindString(0, tabEntity.id)
bindString(1, tabEntity.windowId)
bindString(2, tabEntity.title)
bindString(3, tabEntity.filePath)
bindLong(4, tabEntity.position)
bindString(5, tabEntity.linkedTabId)
bindDouble(6, tabEntity.zoom)
bindDouble(7, tabEntity.widthPercentage)
bindString(8, tabEntity.zoomMode?.let { tabEntityAdapter.zoomModeAdapter.encode(it) })
bindDouble(9, tabEntity.configPanelWidth)
bindDouble(10, tabEntity.styleConfigPanelWidth)
bindLong(11, tabEntity.isSaved)
}
notifyQueries(-618_053_309) { emit ->
emit("tabEntity")
}
}
public fun updatePosition(position: Long, id: String) {
driver.execute(-441_536_100, """
|UPDATE tabEntity
|SET position = ?
|WHERE id = ?
""".trimMargin(), 2) {
bindLong(0, position)
bindString(1, id)
}
notifyQueries(-441_536_100) { emit ->
emit("tabEntity")
}
}
public fun updateTitle(title: String, id: String) {
driver.execute(-57_338_171, """
|UPDATE tabEntity
|SET title = ?
|WHERE id = ?
""".trimMargin(), 2) {
bindString(0, title)
bindString(1, id)
}
notifyQueries(-57_338_171) { emit ->
emit("tabEntity")
}
}
public fun updateZoom(zoom: Double, id: String) {
driver.execute(1_799_450_054, """
|UPDATE tabEntity
|SET zoom = ?
|WHERE id = ?
""".trimMargin(), 2) {
bindDouble(0, zoom)
bindString(1, id)
}
notifyQueries(1_799_450_054) { emit ->
emit("tabEntity")
}
}
public fun updateZoomMode(zoomMode: ZoomMode?, id: String) {
driver.execute(-305_280_887, """
|UPDATE tabEntity
|SET zoomMode = ?
|WHERE id = ?
""".trimMargin(), 2) {
bindString(0, zoomMode?.let { tabEntityAdapter.zoomModeAdapter.encode(it) })
bindString(1, id)
}
notifyQueries(-305_280_887) { emit ->
emit("tabEntity")
}
}
public fun updateFilePath(filePath: String?, id: String) {
driver.execute(-1_925_003_212, """
|UPDATE tabEntity
|SET filePath = ?
|WHERE id = ?
""".trimMargin(), 2) {
bindString(0, filePath)
bindString(1, id)
}
notifyQueries(-1_925_003_212) { emit ->
emit("tabEntity")
}
}
public fun updateLinkedTabId(linkedTabId: String?, id: String) {
driver.execute(501_790_628, """
|UPDATE tabEntity
|SET linkedTabId = ?
|WHERE id = ?
""".trimMargin(), 2) {
bindString(0, linkedTabId)
bindString(1, id)
}
notifyQueries(501_790_628) { emit ->
emit("tabEntity")
}
}
public fun updateWidthPercentage(widthPercentage: Double, id: String) {
driver.execute(-1_557_394_131, """
|UPDATE tabEntity
|SET widthPercentage = ?
|WHERE id = ?
""".trimMargin(), 2) {
bindDouble(0, widthPercentage)
bindString(1, id)
}
notifyQueries(-1_557_394_131) { emit ->
emit("tabEntity")
}
}
public fun updatePanelsWidthPercentage(configPanelWidth: Double, styleConfigPanelWidth: Double) {
driver.execute(1_478_319_230, """
|UPDATE tabEntity
|SET configPanelWidth = ?,
| styleConfigPanelWidth = ?
""".trimMargin(), 2) {
bindDouble(0, configPanelWidth)
bindDouble(1, styleConfigPanelWidth)
}
notifyQueries(1_478_319_230) { emit ->
emit("tabEntity")
}
}
public fun updateOpenedLayoutConfigPanel(layoutConfigPanel: LayoutConfig.Panel?, id: String) {
driver.execute(-1_805_711_332, """
|UPDATE tabEntity
|SET openedLayoutConfigPanel = ?
|WHERE id = ?
""".trimMargin(), 2) {
bindString(0, layoutConfigPanel?.let {
tabEntityAdapter.openedLayoutConfigPanelAdapter.encode(it) })
bindString(1, id)
}
notifyQueries(-1_805_711_332) { emit ->
emit("tabEntity")
}
}
public fun updatePageLayout(pageLayout: LayoutConfig.PageLayout?, id: String) {
driver.execute(573_942_348, """
|UPDATE tabEntity
|SET pageLayout = ?
|WHERE id = ?
""".trimMargin(), 2) {
bindString(0, pageLayout?.let { tabEntityAdapter.pageLayoutAdapter.encode(it) })
bindString(1, id)
}
notifyQueries(573_942_348) { emit ->
emit("tabEntity")
}
}
public fun updateSplitView(splitView: LayoutConfig.SplitView?, id: String) {
driver.execute(-2_105_433_396, """
|UPDATE tabEntity
|SET splitView = ?
|WHERE id = ?
""".trimMargin(), 2) {
bindString(0, splitView?.let { tabEntityAdapter.splitViewAdapter.encode(it) })
bindString(1, id)
}
notifyQueries(-2_105_433_396) { emit ->
emit("tabEntity")
}
}
public fun updateIsSaved(isSaved: Long, id: String) {
driver.execute(-184_506_198, """
|UPDATE tabEntity
|SET isSaved = ?
|WHERE id = ?
""".trimMargin(), 2) {
bindLong(0, isSaved)
bindString(1, id)
}
notifyQueries(-184_506_198) { emit ->
emit("tabEntity")
}
}
public fun delete(id: String) {
driver.execute(-769_719_243, """
|DELETE FROM tabEntity
|WHERE id = ?
""".trimMargin(), 1) {
bindString(0, id)
}
notifyQueries(-769_719_243) { emit ->
emit("tabEntity")
}
}
public fun deleteAll() {
driver.execute(124_491_052, """DELETE FROM tabEntity""", 0)
notifyQueries(124_491_052) { emit ->
emit("tabEntity")
}
}
private inner class SelectOneQuery<out T : Any>(
public val id: String,
mapper: (SqlCursor) -> T,
) : Query<T>(mapper) {
override fun addListener(listener: Query.Listener) {
driver.addListener("tabEntity", listener = listener)
}
override fun removeListener(listener: Query.Listener) {
driver.removeListener("tabEntity", listener = listener)
}
override fun <R> execute(mapper: (SqlCursor) -> QueryResult<R>): QueryResult<R> =
driver.executeQuery(-1_232_761_600, """
|SELECT *
|FROM tabEntity
|WHERE id = ?
""".trimMargin(), mapper, 1) {
bindString(0, id)
}
override fun toString(): String = "TabEntity.sq:selectOne"
}
private inner class SelectAllByWindowIdQuery<out T : Any>(
public val windowId: String,
mapper: (SqlCursor) -> T,
) : Query<T>(mapper) {
override fun addListener(listener: Query.Listener) {
driver.addListener("tabEntity", listener = listener)
}
override fun removeListener(listener: Query.Listener) {
driver.removeListener("tabEntity", listener = listener)
}
override fun <R> execute(mapper: (SqlCursor) -> QueryResult<R>): QueryResult<R> = driver.executeQuery(-753_714_883, """
|SELECT *
|FROM tabEntity
|WHERE windowId = ?
""".trimMargin(), mapper, 1) {
bindString(0, windowId)
}
override fun toString(): String = "TabEntity.sq:selectAllByWindowId"
}
}
griffio
10/05/2023, 8:33 AMcollect
. The other parts seem ok as per docs.dhia chemingui
10/07/2023, 6:57 PM