kminiorm-mongo

ORM for Kotlin supporting JDBC and MongoDB

License

License

Categories

Categories

JavaScript Languages ORM Data
GroupId

GroupId

com.soywiz.korlibs.kminiorm
ArtifactId

ArtifactId

kminiorm-mongo-js
Last Version

Last Version

0.10.2
Release Date

Release Date

Type

Type

pom
Description

Description

kminiorm-mongo
ORM for Kotlin supporting JDBC and MongoDB
Project URL

Project URL

https://github.com/korlibs/kminiorm
Source Code Management

Source Code Management

https://github.com/korlibs/kminiorm

Download kminiorm-mongo-js

How to add to project

<!-- https://jarcasting.com/artifacts/com.soywiz.korlibs.kminiorm/kminiorm-mongo-js/ -->
<dependency>
    <groupId>com.soywiz.korlibs.kminiorm</groupId>
    <artifactId>kminiorm-mongo-js</artifactId>
    <version>0.10.2</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/com.soywiz.korlibs.kminiorm/kminiorm-mongo-js/
implementation 'com.soywiz.korlibs.kminiorm:kminiorm-mongo-js:0.10.2'
// https://jarcasting.com/artifacts/com.soywiz.korlibs.kminiorm/kminiorm-mongo-js/
implementation ("com.soywiz.korlibs.kminiorm:kminiorm-mongo-js:0.10.2")
'com.soywiz.korlibs.kminiorm:kminiorm-mongo-js:pom:0.10.2'
<dependency org="com.soywiz.korlibs.kminiorm" name="kminiorm-mongo-js" rev="0.10.2">
  <artifact name="kminiorm-mongo-js" type="pom" />
</dependency>
@Grapes(
@Grab(group='com.soywiz.korlibs.kminiorm', module='kminiorm-mongo-js', version='0.10.2')
)
libraryDependencies += "com.soywiz.korlibs.kminiorm" % "kminiorm-mongo-js" % "0.10.2"
[com.soywiz.korlibs.kminiorm/kminiorm-mongo-js "0.10.2"]

Dependencies

compile (2)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-js jar 1.4.31
org.jetbrains.kotlin : kotlin-stdlib-common jar 1.4.31

Project Modules

There are no modules declared in this project.

kminiorm

Actions Status

ORM for Kotlin supporting JDBC and MongoDB

Repository:

https://bintray.com/korlibs/korlibs/kminiorm

repositories {
    // ...
    jcenter()
    maven { url = uri("https://dl.bintray.com/korlibs/korlibs") }
}
dependencies {
    // Core:
    implementation("com.soywiz.korlibs.kminiorm:kminiorm-jvm:0.9.0")
    // JDBC:
    implementation("com.soywiz.korlibs.kminiorm:kminiorm-jdbc-jvm:0.9.0")
    implementation("org.xerial:sqlite-jdbc:3.30.1")
    implementation("com.h2database:h2:1.4.200")
    // Mongo:
    implementation("com.soywiz.korlibs.kminiorm:kminiorm-mongo-jvm:0.9.0")
}

Sample:

You can run ./sample.main.kts to get it working.

import com.soywiz.kminiorm.*
import com.soywiz.kminiorm.dialect.*
import com.soywiz.kminiorm.where.*
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.*
import java.io.*

fun main() = runBlocking {
    data class MyTable(
        @DbPrimary val key: String,
        @DbIndex val value: Long
    ) : DbBaseModel

    val sqliteFile = File("sample.sq3")
    val db = JdbcDb(
        "jdbc:sqlite:${sqliteFile.absoluteFile.toURI()}",
        debugSQL = System.getenv("DEBUG_SQL") == "true",
        dialect = SqliteDialect,
        async = true
    )

    val table = db.table<MyTable>()
    table.insert(
        MyTable("hello", 10L),
        MyTable("world", 20L),
        MyTable("this", 30L),
        MyTable("is", 40L),
        MyTable("a", 50L),
        MyTable("test", 60L),
        onConflict = DbOnConflict.IGNORE
    )

    table.where { it::value ge 20L }.limit(10).collect {
        println(it)
    }
    Unit
}

Defining Tables

You can use normal Kotlin fields

data class MyTable(
    @DbPrimary val key: String,
    @DbIndex val value: Long
) : DbBaseModel

Multi-column indices

data class MyTable(
    @DbUnique("a_b") val a: String,
    @DbUnique("a_b") val b: String
) : DbBaseModel

Creating a Repository

Migrations

If you change a table adding a new field to it, you can register a DbMigration that will be executed when the ALTER TABLE is automatically performed.

data class MyTable(
    val a: String,
    @DbPerformMigration(MyAddColumnMigration::class) val newlyAddedField: String // 
) : DbBaseModel {
    class MyAddColumnMigration : DbMigration<MyTable> {
        override suspend fun migrate(table: DbTable<MyTable>, action: DbMigration.Action, column: ColumnDef<MyTable>?) {
            table.where.collect { item -> 
                // Update item here ...
            }
        }
    }
}
com.soywiz.korlibs.kminiorm
Kotlin cORoutine Libraries for fullstack development - https://bintray.com/korlibs/korlibs - https://github.com/korlibs

Versions

Version
0.10.2