-
-
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.
- Loading branch information
1 parent
9bc111a
commit 659181b
Showing
5 changed files
with
60 additions
and
4 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
15 changes: 15 additions & 0 deletions
15
...monMain/kotlin/io/github/reactivecircus/kstreamlined/kmp/persistence/database/adapters.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,15 @@ | ||
package io.github.reactivecircus.kstreamlined.kmp.persistence.database | ||
|
||
import app.cash.sqldelight.ColumnAdapter | ||
import kotlinx.datetime.Instant | ||
import kotlinx.datetime.toInstant | ||
|
||
public val InstantAdapter: ColumnAdapter<Instant, String> = object : ColumnAdapter<Instant, String> { | ||
override fun decode(databaseValue: String): Instant { | ||
return databaseValue.toInstant() | ||
} | ||
|
||
override fun encode(value: Instant): String { | ||
return value.toString() | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...light/io/github/reactivecircus/kstreamlined/kmp/persistence/database/FeedIOriginEntity.sq
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,17 @@ | ||
import kotlin.Boolean; | ||
|
||
CREATE TABLE feedOriginEntity ( | ||
key TEXT NOT NULL PRIMARY KEY, | ||
title TEXT NOT NULL, | ||
description TEXT NOT NULL, | ||
selected INTEGER AS Boolean NOT NULL | ||
); | ||
|
||
CREATE INDEX index_feedOriginEntity_selected ON feedOriginEntity(selected); | ||
|
||
allFeedOrigins: | ||
SELECT * FROM feedOriginEntity; | ||
|
||
upsertFeedOrigin: | ||
INSERT OR REPLACE INTO feedOriginEntity | ||
VALUES (:key, :title, :description, :selected); |
26 changes: 22 additions & 4 deletions
26
...ldelight/io/github/reactivecircus/kstreamlined/kmp/persistence/database/FeedItemEntity.sq
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 |
---|---|---|
@@ -1,11 +1,29 @@ | ||
import kotlin.Boolean; | ||
import kotlinx.datetime.Instant; | ||
|
||
CREATE TABLE feedItemEntity ( | ||
id TEXT NOT NULL PRIMARY KEY, | ||
feedOriginKey TEXT NOT NULL, | ||
title TEXT NOT NULL, | ||
publishTime TEXT NOT NULL, | ||
savedForLater INTEGER AS Boolean NOT NULL | ||
publishTime TEXT AS Instant NOT NULL, | ||
contentUrl TEXT NOT NULL, | ||
imageUrl TEXT, | ||
savedForLater INTEGER AS Boolean NOT NULL, | ||
FOREIGN KEY(feedOriginKey) REFERENCES feedOriginEntity(key) ON DELETE CASCADE | ||
); | ||
|
||
findAllFeedItems: | ||
SELECT * FROM feedItemEntity; | ||
CREATE INDEX index_feedItemEntity_feedOriginKey ON feedItemEntity(feedOriginKey); | ||
CREATE INDEX index_feedItemEntity_savedForLater ON feedItemEntity(savedForLater); | ||
|
||
feedItemsForSelectedOrigins: | ||
SELECT feedItemEntity.* FROM feedItemEntity | ||
JOIN feedOriginEntity ON feedItemEntity.feedOriginKey = feedOriginEntity.key | ||
WHERE feedOriginEntity.selected = 1 | ||
ORDER BY feedItemEntity.publishTime DESC; | ||
|
||
savedFeedItems: | ||
SELECT * FROM feedItemEntity WHERE savedForLater = 1 ORDER BY publishTime DESC; | ||
|
||
upsertFeedItem: | ||
INSERT OR REPLACE INTO feedItemEntity | ||
VALUES (:id, :feedOriginKey, :title, :publishTime, :contentUrl, :imageUrl, :savedForLater); |