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

missing double precision column type #358

Closed
tr8dr opened this issue Aug 2, 2018 · 4 comments
Closed

missing double precision column type #358

tr8dr opened this issue Aug 2, 2018 · 4 comments

Comments

@tr8dr
Copy link
Contributor

tr8dr commented Aug 2, 2018

Most applications that use floating point no longer use Float, rather Double. I noticed that Exposed does not provide a Double column type. Whereas, if have a table such as:

CREATE Table foo (
    a .  double precision,
    b .  double precision
    ...
);

Would want to be able to do the following on the kolin side:

object Foo : Table("foo") {
    val a = double("a")
    val b = double("b")
    ...
}

I added this in a fork and submitted a pull request. As authors of the library you may wish to implement this differently. I need to get this out of my private repo and into the official so we can use this from gradle within our organization. Thanks!

@NekoiNemo
Copy link

NekoiNemo commented Aug 8, 2018

Sorry, noticed you already made PR

Code from deleted post

/// ==== Double column ====

class DoubleColumnType : ColumnType() {
    override fun sqlType(): String = "DOUBLE PRECISION"

    override fun valueFromDB(value: Any): Any = when (value) {
        is Double -> value
        is Number -> value.toDouble()
        else -> error("Unexpected value of type Double: $value of ${value::class.qualifiedName}")
    }
}

fun Table.double(name: String): Column<Double> = registerColumn(name, DoubleColumnType())

@tr8dr
Copy link
Contributor Author

tr8dr commented Aug 8, 2018

Your solve here is nice. I will keep the PR, but will use your code in conjunction with the current release. Hopefully they will get this implemented at some point.

@NekoiNemo
Copy link

It's just a bandaid that can be applied from inside a project, without altering the lib. Of course proper solution is to also modify the dialect...

@Tapac
Copy link
Contributor

Tapac commented Aug 26, 2018

Fixed in master (thank for PR #354 by @tr8dr)

@Tapac Tapac closed this as completed Aug 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants