Sha256: e58c9bb3dda37097422766ea7fe2cb9e1bd5701525ce3dd4e52b54a5c29cb126
Contents?: true
Size: 841 Bytes
Versions: 2
Compression:
Stored size: 841 Bytes
Contents
# frozen_string_literal: true module Ruby module Text2sql class SchemaParser SCHEMA_PATH = "db/schema.rb" def initialize @schema = File.read(SCHEMA_PATH) end # Parses the schema to extract table and column information, including column types def parse tables = [] @schema.each_line do |line| # Extract table names if line =~ /create_table "(.*?)"/ tables << { table: Regexp.last_match(1), columns: [] } # Extract column types and names elsif line =~ /t\.(\w+) "(.*?)"/ column_type = Regexp.last_match(1) column_name = Regexp.last_match(2) tables.last[:columns] << { name: column_name, type: column_type } if tables.any? end end tables end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ruby-text2sql-1.0.0 | lib/ruby/text2sql/schema_parser.rb |
ruby-text2sql-0.1.0 | lib/ruby/text2sql/schema_parser.rb |