Skip to content

Commit c669f3f

Browse files
committed
updated kstore + begening of SQLDelight update
1 parent 585f806 commit c669f3f

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

docs/src/0.language/README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Language Kotlin
2-
3-
1+
# About Kotlin
42

53
## Table of Contents
64

@@ -10,8 +8,6 @@
108
4. [Lesson 4: Concurrent Programming](#lesson-4-concurrent-programming)
119
5. [Lesson 5: Evolution of Kotlin](#lesson-5-evolution-of-kotlin)
1210

13-
---
14-
1511
## Lesson 1: Kotlin Basics
1612

1713
### Overview

docs/src/8.preferences/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Add a RequestTime object with an updatable timestamp
125125
::: details Quiz.kt (commonMain)
126126
```kotlin
127127
@Serializable
128-
data class RequestTime(val updateTime: Long = 0L )
128+
data class RequestTime(val updateTime: Long = 0L)
129129
```
130130
:::
131131

@@ -167,19 +167,19 @@ class QuizRepository {
167167
private suspend fun fetchQuiz(): List<Question> = quizApiDatasource.getAllQuestions().questions
168168

169169
private suspend fun fetchAndStoreQuiz(): List<Question> {
170-
quizKStoreDataSource.resetQuizKstore()
171170
val questions = fetchQuiz()
172171
//Later on we will store the question in a database SQLite
173172
return questions
174173
}
175174

175+
@OptIn(ExperimentalTime::class)
176176
suspend fun updateQuiz(): List<Question> {
177177
try {
178178
val lastRequest = quizKStoreDataSource.getUpdateTimeStamp()
179179
return if (lastRequest == 0L || lastRequest - Clock.System.now().epochSeconds > 300000) {
180180
fetchAndStoreQuiz()
181181
} else {
182-
quizKStoreDataSource.getAllQuestions()
182+
fetchQuiz() //later on we will fetch from the database
183183
}
184184
} catch (e: NullPointerException) {
185185
return fetchAndStoreQuiz()
@@ -188,7 +188,6 @@ class QuizRepository {
188188
return mockDataSource.generateDummyQuestionsList()
189189
}
190190
}
191-
192191
}
193192
```
194193
:::

docs/src/9.database/README.md

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ to `app.cash.sqldelight.*`
3030
Pay attention also with beta, alpha version of Android studio that could produce bugs on gradle task management for code generation of SQL Delight databases.
3131
:::
3232

33-
34-
35-
3633
## 🧪 Add sqldelight db to your quizz
3734

3835
> Refer to the multiplatform implementation of SQLDelight in official Github pages
@@ -43,41 +40,54 @@ Pay attention also with beta, alpha version of Android studio that could produce
4340
``` kotlin
4441
plugins {
4542
...
46-
id("app.cash.sqldelight") version "2.0.0"
43+
alias(libs.plugins.sqldelight)
4744
}
4845
...
4946
sourceSets {
50-
val commonMain by getting {
51-
dependencies {
47+
commonMain.dependencies {
5248
...
53-
implementation("app.cash.sqldelight:runtime:2.0.0")
54-
implementation("app.cash.sqldelight:coroutines-extensions:2.0.0")
55-
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1")
56-
49+
implementation(libs.sqldelight.runtime)
50+
implementation(libs.sqldelight.coroutines.extensions)
5751
}
58-
}
59-
val androidMain by getting {
60-
dependencies {
52+
53+
androidMain.dependencies {
6154
...
62-
implementation("app.cash.sqldelight:android-driver:2.0.0")
55+
implementation(libs.sqldelight.android.driver)
6356

6457
}
65-
}
6658
...
67-
val iosMain by creating {
68-
...
69-
dependencies {
59+
iosMain.dependencies {
7060
...
71-
implementation("app.cash.sqldelight:native-driver:2.0.0")
61+
implementation(libs.sqldelight.ios.driver)
7262
}
73-
}
74-
val desktopMain by getting {
75-
dependencies {
63+
64+
desktopMain.dependencies {
7665
...
77-
implementation("app.cash.sqldelight:sqlite-driver:2.0.0")
66+
implementation(libs.sqldelight.jvm.driver)
7867
}
68+
69+
wasmJsMain.dependencies {
70+
...
71+
implementation(libs.sqldelight.webworker.driver)
72+
implementation(npm("sql.js", libs.versions.sqlJs.get()))
73+
implementation(devNpm("copy-webpack-plugin", libs.versions.webPackPlugin.get()))
74+
75+
}
76+
7977
}
8078
...
79+
80+
sqldelight {
81+
databases {
82+
create("Database") {
83+
packageName = "com.myapplication.common.cache"
84+
generateAsync = true
85+
verifyMigrations = false
86+
}
87+
}
88+
linkSqlite = true
89+
}
90+
8191
```
8292
#### Create the native SQL driver factory and use it for creating the DB with `actual`/`expect` kotlin keywords
8393

0 commit comments

Comments
 (0)