Skip to content
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

fix: Add convert Rails column type to Graphiti type #83

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion lib/generators/graphiti/resource_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ def default_attributes
end
if attributes_class.table_exists?
return attributes_class.columns.map do |c|
OpenStruct.new({name: c.name.to_sym, type: c.type})
OpenStruct.new({
name: c.name.to_sym,
type: convert_column_type_to_graphiti_resource_type(c.type)
})
end
else
raise "#{attributes_class} table must exist. Please run migrations."
Expand Down Expand Up @@ -181,5 +184,34 @@ def resource_klass
def type
model_klass.name.underscore.pluralize
end

def convert_column_type_to_graphiti_resource_type(type)
# TODO: Support database specific types.
case type
when :string, :text
:string
when :float, :decimal
:integer
when :integer, :bigint
:integer
when :datetime, :time
:datetime
when :date
:date
when :boolean
:boolean
when :numeric
# TODO: Return type.
type
when :primary_key
# TODO: Return type.
type
when :binary
# TODO: Return type.
type
else
type
end
end
end
end