Skip to content

Commit

Permalink
feat: ✨ 增加了历史记录
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg886 committed Nov 3, 2024
1 parent fe93d03 commit 7fbfcad
Show file tree
Hide file tree
Showing 9 changed files with 502 additions and 26 deletions.
163 changes: 163 additions & 0 deletions composeApp/schemas/top.kagg886.pmf.backend.database.AppDatabase/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
{
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "44ff089e92f51e4fc0030929629d403d",
"entities": [
{
"tableName": "IllustHistory",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `illust` TEXT NOT NULL, `createTime` INTEGER NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "illust",
"columnName": "illust",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "createTime",
"columnName": "createTime",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
}
},
{
"tableName": "NovelHistory",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `novel` TEXT NOT NULL, `createTime` INTEGER NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "novel",
"columnName": "novel",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "createTime",
"columnName": "createTime",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
}
},
{
"tableName": "DownloadItem",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `illust` TEXT NOT NULL, `success` INTEGER NOT NULL, `progress` REAL NOT NULL, `createTime` INTEGER NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "illust",
"columnName": "illust",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "success",
"columnName": "success",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "progress",
"columnName": "progress",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "createTime",
"columnName": "createTime",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
}
},
{
"tableName": "SearchHistory",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `initialSort` TEXT NOT NULL, `initialTarget` TEXT NOT NULL, `initialKeyWords` TEXT NOT NULL, `tab` TEXT NOT NULL, `createTime` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "initialSort",
"columnName": "initialSort",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "initialTarget",
"columnName": "initialTarget",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "initialKeyWords",
"columnName": "initialKeyWords",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "tab",
"columnName": "tab",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "createTime",
"columnName": "createTime",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
}
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '44ff089e92f51e4fc0030929629d403d')"
]
}
}
163 changes: 163 additions & 0 deletions composeApp/schemas/top.kagg886.pmf.backend.database.AppDatabase/3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
{
"formatVersion": 1,
"database": {
"version": 3,
"identityHash": "44ff089e92f51e4fc0030929629d403d",
"entities": [
{
"tableName": "IllustHistory",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `illust` TEXT NOT NULL, `createTime` INTEGER NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "illust",
"columnName": "illust",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "createTime",
"columnName": "createTime",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
}
},
{
"tableName": "NovelHistory",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `novel` TEXT NOT NULL, `createTime` INTEGER NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "novel",
"columnName": "novel",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "createTime",
"columnName": "createTime",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
}
},
{
"tableName": "DownloadItem",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `illust` TEXT NOT NULL, `success` INTEGER NOT NULL, `progress` REAL NOT NULL, `createTime` INTEGER NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "illust",
"columnName": "illust",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "success",
"columnName": "success",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "progress",
"columnName": "progress",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "createTime",
"columnName": "createTime",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
}
},
{
"tableName": "SearchHistory",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `initialSort` TEXT NOT NULL, `initialTarget` TEXT NOT NULL, `initialKeyWords` TEXT NOT NULL, `tab` TEXT NOT NULL, `createTime` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "initialSort",
"columnName": "initialSort",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "initialTarget",
"columnName": "initialTarget",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "initialKeyWords",
"columnName": "initialKeyWords",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "tab",
"columnName": "tab",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "createTime",
"columnName": "createTime",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
}
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '44ff089e92f51e4fc0030929629d403d')"
]
}
}
2 changes: 2 additions & 0 deletions composeApp/src/commonMain/kotlin/top/kagg886/pmf/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ fun startKoin0() {
module(createdAtStart = true) {
single {
getDataBaseBuilder()
.fallbackToDestructiveMigrationOnDowngrade(true)
.fallbackToDestructiveMigration(true)
.fallbackToDestructiveMigrationFrom(true,1)
.setDriver(BundledSQLiteDriver())
.setQueryCoroutineContext(Dispatchers.IO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface IllustHistoryDAO {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(item: IllustHistory)

@Query("SELECT * FROM IllustHistory ORDER BY createTime DESC LIMIT :size OFFSET (:page - 1) * 30;")
@Query("SELECT * FROM IllustHistory ORDER BY createTime DESC LIMIT :size OFFSET (:page - 1) * :size;")
suspend fun getByPage(page: Int = 1, size: Int = 30): List<IllustHistory>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface NovelHistoryDAO {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(item: NovelHistory)

@Query("SELECT * FROM NovelHistory ORDER BY createTime DESC LIMIT :size OFFSET (:page - 1) * 30;")
@Query("SELECT * FROM NovelHistory ORDER BY createTime DESC LIMIT :size OFFSET (:page - 1) * :size;")
suspend fun getByPage(page: Int = 1, size: Int = 30): List<NovelHistory>
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package top.kagg886.pmf.backend.database.dao

import androidx.room.*
import kotlinx.coroutines.flow.Flow
import top.kagg886.pixko.module.search.SearchSort
import top.kagg886.pixko.module.search.SearchTarget
import top.kagg886.pmf.ui.route.main.search.SearchTab


@Dao
interface SearchHistoryDAO {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(item: SearchHistory)


@Query("SELECT * FROM SearchHistory ORDER BY createTime DESC")
fun allFlow(): Flow<List<SearchHistory>>

@Delete
suspend fun delete(item: SearchHistory)
}

@Entity
data class SearchHistory(
@PrimaryKey(autoGenerate = true)
val id: Long,
val initialSort:SearchSort,
val initialTarget:SearchTarget,
val initialKeyWords:String,
val tab:SearchTab,
val createTime: Long = System.currentTimeMillis()
)
Loading

0 comments on commit 7fbfcad

Please sign in to comment.