Comments (6)
Question: should database enums be maped by Scala enums, Int, maybe both should be supported ?
from squeryl.
Maybe Scala enums or strings. Int is inconvenient: statement "create type t as enum('a', 'b', 'c')" contains symbolic names, not ints.
from squeryl.
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.
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.
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.
Fixed as of 0.9.4-RC1
http://github.com/max-l/Squeryl/commit/e2daa20d51034b5810dca9923f6ffba85df05fe5
from squeryl.
Related Issues (20)
- postgres enum type in where clause doesn't work HOT 1
- PrimitiveTypeMode error HOT 1
- support java 8 time classes
- ResultSet not closed properly in operation "headOption"
- Not able to fetch the data from db
- Query generated without column names in select clause like "select from table"
- enable/fix Scala 2.13.0-RC1 test HOT 1
- squeryl.org domain name has expired HOT 1
- Clicking documentation on website gives 404 HOT 1
- java.lang.IncompatibleClassChangeError
- LinkageError on v0.9.14 HOT 1
- [Docs] All code snippets are broken
- Enum serialization and deserialization
- It's not possible to join more then 10 tables HOT 1
- Mapping error on left outer joins with queries as soon as null values are encountered
- schema.create for database that already exists?
- Crashes at initialisation on JDK 17 HOT 3
- scaladoc link got error
- Doc: Getting Started page render wrong result
- Update with composite key
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from squeryl.