Skip to content

Commit

Permalink
Merge pull request #22 from ty1824/queryImprovements
Browse files Browse the repository at this point in the history
Add utility functions to database API
  • Loading branch information
ty1824 authored May 17, 2023
2 parents 5c65df5 + 264d07d commit 842d864
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions inkt/src/main/kotlin/dev/dialector/inkt/next/QueryDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,23 @@ public interface QueryDatabase {
*/
public fun <T> writeTransaction(body: DatabaseContext.() -> T): T
}

/**
* Convenience function to execute a single query in a read transaction.
*/
public fun <K : Any, V> QueryDatabase.query(definition: QueryDefinition<K, V>, key: K): V =
readTransaction { query(definition, key) }

/**
* Convenience function to set a single query value in a write transaction.
*/
public fun <K : Any, V> QueryDatabase.set(definition: QueryDefinition<K, V>, key: K, value: V) {
writeTransaction { set(definition, key, value) }
}

/**
* Convenience function to remove a single query value in a write transaction.
*/
public fun <K : Any, V> QueryDatabase.remove(definition: QueryDefinition<K, V>, key: K) {
writeTransaction { remove(definition, key) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ public class QueryDatabaseImpl : QueryDatabase {
return true
}

val anyDepsChanged = value.dependencies.any { dep ->
val noDepsChanged = value.dependencies.none { dep ->
get(dep)?.let { maybeChangedAfter(context, dep, it, value.verifiedAt) } ?: true
}

if (!anyDepsChanged) {
if (noDepsChanged) {
value.verifiedAt = currentRevision
}

Expand Down

0 comments on commit 842d864

Please sign in to comment.