Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would it be possible to read columnTable by reflection? #736

Open
Aditya94A opened this issue Dec 22, 2019 · 3 comments
Open

Would it be possible to read columnTable by reflection? #736

Aditya94A opened this issue Dec 22, 2019 · 3 comments
Labels
waiting for reply Additional information required

Comments

@Aditya94A
Copy link

I think this could be a good way to reduce boilerplate, if the names of columns can be automatically set to the the same as the DAO field name

image

@Tapac
Copy link
Contributor

Tapac commented Dec 24, 2019

First of all, I like explicit naming as you are always know what to search in your database.
And, as I can see, you already mention that it will be possible with another dao in a comment at #24 issue.

@Tapac Tapac added the waiting for reply Additional information required label Jan 11, 2020
@AliLozano
Copy link
Contributor

AliLozano commented Feb 19, 2020

This could be easy adding delegated functions for all types.

class ImplicitNameDelegate<T>(val fn: Table.(name: String) -> Column<T>) {
    var column: Column<T>? = null
    operator fun getValue(thisRef: Table, property: KProperty<*>): Column<T> {
        if(column==null) column = fn(thisRef, property.name)
        return column!!
    }
}

fun <T> implicitName(fn: Table.(name: String) -> Column<T>) = ImplicitNameDelegate(fn)

fun Table.varchar(length: Int, collate: String?=null) = implicitName { varchar(it, length, collate)}

object Userable: IntIdTable() {
    val username by varchar(100)
}

@Aditya94A
Copy link
Author

@Tapac Can this be supported natively in the library (for all types)?

In order to not interfere with the rest of the library, we can think of ways to give this functionality to those who want (opt-in only), perhaps by adding a constructor parameter to the base class of Table object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for reply Additional information required
Projects
None yet
Development

No branches or pull requests

3 participants