GithubHelp home page GithubHelp logo

bhanditz / xodus-dnq Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jetbrains/xodus-dnq

0.0 2.0 0.0 2.15 MB

Data definition and queries Kotlin DSL over Xodus

License: Apache License 2.0

Java 0.13% Kotlin 99.81% FreeMarker 0.06%

xodus-dnq's Introduction

Xodus-DNQ

official JetBrains project Maven Central Build Status License Pure Java + Kotlin Stack Overflow

Xodus-DNQ is a Kotlin library that contains the data definition language and queries for Xodus, a transactional schema-less embedded database. Xodus-DNQ provides the same support for Xodus that ORM frameworks provide for SQL databases. With Xodus-DNQ, you can define your persistent meta-model using Kotlin classes.

JetBrains team tools YouTrack and Hub use Xodus-DNQ for persistent layer definition.

More documentation https://jetbrains.github.io/xodus-dnq.

Quick Start Guide

Install to your project

Maven Central

List of released versions is available at https://github.com/JetBrains/xodus-dnq/releases.

Gradle

repositories {
    mavenCentral()
}
compile 'org.jetbrains.xodus:dnq:${version}'

Maven

<dependency>
    <groupId>org.jetbrains.xodus</groupId>
    <artifactId>dnq</artifactId>
    <version>$version</version>
</dependency>

Use Xodus-DNQ

See code in repository.

// Define persistent class. It should extend XdEntity
class XdPost(entity: Entity) : XdEntity(entity) {
    //  and have component object of type XdEntityType
    companion object : XdNaturalEntityType<XdPost>()

    // Define persistent property of type org.joda.time.DateTime?
    var publishedAt by xdDateTimeProp()

    // Define required persistent property of type String
    var text by xdRequiredStringProp()
}

class XdBlog(entity: Entity) : XdEntity(entity) {
    companion object : XdNaturalEntityType<XdBlog>()

    // Define multi-value link to XdPost
    val posts by xdLink0_N(XdPost)
}

fun main(args: Array<String>) {
    // Register persistent classes
    XdModel.registerNodes(XdPost, XdBlog)

    // Initialize Xodus persistent storage
    val xodusStore = StaticStoreContainer.init(
            dbFolder = File(System.getProperty("user.home"), ".xodus-dnq-blog-db"),
            environmentName = "db"
    )

    // Initialize Xodus-DNQ metadata
    initMetaData(XdModel.hierarchy, xodusStore)

    // Do in transaction
    val blog = xodusStore.transactional {
        // Find an existing blog in database
        XdBlog.all().firstOrNull()
                // or create a new one if there are no blogs yet
                ?: XdBlog.new()
    }

    xodusStore.transactional {
        // Create new post
        val post = XdPost.new {
            this.publishedAt = DateTime.now()
            this.text = args.firstOrNull() ?: "Empty post"
        }

        // Add new post to blog
        blog.posts.add(post)
    }

    // Do in read-only transaction
    xodusStore.transactional(readonly = true) {
        // Print all blog posts
        for (post in blog.posts) {
            println("${post.publishedAt}: ${post.text}")
        }
    }
}

Find out more

xodus-dnq's People

Contributors

morj avatar mazine avatar penemue avatar vadimgurov avatar lehvolk avatar sedovalx avatar jk1 avatar denvned avatar chushuhuch avatar anna2390 avatar pavel-nikolaev avatar allvo avatar leostryuk avatar fisakov avatar timzam avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.