-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
55 changed files
with
1,448 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
209 changes: 209 additions & 0 deletions
209
...room/schemas/io.github.taetae98coding.diary.core.diary.database.room.DiaryDatabase/2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 2, | ||
"identityHash": "8e6b08fa78bcbc993963c679fe1d6ce9", | ||
"entities": [ | ||
{ | ||
"tableName": "MemoEntity", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL DEFAULT '', `title` TEXT NOT NULL DEFAULT '', `description` TEXT NOT NULL DEFAULT '', `start` TEXT DEFAULT null, `endInclusive` TEXT DEFAULT null, `color` INTEGER NOT NULL DEFAULT -16777216, `isFinish` INTEGER NOT NULL DEFAULT 0, `isDelete` INTEGER NOT NULL DEFAULT 0, `owner` TEXT DEFAULT null, `updateAt` INTEGER NOT NULL DEFAULT 0, `serverUpdateAt` INTEGER DEFAULT null, PRIMARY KEY(`id`))", | ||
"fields": [ | ||
{ | ||
"fieldPath": "id", | ||
"columnName": "id", | ||
"affinity": "TEXT", | ||
"notNull": true, | ||
"defaultValue": "''" | ||
}, | ||
{ | ||
"fieldPath": "title", | ||
"columnName": "title", | ||
"affinity": "TEXT", | ||
"notNull": true, | ||
"defaultValue": "''" | ||
}, | ||
{ | ||
"fieldPath": "description", | ||
"columnName": "description", | ||
"affinity": "TEXT", | ||
"notNull": true, | ||
"defaultValue": "''" | ||
}, | ||
{ | ||
"fieldPath": "start", | ||
"columnName": "start", | ||
"affinity": "TEXT", | ||
"defaultValue": "null" | ||
}, | ||
{ | ||
"fieldPath": "endInclusive", | ||
"columnName": "endInclusive", | ||
"affinity": "TEXT", | ||
"defaultValue": "null" | ||
}, | ||
{ | ||
"fieldPath": "color", | ||
"columnName": "color", | ||
"affinity": "INTEGER", | ||
"notNull": true, | ||
"defaultValue": "-16777216" | ||
}, | ||
{ | ||
"fieldPath": "isFinish", | ||
"columnName": "isFinish", | ||
"affinity": "INTEGER", | ||
"notNull": true, | ||
"defaultValue": "0" | ||
}, | ||
{ | ||
"fieldPath": "isDelete", | ||
"columnName": "isDelete", | ||
"affinity": "INTEGER", | ||
"notNull": true, | ||
"defaultValue": "0" | ||
}, | ||
{ | ||
"fieldPath": "owner", | ||
"columnName": "owner", | ||
"affinity": "TEXT", | ||
"defaultValue": "null" | ||
}, | ||
{ | ||
"fieldPath": "updateAt", | ||
"columnName": "updateAt", | ||
"affinity": "INTEGER", | ||
"notNull": true, | ||
"defaultValue": "0" | ||
}, | ||
{ | ||
"fieldPath": "serverUpdateAt", | ||
"columnName": "serverUpdateAt", | ||
"affinity": "INTEGER", | ||
"defaultValue": "null" | ||
} | ||
], | ||
"primaryKey": { | ||
"autoGenerate": false, | ||
"columnNames": [ | ||
"id" | ||
] | ||
} | ||
}, | ||
{ | ||
"tableName": "TagEntity", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL DEFAULT '', `title` TEXT NOT NULL DEFAULT '', `description` TEXT NOT NULL DEFAULT '', `color` INTEGER NOT NULL DEFAULT -16777216, `isFinish` INTEGER NOT NULL DEFAULT 0, `isDelete` INTEGER NOT NULL DEFAULT 0, `owner` TEXT DEFAULT null, `updateAt` INTEGER NOT NULL DEFAULT 0, `serverUpdateAt` INTEGER DEFAULT null, PRIMARY KEY(`id`))", | ||
"fields": [ | ||
{ | ||
"fieldPath": "id", | ||
"columnName": "id", | ||
"affinity": "TEXT", | ||
"notNull": true, | ||
"defaultValue": "''" | ||
}, | ||
{ | ||
"fieldPath": "title", | ||
"columnName": "title", | ||
"affinity": "TEXT", | ||
"notNull": true, | ||
"defaultValue": "''" | ||
}, | ||
{ | ||
"fieldPath": "description", | ||
"columnName": "description", | ||
"affinity": "TEXT", | ||
"notNull": true, | ||
"defaultValue": "''" | ||
}, | ||
{ | ||
"fieldPath": "color", | ||
"columnName": "color", | ||
"affinity": "INTEGER", | ||
"notNull": true, | ||
"defaultValue": "-16777216" | ||
}, | ||
{ | ||
"fieldPath": "isFinish", | ||
"columnName": "isFinish", | ||
"affinity": "INTEGER", | ||
"notNull": true, | ||
"defaultValue": "0" | ||
}, | ||
{ | ||
"fieldPath": "isDelete", | ||
"columnName": "isDelete", | ||
"affinity": "INTEGER", | ||
"notNull": true, | ||
"defaultValue": "0" | ||
}, | ||
{ | ||
"fieldPath": "owner", | ||
"columnName": "owner", | ||
"affinity": "TEXT", | ||
"defaultValue": "null" | ||
}, | ||
{ | ||
"fieldPath": "updateAt", | ||
"columnName": "updateAt", | ||
"affinity": "INTEGER", | ||
"notNull": true, | ||
"defaultValue": "0" | ||
}, | ||
{ | ||
"fieldPath": "serverUpdateAt", | ||
"columnName": "serverUpdateAt", | ||
"affinity": "INTEGER", | ||
"defaultValue": "null" | ||
} | ||
], | ||
"primaryKey": { | ||
"autoGenerate": false, | ||
"columnNames": [ | ||
"id" | ||
] | ||
} | ||
}, | ||
{ | ||
"tableName": "MemoBackupEntity", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uid` TEXT NOT NULL, `memoId` TEXT NOT NULL, PRIMARY KEY(`uid`, `memoId`), FOREIGN KEY(`memoId`) REFERENCES `MemoEntity`(`id`) ON UPDATE CASCADE ON DELETE CASCADE )", | ||
"fields": [ | ||
{ | ||
"fieldPath": "uid", | ||
"columnName": "uid", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "memoId", | ||
"columnName": "memoId", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"autoGenerate": false, | ||
"columnNames": [ | ||
"uid", | ||
"memoId" | ||
] | ||
}, | ||
"foreignKeys": [ | ||
{ | ||
"table": "MemoEntity", | ||
"onDelete": "CASCADE", | ||
"onUpdate": "CASCADE", | ||
"columns": [ | ||
"memoId" | ||
], | ||
"referencedColumns": [ | ||
"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, '8e6b08fa78bcbc993963c679fe1d6ce9')" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...onMain/kotlin/io/github/taetae98coding/diary/core/diary/database/room/dao/TagEntityDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.github.taetae98coding.diary.core.diary.database.room.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Query | ||
import io.github.taetae98coding.diary.core.diary.database.room.entity.TagEntity | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
internal abstract class TagEntityDao : EntityDao<TagEntity>() { | ||
@Query( | ||
""" | ||
SELECT * | ||
FROM TagEntity | ||
WHERE id = :tagId | ||
""", | ||
) | ||
abstract fun find(tagId: String): Flow<TagEntity?> | ||
|
||
@Query( | ||
""" | ||
SELECT * | ||
FROM TagEntity | ||
WHERE isDelete = 0 | ||
AND (owner = :owner OR (owner IS NULL AND :owner IS NULL)) | ||
ORDER BY title | ||
""", | ||
) | ||
abstract fun page(owner: String?): Flow<List<TagEntity>> | ||
} |
32 changes: 32 additions & 0 deletions
32
...mmonMain/kotlin/io/github/taetae98coding/diary/core/diary/database/room/dao/TagRoomDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.github.taetae98coding.diary.core.diary.database.room.dao | ||
|
||
import io.github.taetae98coding.diary.core.diary.database.TagDao | ||
import io.github.taetae98coding.diary.core.diary.database.room.DiaryDatabase | ||
import io.github.taetae98coding.diary.core.diary.database.room.entity.TagEntity | ||
import io.github.taetae98coding.diary.core.diary.database.room.mapper.toDto | ||
import io.github.taetae98coding.diary.core.diary.database.room.mapper.toEntity | ||
import io.github.taetae98coding.diary.core.model.tag.TagDto | ||
import io.github.taetae98coding.diary.library.coroutines.mapCollectionLatest | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.mapLatest | ||
import org.koin.core.annotation.Factory | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
@Factory | ||
internal class TagRoomDao( | ||
private val database: DiaryDatabase, | ||
) : TagDao { | ||
override suspend fun upsert(tag: TagDto) { | ||
database.tag().upsert(tag.toEntity()) | ||
} | ||
|
||
override fun find(tagId: String): Flow<TagDto?> { | ||
return database.tag().find(tagId).mapLatest { it?.toDto() } | ||
} | ||
|
||
override fun page(owner: String?): Flow<List<TagDto>> { | ||
return database.tag().page(owner) | ||
.mapCollectionLatest(TagEntity::toDto) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...onMain/kotlin/io/github/taetae98coding/diary/core/diary/database/room/entity/TagEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.github.taetae98coding.diary.core.diary.database.room.entity | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import kotlinx.datetime.Instant | ||
|
||
@Entity | ||
internal data class TagEntity( | ||
@PrimaryKey | ||
@ColumnInfo(defaultValue = "") | ||
val id: String, | ||
@ColumnInfo(defaultValue = "") | ||
val title: String, | ||
@ColumnInfo(defaultValue = "") | ||
val description: String, | ||
@ColumnInfo(defaultValue = "-16777216") | ||
val color: Int, | ||
@ColumnInfo(defaultValue = "0") | ||
val isFinish: Boolean, | ||
@ColumnInfo(defaultValue = "0") | ||
val isDelete: Boolean, | ||
@ColumnInfo(defaultValue = "null") | ||
val owner: String?, | ||
@ColumnInfo(defaultValue = "0") | ||
val updateAt: Instant, | ||
@ColumnInfo(defaultValue = "null") | ||
val serverUpdateAt: Instant?, | ||
) |
38 changes: 38 additions & 0 deletions
38
...onMain/kotlin/io/github/taetae98coding/diary/core/diary/database/room/mapper/TagMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.github.taetae98coding.diary.core.diary.database.room.mapper | ||
|
||
import io.github.taetae98coding.diary.core.diary.database.room.entity.MemoEntity | ||
import io.github.taetae98coding.diary.core.diary.database.room.entity.TagEntity | ||
import io.github.taetae98coding.diary.core.model.memo.MemoDetail | ||
import io.github.taetae98coding.diary.core.model.memo.MemoDto | ||
import io.github.taetae98coding.diary.core.model.tag.TagDetail | ||
import io.github.taetae98coding.diary.core.model.tag.TagDto | ||
|
||
internal fun TagDto.toEntity(): TagEntity { | ||
return TagEntity( | ||
id = id, | ||
title = detail.title, | ||
description = detail.description, | ||
color = detail.color, | ||
isFinish = isFinish, | ||
isDelete = isDelete, | ||
owner = owner, | ||
updateAt = updateAt, | ||
serverUpdateAt = serverUpdateAt, | ||
) | ||
} | ||
|
||
internal fun TagEntity.toDto(): TagDto { | ||
return TagDto( | ||
id = id, | ||
detail = TagDetail( | ||
title = title, | ||
description = description, | ||
color = color, | ||
), | ||
owner = owner, | ||
isFinish = isFinish, | ||
isDelete = isDelete, | ||
updateAt = updateAt, | ||
serverUpdateAt = serverUpdateAt, | ||
) | ||
} |
Oops, something went wrong.