-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds in Array enums. Fixes #940 * Removing this commented code since the actual case is covered in the parent Type
- Loading branch information
Showing
8 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class AddEnumsToBucket::V20240309222910 < Avram::Migrator::Migration::V1 | ||
def migrate | ||
alter table_for(Bucket) do | ||
add enums : Array(Int32), default: [] of Int32 | ||
end | ||
end | ||
|
||
def rollback | ||
alter table_for(Bucket) do | ||
remove :enums | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Extends the PG shard and adds a converter for | ||
# converting `Array(Int)` columns to `Array(Enum)`. This | ||
# can be used with raw SQL queries. | ||
# ``` | ||
# enum Colors | ||
# Red | ||
# end | ||
# @[DB::Field(converter: PG::EnumArrayConverter(Colors))] | ||
# property colors : Array(Colors) | ||
# ``` | ||
module PG::EnumArrayConverter(T) | ||
def self.from_rs(rs : DB::ResultSet) | ||
rs.read(Array(typeof(T.values.first.value))).map { |i| T.from_value(i) } | ||
end | ||
end |