Skip to content

Commit

Permalink
Merge pull request #82 from infinum/develop
Browse files Browse the repository at this point in the history
Add history feature
  • Loading branch information
bojankoma authored Feb 24, 2021
2 parents d92dc15 + e292f58 commit 9c4c3d3
Show file tree
Hide file tree
Showing 85 changed files with 1,423 additions and 107 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ on:
- '*'

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Save Gradle Caches
uses: actions/cache@v2
with:
path: ~/.gradle/caches/
key: gradle-caches-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-caches-${{ runner.os }}-
- name: Lint
run: ./gradlew lintAll
- name: Stop Gradle
run: ./gradlew --stop

detekt:
name: Detekt
runs-on: ubuntu-latest
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

## Version 5.2.7

_2021-02-24_

* Implement history in editor.
* Fix word tokenization in editor.

## Version 5.2.6

_2021-02-18_
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ Then add the following dependencies in your app `build.gradle` or `build.gradle.

**Groovy**
```groovy
debugImplementation "com.infinum.dbinspector:dbinspector:5.2.6"
releaseImplementation "com.infinum.dbinspector:dbinspector-no-op:5.2.6"
debugImplementation "com.infinum.dbinspector:dbinspector:5.2.7"
releaseImplementation "com.infinum.dbinspector:dbinspector-no-op:5.2.7"
```
**KotlinDSL**
```kotlin
debugImplementation("com.infinum.dbinspector:dbinspector:5.2.6")
releaseImplementation("com.infinum.dbinspector:dbinspector-no-op:5.2.6")
debugImplementation("com.infinum.dbinspector:dbinspector:5.2.7")
releaseImplementation("com.infinum.dbinspector:dbinspector-no-op:5.2.7")
```

### Usage
Expand Down
20 changes: 14 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ subprojects {
apply from: "$rootDir/dokka.gradle"
}

apply from: "shared.gradle"
apply from: "deploy.gradle"
apply from: "jacoco.gradle"

Expand All @@ -69,35 +68,44 @@ task clean(type: Delete) {
delete rootProject.buildDir
}

task lintAll(dependsOn: [
':dbinspector:lintRelease',
':dbinspector-no-op:lintRelease'
]) {
group = "Verification"
description = "Run Lint on all modules"
}

task detektAll(dependsOn: [
':dbinspector:detekt',
':dbinspector-no-op:detekt'
]) {
group = "Verification"
description = "Run detekt on all modules"
description = "Run Detekt on all modules"
}

task ktlintAll(dependsOn: [
':dbinspector:ktlintCheck',
':dbinspector-no-op:ktlintCheck'
]) {
group = "Verification"
description = "Run ktlintCheck on all modules"
description = "Run Ktlint on all modules"
}

task cpdAll(dependsOn: [
':dbinspector:cpdCheck',
':dbinspector-no-op:cpdCheck'
]) {
group = "Verification"
description = "Run cpdCheck on all modules"
description = "Run CPD on all modules"
}

task runStaticChecks(dependsOn: ordered(
task runStaticChecks(dependsOn: [
':lintAll',
':detektAll',
':ktlintAll',
':cpdAll'
)) {
]) {
group = "Verification"
description = "Run static checks on all modules"
}
4 changes: 2 additions & 2 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ext {
]
releaseConfig = [
"group" : "com.infinum.dbinspector",
"version" : "5.2.6",
"versionCode": 5 * 100 * 100 + 2 * 100 + 6
"version" : "5.2.7",
"versionCode": 5 * 100 * 100 + 2 * 100 + 7
]
}
1 change: 1 addition & 0 deletions dbinspector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ dependencies {
implementation packages.koin.scope
implementation packages.koin.viewmodel
implementation packages.timber.core
implementation packages.fuzzy.core
}

apply from: "publish.gradle"
46 changes: 36 additions & 10 deletions dbinspector/src/main/kotlin/com/infinum/dbinspector/data/Data.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.infinum.dbinspector.data

import android.content.Context
import androidx.datastore.core.Serializer
import androidx.datastore.createDataStore
import com.infinum.dbinspector.data.Data.Constants.Name.PROTO_FILENAME_HISTORY
import com.infinum.dbinspector.data.Data.Constants.Name.PROTO_FILENAME_SETTINGS
import com.infinum.dbinspector.data.models.local.proto.output.HistoryEntity
import com.infinum.dbinspector.data.models.local.proto.output.SettingsEntity
import com.infinum.dbinspector.data.source.local.cursor.PragmaSource
import com.infinum.dbinspector.data.source.local.cursor.RawQuerySource
import com.infinum.dbinspector.data.source.local.cursor.SchemaSource
import com.infinum.dbinspector.data.source.local.proto.DataStoreFactory
import com.infinum.dbinspector.data.source.local.proto.history.HistoryDataStore
import com.infinum.dbinspector.data.source.local.proto.history.HistorySerializer
import com.infinum.dbinspector.data.source.local.proto.settings.SettingsDataStore
import com.infinum.dbinspector.data.source.local.proto.settings.SettingsSerializer
import com.infinum.dbinspector.data.source.memory.connection.AndroidConnectionSource
import com.infinum.dbinspector.data.source.memory.pagination.CursorPaginator
Expand All @@ -27,12 +34,18 @@ internal object Data {
object Settings {
const val LINES_LIMIT_MAXIMUM = 100
}

object Name {
const val PROTO_FILENAME_SETTINGS = "settings-entity.pb"
const val PROTO_FILENAME_HISTORY = "history-entity.pb"
}
}

object Qualifiers {

object Name {
val DATASTORE_SETTINGS = StringQualifier("data.qualifiers.name.datastore.settings")
val DATASTORE_HISTORY = StringQualifier("data.qualifiers.name.datastore.history")
}

object Schema {
Expand Down Expand Up @@ -92,15 +105,28 @@ internal object Data {
}

private fun local() = module {
single(qualifier = Qualifiers.Name.DATASTORE_SETTINGS) { "settings-entity.pb" }

single<Serializer<SettingsEntity>> { SettingsSerializer() }

single<Sources.Local.Store> {
DataStoreFactory(
get(),
get(qualifier = Qualifiers.Name.DATASTORE_SETTINGS),
get()
single(qualifier = Qualifiers.Name.DATASTORE_SETTINGS) { PROTO_FILENAME_SETTINGS }
single(qualifier = Qualifiers.Name.DATASTORE_HISTORY) { PROTO_FILENAME_HISTORY }

single<Serializer<SettingsEntity>>(qualifier = Qualifiers.Name.DATASTORE_SETTINGS) { SettingsSerializer() }
single<Serializer<HistoryEntity>>(qualifier = Qualifiers.Name.DATASTORE_HISTORY) { HistorySerializer() }

single<Sources.Local.Settings> {
val context: Context = get()
SettingsDataStore(
context.createDataStore(
fileName = get(qualifier = Qualifiers.Name.DATASTORE_SETTINGS),
serializer = get(qualifier = Qualifiers.Name.DATASTORE_SETTINGS)
)
)
}
single<Sources.Local.History> {
val context: Context = get()
HistoryDataStore(
context.createDataStore(
fileName = get(qualifier = Qualifiers.Name.DATASTORE_HISTORY),
serializer = get(qualifier = Qualifiers.Name.DATASTORE_HISTORY)
)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.infinum.dbinspector.data

import android.database.sqlite.SQLiteDatabase
import androidx.datastore.core.DataStore
import com.infinum.dbinspector.data.models.local.cursor.input.Query
import com.infinum.dbinspector.data.models.local.cursor.output.QueryResult
import com.infinum.dbinspector.data.models.local.proto.output.HistoryEntity
import com.infinum.dbinspector.data.models.local.proto.output.SettingsEntity
import com.infinum.dbinspector.data.shared.base.BaseStore
import com.infinum.dbinspector.domain.database.models.Operation
import java.io.File

Expand Down Expand Up @@ -32,12 +33,9 @@ internal interface Sources {

interface Local {

interface Store {
interface Settings : BaseStore<SettingsEntity>

suspend fun settings(): DataStore<SettingsEntity>

suspend fun current(): SettingsEntity
}
interface History : BaseStore<HistoryEntity>

interface Schema {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.infinum.dbinspector.data.models.local.proto.input

import com.infinum.dbinspector.data.models.local.proto.output.HistoryEntity

internal data class HistoryTask(
val databasePath: String? = null,
val execution: HistoryEntity.ExecutionEntity? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.infinum.dbinspector.data.shared.base

import androidx.datastore.core.DataStore
import kotlinx.coroutines.flow.Flow

internal interface BaseStore<OutputModel> {

suspend fun store(): DataStore<OutputModel> = throw NotImplementedError()

suspend fun current(): OutputModel = throw NotImplementedError()

fun flow(): Flow<OutputModel> = throw NotImplementedError()
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class PragmaSource(
private val tableInfoPaginator: Paginator,
private val foreignKeysPaginator: Paginator,
private val indexesPaginator: Paginator,
private val store: Sources.Local.Store
private val store: Sources.Local.Settings
) : CursorSource(), Sources.Local.Pragma {

override suspend fun getUserVersion(query: Query): QueryResult =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kotlinx.coroutines.suspendCancellableCoroutine

internal class RawQuerySource(
private val rawQueryPaginator: Paginator,
private val store: Sources.Local.Store
private val store: Sources.Local.Settings
) : CursorSource(), Sources.Local.RawQuery {

override suspend fun rawQueryHeaders(query: Query): QueryResult =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class SchemaSource(
private val triggersPaginator: Paginator,
private val triggerByNamePaginator: Paginator,
private val dropTriggerPaginator: Paginator,
private val store: Sources.Local.Store
private val store: Sources.Local.Settings
) : CursorSource(), Sources.Local.Schema {

// region Tables
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.infinum.dbinspector.data.source.local.proto.history

import androidx.datastore.core.DataStore
import com.infinum.dbinspector.data.Sources
import com.infinum.dbinspector.data.models.local.proto.output.HistoryEntity
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.firstOrNull

internal class HistoryDataStore(
private val store: DataStore<HistoryEntity>
) : Sources.Local.History {

override suspend fun store(): DataStore<HistoryEntity> = store

override suspend fun current(): HistoryEntity =
store.data.firstOrNull() ?: HistoryEntity.getDefaultInstance()

override fun flow(): Flow<HistoryEntity> =
store.data
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.infinum.dbinspector.data.source.local.proto.history

import androidx.datastore.core.CorruptionException
import androidx.datastore.core.Serializer
import com.google.protobuf.InvalidProtocolBufferException
import com.infinum.dbinspector.data.models.local.proto.output.HistoryEntity
import java.io.InputStream
import java.io.OutputStream

internal class HistorySerializer : Serializer<HistoryEntity> {

override val defaultValue: HistoryEntity =
HistoryEntity.getDefaultInstance()

override fun readFrom(input: InputStream): HistoryEntity {
try {
return HistoryEntity.parseFrom(input)
} catch (exception: InvalidProtocolBufferException) {
throw CorruptionException("Cannot read proto.", exception)
}
}

override fun writeTo(t: HistoryEntity, output: OutputStream) =
t.writeTo(output)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.infinum.dbinspector.data.source.local.proto.settings

import androidx.datastore.core.DataStore
import com.infinum.dbinspector.data.Sources
import com.infinum.dbinspector.data.models.local.proto.output.SettingsEntity
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.firstOrNull

internal class SettingsDataStore(
private val store: DataStore<SettingsEntity>
) : Sources.Local.Settings {

override suspend fun store(): DataStore<SettingsEntity> = store

override suspend fun current(): SettingsEntity =
store.data.firstOrNull() ?: SettingsEntity.getDefaultInstance()

override fun flow(): Flow<SettingsEntity> =
store.data
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ internal interface Control {
interface Pragma : BaseControl<Mappers.Pragma, Converters.Pragma>

interface Settings : BaseControl<Mappers.Settings, Converters.Settings>

interface History : BaseControl<Mappers.History, Converters.History>
}
Loading

0 comments on commit 9c4c3d3

Please sign in to comment.