Giter VIP home page Giter VIP logo

aorm's Introduction

AORM

Download

AORM is analytical SQL framework. Basically, it is a fork of Exposed SQL framework for ClickHouse database dialect.

AORM supports Exposed-like DSL for standard SQL operations and rich set of ClickHouse dialect features (like state-aggregation functions, different engines, replicated context of execution and so on)

Setup

AORM releases are published to JCenter.

How to

First of all you'll need to set up Database object. Provide it with DataSource (self-constructed, JNDI -- it doesn't matter, but don't forget to use pooling :) ). In context of Database (withContext(db) call) you will perform all operations.

val database = Database("default",
        ClickHouseDataSource("jdbc:clickhouse://localhost:8123",
                ClickHouseProperties().withCredentials("default", ""))
)

If you have a replicated cluster and want to balance load you may need to set up few Database objects and use ReplicatedConnectionContext.

You can set up Table objects once database is created. Right now AORM supports a lot of ClickHouse types, but does not support nullability. Instead, null values will fallback to ClickHouse defaults. Support of nullability is considered to be implemented.

object TestTable : Table("test_table") {
     val dateCol = date("date_col")
     val int8Col = int8("int8_col")
     val int64Col = int64("int64_col")
     val stringCol = string("string_col")
     val arrayStringCol = arrayString("arrayString_col")
 
     override val engine: Engine = Engine.MergeTree(dateCol, listOf(dateCol))
}

Please note, that table is not linked to specific database. Table object is only declaration of scheme. You can use it in different contexts during work with different databases.

Once you have created table object, you can align the scheme of your table with you database. Aligning of scheme means, that table will be created if it does not exist, or, if it exists, not existing columns will be added. AORM, by default, not performing any removal operations on aligning of scheme. It will not drop existing tables or columns.

withDatabase(database) {
    TestTable.syncScheme() // this call will align the scheme of TestTable in a database
}

Once everything is set up, you can insert some data:

withDatabase(database) {
    TestTable.insert {
        it[TestTable.dateCol] = SimpleDateFormat("yyyy-MM-dd").parse("2000-01-01")
        it[TestTable.int8Col] = 1.toByte()
        it[TestTable.int64Col] = 1L
        it[TestTable.stringCol] = "test"
        it[TestTable.arrayStringCol] = listOf("test1", "test2")
    }
}

Then load it:

withDatabase(database) {
    val query = TestTable.select() where (TestTable.int8Col eq 1.toByte())
    val res = query.toResult()
}

There are a lot more query functions, types of columns, and so on. You can take a closer look at all features of AORM at it's tests or at next section

More examples

A lot of examples of AORM production usage are located at JetAudit library. JetAudit is library for reliable and fast saving of business processes events (audit-events) and for reading of such events. It uses ClickHouse as data warehouse and AORM is used as programmatic interface.

aorm's People

Contributors

denlink avatar guredd avatar sndl avatar tanvd avatar tapac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

aorm's Issues

mvn/gradle repository.

Can you please provide an opportunity for using you great library as mvn/gradle dependency?

Utils for batch insert

Please add some generic function to collect data for further batchInserts (for example: queue + scheduled task executor)

The simplest example of setup and usage.

I tried to use your library a little. And at first sight it looks simple, but It's not very clear how to use your library without the need to add clickhouse-jdbc as separate dependency. Because i think it's bad practice to duplicate this dependency due differences in versions for example. I would be very grateful if you explain this process.

Json, Maps, Nested types support

Hello!
Do you have any plans to add support for json, map, nested datatypes to your framework? Was it not implemented due to some technical difficulties?

Maven central,

Hi! Since jcenter has been closed, you may be asked to upload the project to maven central?

Maven

Hi! I wanted to try AORM. But I didn’t find it on maven central. I have already done a local build, but it would be more convenient to be able to pull it from a maven central

Table creation statements use deprecated MergeTree syntax

When using newer clickhouse-server instances AORM fails to create tables because a deprecated statement syntax is used.

For example it uses
CREATE TABLE tally_entity_table (date Date, tally_id Int32, trentity_id Int32, article_id Int32, region_id Int32) ENGINE = MergeTree(date, (date, tally_id, trentity_id), 8192) to create a table.

The documentation at https://clickhouse.com/docs/en/engines/table-engines/mergetree-family/mergetree describes the new way to create tables.

In edwinRNDR@db8ab6e I fixed the syntax but I had to hardcode a partitioning function (toYYYYMMDD). I believe this function should be configurable in Engine.MergeTree().

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.