-
Notifications
You must be signed in to change notification settings - Fork 1
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
928bf43
commit b7fcb56
Showing
12 changed files
with
186 additions
and
45 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
18 changes: 18 additions & 0 deletions
18
core/di/src/main/kotlin/xyz/ksharma/krail/di/CoroutinesModule.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,18 @@ | ||
package xyz.ksharma.krail.di | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.SupervisorJob | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object CoroutinesModule { | ||
|
||
@Provides | ||
fun provideCoroutineScope(@Dispatcher(AppDispatchers.IO) ioDispatcher: CoroutineDispatcher): CoroutineScope = | ||
CoroutineScope(context = ioDispatcher + SupervisorJob()) | ||
} |
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,10 +1,19 @@ | ||
plugins { | ||
alias(libs.plugins.krail.android.library) | ||
alias(libs.plugins.cash.sqldelight) | ||
} | ||
|
||
android { | ||
namespace = "xyz.ksharma.krail.sydney_trains.database.api" | ||
} | ||
|
||
sqldelight { | ||
databases { | ||
create("KrailDB") { | ||
packageName.set("xyz.ksharma.krail") | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
} |
10 changes: 0 additions & 10 deletions
10
...dney-trains/database/api/src/main/kotlin/xyz/ksharma/krail/database/api/SydneyTrainsDB.kt
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
...rains/database/api/src/main/kotlin/xyz/ksharma/krail/database/api/SydneyTrainsStaticDB.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,12 @@ | ||
package xyz.ksharma.krail.database.api | ||
|
||
import xyz.ksharma.krail.StopTimes | ||
|
||
interface SydneyTrainsStaticDB { | ||
|
||
suspend fun insertStopTimes() | ||
|
||
suspend fun clearStopTimes() | ||
|
||
suspend fun getStopTimes(): List<StopTimes> | ||
} |
27 changes: 27 additions & 0 deletions
27
feature/sydney-trains/database/api/src/main/sqldelight/xyz/ksharma/krail/stoptimes.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,27 @@ | ||
CREATE TABLE stopTimes ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
trip_id TEXT NOT NULL, | ||
arrival_time TEXT, | ||
departure_time TEXT, | ||
stop_id TEXT, | ||
stop_sequence INTEGER, | ||
stop_headsign TEXT, | ||
pickup_type INTEGER, | ||
drop_off_type INTEGER | ||
); | ||
|
||
insertIntoStopTime: | ||
INSERT INTO stopTimes ( | ||
trip_id, | ||
arrival_time, | ||
departure_time, | ||
stop_id, | ||
stop_sequence, | ||
stop_headsign, | ||
pickup_type, | ||
drop_off_type | ||
) | ||
VALUES (?, ?, ?, ?, ?, ?, ?, ?); | ||
|
||
selectAll: | ||
SELECT * FROM stopTimes; |
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
58 changes: 58 additions & 0 deletions
58
...sydney-trains/database/real/src/main/kotlin/xyz/ksharma/krail/RealSydneyTrainsStaticDb.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,58 @@ | ||
package xyz.ksharma.krail | ||
|
||
import android.content.Context | ||
import app.cash.sqldelight.driver.android.AndroidSqliteDriver | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Deferred | ||
import kotlinx.coroutines.async | ||
import xyz.ksharma.krail.database.api.SydneyTrainsStaticDB | ||
import xyz.ksharma.krail.di.AppDispatchers | ||
import xyz.ksharma.krail.di.Dispatcher | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class RealSydneyTrainsStaticDb @Inject constructor( | ||
@Dispatcher(AppDispatchers.IO) private val ioDispatcher: CoroutineDispatcher, | ||
coroutineScope: CoroutineScope, | ||
@ApplicationContext private val applicationContext: Context, | ||
) : SydneyTrainsStaticDB { | ||
|
||
private val sydneyTrainsDB: Deferred<KrailDB> by lazy { | ||
coroutineScope.async(ioDispatcher) { | ||
KrailDB( | ||
AndroidSqliteDriver( | ||
KrailDB.Schema, | ||
applicationContext, | ||
"sydney_trains_static.db" | ||
) | ||
) | ||
} | ||
} | ||
|
||
private suspend fun getSydneyTrainsDb(): KrailDB = sydneyTrainsDB.await() | ||
|
||
override suspend fun insertStopTimes() { | ||
getSydneyTrainsDb().stoptimesQueries.insertStopTimes( | ||
trip_id = "id_1", | ||
arrival_time = "arr", | ||
departure_time = "depart", | ||
stop_id = "", | ||
stop_sequence = 1, | ||
stop_headsign = "", | ||
pickup_type = 1, | ||
drop_off_type = 1, | ||
) | ||
} | ||
|
||
override suspend fun getStopTimes(): List<StopTimes> { | ||
val all = getSydneyTrainsDb().stoptimesQueries.selectAll() | ||
return all.executeAsList() | ||
} | ||
|
||
override suspend fun clearStopTimes() { | ||
TODO("Not yet implemented") | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
...e/sydney-trains/database/real/src/main/sqldelight/xyz/ksharma/krail/database/stoptimes.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,32 @@ | ||
CREATE TABLE stopTimes ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
trip_id TEXT NOT NULL, | ||
arrival_time TEXT, | ||
departure_time TEXT, | ||
stop_id TEXT, | ||
stop_sequence INTEGER, | ||
stop_headsign TEXT, | ||
pickup_type INTEGER, | ||
drop_off_type INTEGER | ||
); | ||
|
||
insertIntoStopTime: | ||
INSERT INTO stopTimes ( | ||
trip_id, | ||
arrival_time, | ||
departure_time, | ||
stop_id, | ||
stop_sequence, | ||
stop_headsign, | ||
pickup_type, | ||
drop_off_type | ||
) | ||
VALUES (?, ?, ?, ?, ?, ?, ?, ?); | ||
|
||
selectAll: | ||
<<<<<<<< Updated upstream:feature/sydney-trains/database/real/src/main/sqldelight/xyz/ksharma/krail/database/stoptimes.sq | ||
SELECT * | ||
FROM stopTimes; | ||
======== | ||
SELECT * FROM stopTimes; | ||
>>>>>>>> Stashed changes:feature/sydney-trains/database/api/src/main/sqldelight/xyz/ksharma/krail/stoptimes.sq |
14 changes: 0 additions & 14 deletions
14
feature/sydney-trains/database/real/src/main/sqldelight/xyz/ksharma/krail/stoptimes.sq
This file was deleted.
Oops, something went wrong.