https://github.com/droptheplot/enumify
https://github.com/droptheplot/enumify
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/droptheplot/enumify
- Owner: droptheplot
- License: mit
- Created: 2021-11-03T15:00:33.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-15T09:53:19.000Z (over 4 years ago)
- Last Synced: 2025-03-18T06:33:14.675Z (about 1 year ago)
- Language: Scala
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Enumify

Enumify is a SBT plugin that will keep enums from your favorite database in sync with Scala types
## Getting Started
Add SBT plugin to `project/plugins.sbt`
```scala
addSbtPlugin("com.github.droptheplot" % "enumify" % "0.1")
```
Add source generator to `build.sbt`
```scala
sourceGenerators in Compile += Def.task {
val connection: java.sql.Connection = ???
enumify.Enumify(connection, enumify.sources.PostgreSQL, enumify.renderers.Plain) {
(sourceManaged in Compile).value / "enumify"
}
}.taskValue
```
### Available Sources
* [PostgreSQL](https://www.postgresql.org/docs/current/datatype-enum.html)
* [MySQL](https://dev.mysql.com/doc/refman/8.0/en/enum.html)
### Available Renderers
#### Plain
```scala
sealed abstract class Mood(value: String)
object Mood {
case object Sad extends Mood("sad")
case object Ok extends Mood("ok")
case object Happy extends Mood("happy")
}
```
#### Enumeratum
```scala
sealed abstract class Mood extends EnumEntry(override val entryName: String) extends EnumEntry
object Mood extends Enum[Mood] {
case object Sad extends Mood("sad")
case object Ok extends Mood("ok")
case object Happy extends Mood("happy")
val values = findValues
}
```
### Contributing
Use `sbt "testOnly -- -l IntegrationTest"` to run only unit tests