GithubHelp home page GithubHelp logo

Comments (6)

max-l avatar max-l commented on June 17, 2024

Question: should database enums be maped by Scala enums, Int, maybe both should be supported ?

from squeryl.

dimgel avatar dimgel commented on June 17, 2024

Maybe Scala enums or strings. Int is inconvenient: statement "create type t as enum('a', 'b', 'c')" contains symbolic names, not ints.

from squeryl.

max-l avatar max-l commented on June 17, 2024

Ok, I think both needs to be supported then, I need to find out how Scala enums work
internally, I mean how they can be set/get by reflection. Do you know ?
Another thing is that some DBs don't support enums, so we have to see if a
"lowest common denominator" can be good in all cases.

from squeryl.

dimgel avatar dimgel commented on June 17, 2024

Do you know ?

Unfortunately no.

lowest common denominator

No much help from me here either. The first idea - it's String because enum value maybe converted to string, and before Postgres supported enums, they were emulated with text + check constraint.

But the problem is about declaration. If class field is declared as string, how would you know it must be casted to enum? Where would you get enum's name from? Maybe annotation is needed here which provides enum (generally - any custom type) name.

For example, if you see:
@enum("kind_enum") kind: String
or:
@type("kind_enum") kind: String

then in SQL you generate:
cast(kind as kind_enum)

It was just draft idea.

from squeryl.

dflemstr avatar dflemstr commented on June 17, 2024

To reflect on Enumerations, you can use "classOf[MyEnumeration#Value]" to gain access to the class, if you want to access information about individual value alternatives.

Enumeration values can be gotten via "MyEnumeration.values" (The "MyEnumeration" object can be accessed reflexively like any other singleton object, by e.g. appending "$" to the name).

Every Enumeration value has an id: Int. This is the common denominator for Enumerations, at least. You can also get enumeration values by id and map each enumeration value to a string.

I don't see how this is any more or less difficult than mapping any other kind of value to a database...

from squeryl.

max-l avatar max-l commented on June 17, 2024

Fixed as of 0.9.4-RC1
http://github.com/max-l/Squeryl/commit/e2daa20d51034b5810dca9923f6ffba85df05fe5

from squeryl.

Related Issues (20)

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.