d-r-q / qbit

qbit is a kotlin-multiplatform embeddable decentralized DBMS with object-relational information model
44 stars 9 forks source link

Map several classes to single entity collection #70

Open d-r-q opened 4 years ago

d-r-q commented 4 years ago

The general idea is following

First of all, allow user to create several classes with different fields mapped to the same entity collection:

data class User(val id: Long?)

data class UserExt(val id: Long?, val name: String, val father: User, val mother: User) : User(id)

And then allow user to define refs in schema definition:

schema {
    entity(UserExt::class) {
        ref(User::class)
    }
}

And finally allow user to express adhoc query:

// select only user, all ref fields fetched as refs by default
val user = query<UserExt>(UserExt::name eq "user")
assertTrue(user.father is User)
assertTrue(user.mother is User)

// select user and his father
val queryGraph = root(UserExt::class) {
    UserExt::father fetchAs UserExt::class
}
val userWithFather = query<UserExt>(UserExt::name eq "user")
assertTrue(user.father is User)
assertTrue(user.mother is UserId)

Motivation: provide user simple way to express exact form required entites graph

Problems/questions: 1) Recursive types

Relates to: #51