class SyntaxTree::Database::Connection

Attributes

raw_connection[R]

Public Class Methods

new(raw_connection) click to toggle source
# File lib/syntax_tree/database.rb, line 279
def initialize(raw_connection)
  @raw_connection = raw_connection
end

Public Instance Methods

execute(query, binds = []) click to toggle source
# File lib/syntax_tree/database.rb, line 283
def execute(query, binds = [])
  raw_connection.execute(query, binds)
end
index_file(filepath) click to toggle source
# File lib/syntax_tree/database.rb, line 287
def index_file(filepath)
  program = SyntaxTree.parse(SyntaxTree.read(filepath))
  program.accept(IndexingVisitor.new(self, filepath))
end
last_insert_row_id() click to toggle source
# File lib/syntax_tree/database.rb, line 292
def last_insert_row_id
  raw_connection.last_insert_row_id
end
prepare() click to toggle source
# File lib/syntax_tree/database.rb, line 296
      def prepare
        raw_connection.execute(<<~SQL)
          CREATE TABLE nodes (
            id integer primary key,
            type varchar(20),
            path varchar(200),
            line integer,
            column integer
          );
        SQL

        raw_connection.execute(<<~SQL)
          CREATE INDEX nodes_type ON nodes (type);
        SQL

        raw_connection.execute(<<~SQL)
          CREATE TABLE edges (
            id integer primary key,
            from_id integer,
            to_id integer,
            name varchar(20),
            list_index integer
          );
        SQL

        raw_connection.execute(<<~SQL)
          CREATE INDEX edges_name ON edges (name);
        SQL
      end