mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 09:57:04 +05:30
feat(database): add a table for post comments
This commit is contained in:
parent
3e2d32e4c9
commit
1ae0cbb95d
7 changed files with 77 additions and 27 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright © 2021-2022 Harsh Shandilya.
|
||||
* Copyright © 2021-2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
|
@ -15,8 +15,9 @@ import com.squareup.anvil.annotations.ContributesTo
|
|||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dev.msfjarvis.claw.database.LobstersDatabase
|
||||
import dev.msfjarvis.claw.database.local.PostComments
|
||||
import dev.msfjarvis.claw.database.local.SavedPost
|
||||
import dev.msfjarvis.claw.database.model.TagsAdapter
|
||||
import dev.msfjarvis.claw.database.model.CSVAdapter
|
||||
|
||||
@Module
|
||||
@ContributesTo(ApplicationScope::class)
|
||||
|
@ -27,6 +28,10 @@ object DatabaseModule {
|
|||
@Provides
|
||||
fun provideDatabase(@ForScope(ApplicationScope::class) context: Context): LobstersDatabase {
|
||||
val driver = AndroidSqliteDriver(LobstersDatabase.Schema, context, LOBSTERS_DATABASE_NAME)
|
||||
return LobstersDatabase(driver, SavedPost.Adapter(IntColumnAdapter, TagsAdapter()))
|
||||
return LobstersDatabase(
|
||||
driver,
|
||||
PostComments.Adapter(CSVAdapter()),
|
||||
SavedPost.Adapter(IntColumnAdapter, CSVAdapter()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2021-2022 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.database.local
|
||||
|
||||
import android.content.Context
|
||||
import app.cash.sqldelight.adapter.primitive.IntColumnAdapter
|
||||
import app.cash.sqldelight.driver.android.AndroidSqliteDriver
|
||||
import dev.msfjarvis.claw.database.LobstersDatabase
|
||||
import dev.msfjarvis.claw.database.model.TagsAdapter
|
||||
|
||||
internal const val LobstersDatabaseName = "SavedPosts.db"
|
||||
|
||||
fun createDatabase(context: Context): LobstersDatabase {
|
||||
val driver = AndroidSqliteDriver(LobstersDatabase.Schema, context, LobstersDatabaseName)
|
||||
return LobstersDatabase(driver, SavedPost.Adapter(IntColumnAdapter, TagsAdapter()))
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright © 2021-2022 Harsh Shandilya.
|
||||
* Copyright © 2021-2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
|
@ -8,7 +8,7 @@ package dev.msfjarvis.claw.database.model
|
|||
|
||||
import app.cash.sqldelight.ColumnAdapter
|
||||
|
||||
class TagsAdapter : ColumnAdapter<List<String>, String> {
|
||||
class CSVAdapter : ColumnAdapter<List<String>, String> {
|
||||
override fun decode(databaseValue: String): List<String> {
|
||||
return databaseValue.split(SEPARATOR)
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,17 @@
|
|||
import kotlin.String;
|
||||
import kotlin.collections.List;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS PostComments(
|
||||
postId TEXT NOT NULL PRIMARY KEY,
|
||||
commentIds TEXT AS List<String> NOT NULL
|
||||
);
|
||||
|
||||
rememberComments:
|
||||
INSERT OR REPLACE
|
||||
INTO PostComments
|
||||
VALUES ?;
|
||||
|
||||
getCommentIds:
|
||||
SELECT *
|
||||
FROM PostComments
|
||||
WHERE postId = ?;
|
Loading…
Add table
Add a link
Reference in a new issue