# Getting Started in Kotlin

Nitrite's Kotlin SDK is a wrapper around the Java SDK. It provides some Kotlin friendly extensions for some of the Java API to work with Nitrite database. The Kotlin SDK is available as a separate module named potassium-nitrite (KNO2). In this guide, we will discuss the Kotlin specific API only. For rest of the API, please refer to the Java SDK. So it is highly recommended to go through the Java SDK guide first.

To get started with Nitrite database, you need to add the Nitrite BOM to your project. The BOM will help you to manage the dependencies. Details of the BOM can be found here.

To add the BOM to your project, follow the steps below:

# Add dependency

To enable Kotlin support, you need to add the potassium-nitrite library to your project. It will automatically add the nitrite library as a dependency along with nitrite-spatial and nitrite-jackson-mapper libraries.

# Maven

Add the nitrite dependency to your pom.xml file:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.dizitart</groupId>
            <artifactId>nitrite-bom</artifactId>
            <version>[latest version]</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.dizitart</groupId>
        <artifactId>potassium-nitrite</artifactId>
    </dependency>
</dependencies>

# Gradle

Add the nitrite dependency to your build.gradle file:

dependencies {
    implementation platform('org.dizitart:nitrite-bom:[latest version]')
    implementation 'org.dizitart:potassium-nitrite'
}

The latest released version of Nitrite can be found here.

# Snapshot builds

Snapshot builds are available from Sonatype.

To use snapshot builds, you need to add the snapshot repository to your pom.xml or build.gradle file:

# Maven

<repositories>
    <repository>
        <id>sonatype-snapshot</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

# Gradle

repositories {
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots/"
    }
}

Nitrite's Kotlin SDK is not as lean as the Java SDK. It has a lot of dependencies. If you are using Kotlin in your project, it is recommended to use the Kotlin SDK. Otherwise, you can use the Java SDK with Kotlin as well.

# Upgrade from 3.x

If you are upgrading from 3.x, please note that there are lots of breaking changes in the API. The whole library is re-written from scratch. It is recommended to go through this guide before upgrading.

Nitrite will try to migrate your existing database to the latest version on the best effort basis without any guarantee provided you are using the MVStore module. If you are using the RocksDB module, you need to migrate your database manually. However, it is recommended to take a backup of your database before upgrading.