Skip to content

Commit

Permalink
Make some data queries shorter
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtakac committed Nov 6, 2022
1 parent 2017201 commit 9f9a9dd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import hr.dtakac.prognoza.data.PlaceQueries
import hr.dtakac.prognoza.domain.place.SavedPlaceGetter
import hr.dtakac.prognoza.domain.place.PlaceSaver
import hr.dtakac.prognoza.entities.Place
import hr.dtakac.prognoza.data.Place as PlaceDbModel
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext

Expand Down Expand Up @@ -50,10 +51,12 @@ class PlaceRepository(
override suspend fun save(place: Place) {
withContext(ioDispatcher) {
placeQueries.insert(
latitude = place.latitude,
longitude = place.longitude,
name = place.name,
details = place.details
PlaceDbModel(
latitude = place.latitude,
longitude = place.longitude,
name = place.name,
details = place.details
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hr.dtakac.prognoza.data.repository

import hr.dtakac.prognoza.data.GetSettings
import hr.dtakac.prognoza.data.Get
import hr.dtakac.prognoza.data.SettingsQueries
import hr.dtakac.prognoza.domain.place.SavedPlaceGetter
import hr.dtakac.prognoza.domain.settings.SettingsRepository
Expand Down Expand Up @@ -56,7 +56,7 @@ class SettingsRepository(
settingsQueries.setWindUnit(unit)
}

private suspend fun getSettings(): GetSettings = withContext(ioDispatcher) {
settingsQueries.getSettings().executeAsOne()
private suspend fun getSettings(): Get = withContext(ioDispatcher) {
settingsQueries.get().executeAsOne()
}
}
3 changes: 1 addition & 2 deletions data/src/main/sqldelight/hr/dtakac/prognoza/data/Place.sq
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ CREATE TABLE IF NOT EXISTS Place (
);

insert:
INSERT OR REPLACE INTO Place (latitude, longitude, name, details)
VALUES (?, ?, ?, ?);
INSERT OR REPLACE INTO Place VALUES ?;

get:
SELECT * FROM Place
Expand Down
7 changes: 3 additions & 4 deletions data/src/main/sqldelight/hr/dtakac/prognoza/data/Settings.sq
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ CREATE TABLE IF NOT EXISTS Settings (
);

-- Prepopulated database
INSERT OR IGNORE INTO Settings (id, temperatureUnit, precipitationUnit, windUnit, pressureUnit, placeLatitude, placeLongitude)
INSERT OR IGNORE INTO Settings
VALUES (0, 0, 0, 0, 0, NULL, NULL);

getSettings:
get:
SELECT temperatureUnit, precipitationUnit, windUnit, pressureUnit, placeLatitude, placeLongitude
FROM Settings
WHERE id = 0;
FROM Settings WHERE id = 0;

setPlace:
UPDATE Settings SET placeLatitude = ?, placeLongitude = ? WHERE id = 0;
Expand Down

0 comments on commit 9f9a9dd

Please sign in to comment.