Skip to content

Instantly share code, notes, and snippets.

@lumentut
Last active July 9, 2021 14:41
Show Gist options
  • Save lumentut/f70e753b75ced06caea91c4b5afbbfc6 to your computer and use it in GitHub Desktop.
Save lumentut/f70e753b75ced06caea91c4b5afbbfc6 to your computer and use it in GitHub Desktop.
class DataTypes
def initialize
@columns = {}
end
def columns
@columns
end
def col(name, args)
@columns[name] = args
end
end
class Test
def initialize
@queries = {}
end
def queries
@queries
end
def column_defs(query_name, &block)
data_types = DataTypes.new
yield data_types
queries[query_name] = data_types.columns
puts queries
end
end
test = Test.new
test.column_defs :test_query do |q|
q.col :satu ,type: :string, length: 10
q.col :dua ,type: :integer, length: 5
q.col :tiga ,type: :boolean, default: true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment