Skip to content

Commit

Permalink
Added README.md
Browse files Browse the repository at this point in the history
lamba92 committed Jul 9, 2024
1 parent c86e7e1 commit 2f7b3ee
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# kotlinx.document.store

A Kotlin Multiplatform embedded nosql document database. kotlinx.document.store is an abstraction on top of platform-specific key-value stores like RocksDB, MVStore, etc. It provides a simple API to store and retrieve documents.

## Features

- **Multiplatform**:
- :done: JVM (MVStore, RocksDB)
`org.github.lamba92:kotlinx-document-store-mvstore:1.0.0-SNAPSHOT`
- :done: JS/Browser (IndexedDB idb-keyval)
`org.github.lamba92:kotlinx-document-store-browser:1.0.0-SNAPSHOT`
- :loading: macOS (RockDB)
- :loading: iOS (RockDB)
- :no: watchOs
- :no: tvOs
- :no: Linux
- :no: Windows

- **Simple**

```kotlin
// JVM
val dataStore: DataStore = MVStore.open("test.db").asDataStore()

// JS
val datataStore = IndexedDBStore

// common
val db = KotlinxDocumentDatabase {
store = dataStore
}

@Serializable // kotlinx.serialization
data class User(val name: String, val age: Int)

val usersCollection: ObjectCollection<User> = db.getObjectCollection<User>("users")

usersCollection.createIndex("name")

val jhon = User("John", 30)

usersCollection.insert(jhon)

val aJhon: User = usersCollection.find("name", "John") // Flow<User>
.filter { it.age > 20 }
.first()
```

**Schemaless**

While one can work with typed objects, kotlinx.document.store also supports schemaless documents relying on kotlinx.serialization for serialization [JsonObject](https://github.com/Kotlin/kotlinx.serialization/blob/c75b46dee6216f600f2c94a0817f0f90fc8ed029/formats/json/commonMain/src/kotlinx/serialization/json/JsonElement.kt#L191)

```kotlin
val db = KotlinxDocumentDatabase {
store = MVStore.open("test.db").asDataStore()
}

val jsonCollection: JsonCollection = db.getJsonCollection("users")

val jhon: JsonObject = jsonCollection.find("name", "John") // Flow<JsonObject>
.filter { it["age"].jsonPrimitive.int > 20 }
.first()

jsonCollection.insert(
buildJsonObject {
put("surname", "117")
put("age", 30)
}
)
```

Of course deserialization into object matters! Don't forget to update your data classes accordingly if you also access the same collection with typed objects.

## Installation

```kotlin
// settings.gradle.kts
dependecyResolutionManagement {
repositories {
maven("https://packages.jetbrains.team/maven/p/kpm/public")
}
}

// build.gradle.kts Kotlin/Multiplatform
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.github.lamba92:kotlinx-document-store-core:1.0.0-SNAPSHOT")
}
}
val jvmMain by getting {
dependencies {
implementation("org.github.lamba92:kotlinx-document-store-mvstore:1.0.0-SNAPSHOT")
}
}
val jsMain by getting {
dependencies {
implementation("org.github.lamba92:kotlinx-document-store-browser:1.0.0-SNAPSHOT")
}
}
}
}

// build.gradle.kts Kotlin/JVM
dependencies {
implementation("org.github.lamba92:kotlinx-document-store-mvstore:1.0.0-SNAPSHOT")
}
```

0 comments on commit 2f7b3ee

Please sign in to comment.