-
Notifications
You must be signed in to change notification settings - Fork 64
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
Experimental/json serializable columns #695
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c3d364d
Attempting to implement the json serializable. First spec passes, but…
jwoertink 1daa955
round two reverts some of the previous commit. Now using a column con…
jwoertink dcbe24b
reverting these changes because they're refactors and not really rela…
jwoertink 29aec80
use separate branch with json changes and we no longer need any patches
jwoertink 75fd177
Adding the ability to query serializable columns
jwoertink 761616f
This line wasn't needed
jwoertink a34d2f7
Merge branch 'master' into experimental/json_serializable_columns
jwoertink be1db3c
Go back to original PG Shard, but use master now that Matthew's PR wa…
jwoertink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,15 @@ | ||
class AddMetadataToBlobs::V20210703234151 < Avram::Migrator::Migration::V1 | ||
def migrate | ||
alter :blobs do | ||
add metadata : JSON::Any, default: JSON::Any.new({} of String => JSON::Any) | ||
add media : JSON::Any?, fill_existing_with: :nothing | ||
end | ||
end | ||
|
||
def rollback | ||
alter :blobs do | ||
remove :metadata | ||
remove :media | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
class BlobFactory < BaseFactory | ||
def initialize | ||
doc JSON::Any.new({"foo" => JSON::Any.new("bar")}) | ||
metadata(BlobMetadata.from_json({name: "Test", code: 4}.to_json)) | ||
media nil | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
class BlobMetadata | ||
include JSON::Serializable | ||
|
||
property name : String? | ||
property code : Int32? | ||
end | ||
|
||
class MediaMetadata | ||
include JSON::Serializable | ||
|
||
property image : String? | ||
end | ||
|
||
class Blob < BaseModel | ||
table do | ||
column doc : JSON::Any? | ||
column metadata : BlobMetadata, serialize: true | ||
column media : MediaMetadata?, serialize: true | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module PG::Decoders | ||
struct JsonDecoder | ||
def decode(io, bytesize, oid) | ||
if oid == JSONB_OID | ||
io.read_byte | ||
bytesize -= 1 | ||
end | ||
|
||
string = String.new(bytesize) do |buffer| | ||
io.read_fully(Slice.new(buffer, bytesize)) | ||
{bytesize, 0} | ||
end | ||
JSON::PullParser.new(string) | ||
end | ||
|
||
def type | ||
JSON::PullParser | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These had to be moved up so our patch to "pg" comes after the definition