Class: Jabara::MySQL::Schema::Builder
- Inherits:
-
Object
- Object
- Jabara::MySQL::Schema::Builder
- Defined in:
- lib/jabara/mysql/schema.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
Instance Method Summary collapse
- #boolean ⇒ Object
- #char(max, char_set: nil) ⇒ Object
- #column(key, type, *args) ⇒ Object
- #datetime ⇒ Object
- #float ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #integer ⇒ Object
- #not_null ⇒ Object
-
#table_name(table_name) ⇒ Object
以下DSLメソッド。buildに渡すblock内で使う。.
- #varchar(max) ⇒ Object
Constructor Details
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
127 128 129 |
# File 'lib/jabara/mysql/schema.rb', line 127 def schema @schema end |
Class Method Details
.build(&block) ⇒ Object
133 134 135 136 137 |
# File 'lib/jabara/mysql/schema.rb', line 133 def self.build(&block) this = self.new this.instance_eval(&block) return this.schema end |
.build_from_sql(query_str) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/jabara/mysql/schema.rb', line 139 def self.build_from_sql(query_str) parser = Scheman::Parsers::Mysql.new create_stmt_hashs = parser.parse(query_str) .to_hash .select {|stmt| not stmt[:create_table].nil? } .map{|stmt| stmt[:create_table] } create_stmt_hashs.map { |create_stmt_hash| schema = stmt_to_schema(create_stmt_hash) [schema.table_name, schema] }.to_h end |
Instance Method Details
#boolean ⇒ Object
167 168 169 |
# File 'lib/jabara/mysql/schema.rb', line 167 def boolean Boolean.new end |
#char(max, char_set: nil) ⇒ Object
179 180 181 182 |
# File 'lib/jabara/mysql/schema.rb', line 179 def char(max, char_set:nil) # TODO char_set Char.new max: max end |
#column(key, type, *args) ⇒ Object
159 160 161 |
# File 'lib/jabara/mysql/schema.rb', line 159 def column(key, type, *args) @schema.columns.push({key: key, type: type, constraints: args}) end |
#datetime ⇒ Object
184 185 186 |
# File 'lib/jabara/mysql/schema.rb', line 184 def datetime DateTime.new end |
#float ⇒ Object
188 189 190 |
# File 'lib/jabara/mysql/schema.rb', line 188 def float Float.new end |
#integer ⇒ Object
171 172 173 |
# File 'lib/jabara/mysql/schema.rb', line 171 def integer Integer.new end |
#not_null ⇒ Object
163 164 165 |
# File 'lib/jabara/mysql/schema.rb', line 163 def not_null :not_null end |
#table_name(table_name) ⇒ Object
以下DSLメソッド。buildに渡すblock内で使う。
155 156 157 |
# File 'lib/jabara/mysql/schema.rb', line 155 def table_name(table_name) @schema.table_name = table_name end |