Class: SqlTools::Index
- Inherits:
-
Object
- Object
- SqlTools::Index
- Defined in:
- lib/sql_tools/index.rb
Instance Method Summary collapse
- #columns ⇒ Object
-
#initialize(node) ⇒ Index
constructor
A new instance of Index.
- #name ⇒ Object
- #primary_key? ⇒ Boolean
Constructor Details
#initialize(node) ⇒ Index
Returns a new instance of Index.
3 4 5 |
# File 'lib/sql_tools/index.rb', line 3 def initialize(node) @node = node end |
Instance Method Details
#columns ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/sql_tools/index.rb', line 7 def columns @node.query(<<~QUERY).map do |match| (ordered_columns (column name: (identifier) @column_name)) QUERY match["column_name"].text end end |
#name ⇒ Object
20 21 22 23 24 |
# File 'lib/sql_tools/index.rb', line 20 def name return :primary_key if primary_key? @node.name.text.delete("`") end |
#primary_key? ⇒ Boolean
15 16 17 18 |
# File 'lib/sql_tools/index.rb', line 15 def primary_key? @node.any? { |child| child.type == :keyword_primary } && @node.any? { |child| child.type == :keyword_key } end |